Example #1
0
        public ActionResult Index()
        {
            List<TabletViewModel> tabletList = new List<TabletViewModel>();
            var tabs = db.Tablets.ToList();

            foreach (Tablet tab in tabs)
            {
                TabletViewModel tabView = new TabletViewModel();
                ApplicationUser _user = tab.ApplicationUser;
                tabView._tablet = tab;
                tabView._username = _user.FirstName + " " + _user.LastName;
                tabView._lastcheckout = tab.Checkouts
                    .OrderBy(x => x.dtCheckedOut)
                    .LastOrDefault() == null ? null :
                        tab.Checkouts.OrderBy(x => x.dtCheckedOut)
                        .Select(x => new CheckoutViewModel
                        {
                            dtCheckedOut = x.dtCheckedOut,
                            dtReturned = x.dtReturned,
                            Username = x.ApplicationUser.FirstName + " " + x.ApplicationUser.LastName
                        }).LastOrDefault();
                tabView._sold = tab.Sale ?? null;
                tabletList.Add(tabView);
            }

            return View(tabletList.AsEnumerable());
        }
Example #2
0
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Tablet tablet = db.Tablets.Find(id);
            if (tablet == null)
            {
                return HttpNotFound();
            }
            TabletViewModel details = new TabletViewModel();
            details._tablet = tablet;

            details._lastcheckout = tablet.Checkouts.Any() ? tablet.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 = tablet.Sale == null ? null : tablet.Sale;

            return View(details);
        }