示例#1
0
 public LaptopEditModel(Laptop _laptop)
 {
     this.LaptopId = _laptop.LaptopId;
     this.EquipmentName = _laptop.EquipmentName;
     this.SerialNumber = _laptop.SerialNumber;
     this.PurchasePrice = _laptop.PurchasePrice;
     this.Discarded = _laptop.Discarded;
     this.LostOrStolen = _laptop.LostOrStolen;
     this.isCheckedOut = _laptop.isCheckedOut;
     this.ApplicationUserId = _laptop.ApplicationUser.Id;
     this.Checkouts = _laptop.Checkouts == null ? new List<CheckoutViewModel>() { } : _laptop.Checkouts
         .Select(x => new CheckoutViewModel
         {
             dtCheckedOut = x.dtCheckedOut,
             dtReturned = x.dtReturned,
             Username = x.ApplicationUser.FirstName + " " + x.ApplicationUser.LastName
         })
         .ToList();
     if (_laptop.Sale != null)
     {
         this.dtSold = _laptop.Sale.dtSold;
         this.SalePrice = _laptop.Sale.SalePrice;
     }
 }
示例#2
0
        public ActionResult Create(EquipmentCreateModel model)
        {
            if (ModelState.IsValid)
            {
                Laptop _laptop = new Laptop
                    {
                        ApplicationUser = um.FindById(model.ApplicationUserId),
                        EquipmentName = model.EquipmentName,
                        SerialNumber = model.SerialNumber,
                        PurchasePrice = model.PurchasePrice,
                        isCheckedOut = false
                    };
                db.Laptops.Add(_laptop);
                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);
        }