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