public ActionResult Index() { List<MonitorViewModel> monitorList = new List<MonitorViewModel>(); var mons = db.Monitors.ToList(); foreach (Monitor mon in mons) { MonitorViewModel monView = new MonitorViewModel(); ApplicationUser _user = mon.ApplicationUser; monView._monitor = mon; monView._username = _user.FirstName + " " + _user.LastName; monView._lastcheckout = mon.Checkouts .OrderBy(x => x.dtCheckedOut) .LastOrDefault() == null ? null : mon.Checkouts.OrderBy(x => x.dtCheckedOut) .Select(x => new CheckoutViewModel { dtCheckedOut = x.dtCheckedOut, dtReturned = x.dtReturned, Username = x.ApplicationUser.FirstName + " " + x.ApplicationUser.LastName }).LastOrDefault(); monView._sold = mon.Sale ?? null; monitorList.Add(monView); } return View(monitorList.AsEnumerable()); }
public ActionResult Details(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Monitor monitor = db.Monitors.Find(id); if (monitor == null) { return HttpNotFound(); } MonitorViewModel details = new MonitorViewModel(); details._monitor = monitor; details._lastcheckout = monitor.Checkouts.Any() ? monitor.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 = monitor.Sale == null ? null : monitor.Sale; return View(details); }