Пример #1
0
        public ActionResult Index()
        {
            List<MobilePhoneViewModel> mobilePhoneList = new List<MobilePhoneViewModel>();
            var mobiles = db.MobilePhones.ToList();

            foreach (MobilePhone mobile in mobiles)
            {
                MobilePhoneViewModel mobileView = new MobilePhoneViewModel();
                ApplicationUser _user = mobile.ApplicationUser;
                mobileView._mobilePhone = mobile;
                mobileView._username = _user.FirstName + " " + _user.LastName;
                mobileView._lastcheckout = mobile.Checkouts
                    .OrderBy(x => x.dtCheckedOut)
                    .LastOrDefault() == null ? null :
                        mobile.Checkouts.OrderBy(x => x.dtCheckedOut)
                        .Select(x => new CheckoutViewModel
                        {
                            dtCheckedOut = x.dtCheckedOut,
                            dtReturned = x.dtReturned,
                            Username = x.ApplicationUser.FirstName + " " + x.ApplicationUser.LastName
                        }).LastOrDefault();
                mobileView._sold = mobile.Sale ?? null;
                mobilePhoneList.Add(mobileView);
            }

            return View(mobilePhoneList.AsEnumerable());
        }
Пример #2
0
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            MobilePhone mobilePhone = db.MobilePhones.Find(id);
            if (mobilePhone == null)
            {
                return HttpNotFound();
            }
            MobilePhoneViewModel details = new MobilePhoneViewModel();
            details._mobilePhone = mobilePhone;

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

            return View(details);
        }