コード例 #1
0
        public ActionResult Edit(MobilePhoneEditModel model)
        {
            if (ModelState.IsValid)
            {
                MobilePhone _mobilePhone = db.MobilePhones.Find(model.MobilePhoneId);

                _mobilePhone.ApplicationUser = um.FindById(model.ApplicationUserId);
                _mobilePhone.Discarded = model.Discarded;
                _mobilePhone.EquipmentName = model.EquipmentName;
                _mobilePhone.LostOrStolen = model.LostOrStolen;
                _mobilePhone.PurchasePrice = model.PurchasePrice;
                _mobilePhone.SerialNumber = model.SerialNumber;

                if (model.dtSold != null)
                {
                    Sale _sale = new Sale
                        {
                            dtSold = (DateTime)model.dtSold,
                            SalePrice = model.SalePrice ?? 0.0
                        };
                    db.Sales.Add(_sale);
                    db.SaveChanges();
                    _mobilePhone.Sale = _sale;
                }

                db.Entry(_mobilePhone).State = EntityState.Modified;
                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);
        }
コード例 #2
0
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            MobilePhone _mobilePhone = db.MobilePhones.Find(id);
            if (_mobilePhone == null)
            {
                return HttpNotFound();
            }

            MobilePhoneEditModel model = new MobilePhoneEditModel(_mobilePhone);

            string selectId = _mobilePhone.ApplicationUser.Id;
            model.Users = FullNameUserList(db, selectId);

            return View(model);
        }