Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // /Home/Index.cshtml contains a link to /Title/<titleId>
- // Clicking on the link gives an HTTP 404 error
- // URL: http://localhost:50359/Title/1/
- public class TitleController : BaseController
- {
- // GET: Title
- public ActionResult Index(int TitleId)
- {
- // load the DbContext
- ForumEntities Db = new ForumEntities();
- // get a list of Threads for the selected Title
- List<Thread> DbThreads = new List<Thread>();
- DbThreads = Db.Threads.Where(x => x.Id == TitleId && x.Deleted == false).ToList();
- // build a ViewModel for each thread and add it to a list
- List<ThreadViewModel> Threads = new List<ThreadViewModel>();
- foreach (Thread Thread in DbThreads)
- {
- Threads.Add(new ThreadViewModel
- {
- Author = Db.Users.FirstOrDefault(x => x.Id == Thread.UserId).Username,
- Id = Thread.Id,
- Date = Thread.CreatedOn,
- Name = Thread.Name,
- PostCount = Db.Posts.Where(x => x.ThreadId == Thread.Id && x.Deleted == false).Count()
- });
- }
- // build the ViewModel for this particular view which contains the requested threads
- ListThreadsViewModel ThreadList = new ListThreadsViewModel
- {
- TitleName = Db.Titles.FirstOrDefault(x => x.Id == TitleId).Name,
- Threads = Threads
- };
- return View(ThreadList);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement