Esempio n. 1
0
        public ActionResult Edit(TabletEditModel model)
        {
            if (ModelState.IsValid)
            {
                Tablet _tablet = db.Tablets.Find(model.TabletId);

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

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

            Tablet _tablet = db.Tablets.Find(id);
            if (_tablet == null)
            {
                return HttpNotFound();
            }

            TabletEditModel model = new TabletEditModel(_tablet);

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

            return View(model);
        }