Esempio n. 1
0
        public ActionResult Index()
        {
            List<TelephoneViewModel> telephoneList = new List<TelephoneViewModel>();
            var phones = db.Telephones.ToList();

            foreach (Telephone phone in phones)
            {
                TelephoneViewModel phoneView = new TelephoneViewModel();
                ApplicationUser _user = phone.ApplicationUser;
                phoneView._telephone = phone;
                phoneView._username = _user.FirstName + " " + _user.LastName;
                phoneView._lastcheckout = phone.Checkouts
                    .OrderBy(x => x.dtCheckedOut)
                    .LastOrDefault() == null ? null :
                        phone.Checkouts.OrderBy(x => x.dtCheckedOut)
                        .Select(x => new CheckoutViewModel
                        {
                            dtCheckedOut = x.dtCheckedOut,
                            dtReturned = x.dtReturned,
                            Username = x.ApplicationUser.FirstName + " " + x.ApplicationUser.LastName
                        }).LastOrDefault();
                phoneView._sold = phone.Sale ?? null;
                telephoneList.Add(phoneView);
            }

            return View(telephoneList.AsEnumerable());
        }
Esempio n. 2
0
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Telephone telephone = db.Telephones.Find(id);
            if (telephone == null)
            {
                return HttpNotFound();
            }
            TelephoneViewModel details = new TelephoneViewModel();
            details._telephone = telephone;

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

            return View(details);
        }