Exemplo n.º 1
0
        public ActionResult Edit(DesktopEditModel model)
        {
            if (ModelState.IsValid)
            {
                Desktop _desktop = db.Desktops.Find(model.DesktopId);

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

                db.Entry(_desktop).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);
        }
Exemplo n.º 2
0
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            Desktop _desktop = db.Desktops.Find(id);
            if (_desktop == null)
            {
                return HttpNotFound();
            }

            DesktopEditModel model = new DesktopEditModel(_desktop);

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

            return View(model);
        }