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