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