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