public TabletEditModel(Tablet _tablet)
 {
     this.TabletId = _tablet.TabletId;
     this.EquipmentName = _tablet.EquipmentName;
     this.SerialNumber = _tablet.SerialNumber;
     this.PurchasePrice = _tablet.PurchasePrice;
     this.Discarded = _tablet.Discarded;
     this.LostOrStolen = _tablet.LostOrStolen;
     this.isCheckedOut = _tablet.isCheckedOut;
     this.ApplicationUserId = _tablet.ApplicationUser.Id;
     this.Checkouts = _tablet.Checkouts == null ? new List<CheckoutViewModel>() { } : _tablet.Checkouts
         .Select(x => new CheckoutViewModel
         {
             dtCheckedOut = x.dtCheckedOut,
             dtReturned = x.dtReturned,
             Username = x.ApplicationUser.FirstName + " " + x.ApplicationUser.LastName
         })
         .ToList();
     if (_tablet.Sale != null)
     {
         this.dtSold = _tablet.Sale.dtSold;
         this.SalePrice = _tablet.Sale.SalePrice;
     }
 }
Beispiel #2
0
        public ActionResult Create(EquipmentCreateModel model)
        {
            if (ModelState.IsValid)
            {
                Tablet _tablet = new Tablet
                    {
                        ApplicationUser = um.FindById(model.ApplicationUserId),
                        EquipmentName = model.EquipmentName,
                        SerialNumber = model.SerialNumber,
                        PurchasePrice = model.PurchasePrice,
                        isCheckedOut = false
                    };
                db.Tablets.Add(_tablet);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            // Validation failed, reassign the list without assigning anything
            string selectId = model.ApplicationUserId;
            model.Users = FullNameUserList(db, selectId);

            return View(model);
        }