Beispiel #1
0
        public ActionResult Edit(NotebookEditModel model)
        {
            if (ModelState.IsValid)
            {
                Notebook _notebook = db.Notebooks.Find(model.NotebookId);

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

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

            Notebook _notebook = db.Notebooks.Find(id);
            if (_notebook == null)
            {
                return HttpNotFound();
            }

            NotebookEditModel model = new NotebookEditModel(_notebook);

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

            return View(model);
        }