public ActionResult Index() { List<NotebookViewModel> notebookList = new List<NotebookViewModel>(); var notes = db.Notebooks.ToList(); foreach(Notebook note in notes) { NotebookViewModel noteView = new NotebookViewModel(); ApplicationUser _user = note.ApplicationUser; noteView._notebook = note; noteView._username = _user.FirstName + " " + _user.LastName; noteView._lastcheckout = note.Checkouts .OrderBy(x => x.dtCheckedOut) .LastOrDefault() == null ? null : note.Checkouts.OrderBy(x => x.dtCheckedOut) .Select(x => new CheckoutViewModel { dtCheckedOut = x.dtCheckedOut, dtReturned = x.dtReturned, Username = x.ApplicationUser.FirstName + " " + x.ApplicationUser.LastName }).LastOrDefault(); noteView._sold = note.Sale ?? null; notebookList.Add(noteView); } return View(notebookList.AsEnumerable()); }
public ActionResult Details(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Notebook notebook = db.Notebooks.Find(id); if (notebook == null) { return HttpNotFound(); } NotebookViewModel details = new NotebookViewModel(); details._notebook = notebook; details._lastcheckout = notebook.Checkouts.Any() ? notebook.Checkouts.OrderByDescending(x => x.dtCheckedOut).Select(x => new CheckoutViewModel { dtCheckedOut = x.dtCheckedOut, dtReturned = x.dtReturned, Username = x.ApplicationUser.FirstName + " " + x.ApplicationUser.LastName }).First() : null; details._sold = notebook.Sale == null ? null : notebook.Sale; return View(details); }