Пример #1
0
        public ActionResult Edit(CameraEditModel model)
        {
            if (ModelState.IsValid)
            {
                Camera _camera = db.Cameras.Find(model.CameraId);

                _camera.ApplicationUser = um.FindById(model.ApplicationUserId);
                _camera.Discarded = model.Discarded;
                _camera.EquipmentName = model.EquipmentName;
                _camera.LostOrStolen = model.LostOrStolen;
                _camera.PurchasePrice = model.PurchasePrice;
                _camera.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();
                    _camera.Sale = _sale;
                }

                db.Entry(_camera).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);
            }

            Camera _camera = db.Cameras.Find(id);
            if (_camera == null)
            {
                return HttpNotFound();
            }

            CameraEditModel model = new CameraEditModel(_camera);

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

            return View(model);
        }