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