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