// // GET: /ImportBatches/Edit/5 public ActionResult Edit(int id) { var model = new ImportBatchesViewModelItem(); model = model.Populate(db, id); if (model == null) { return(HttpNotFound()); } return(View(model)); }
public ActionResult Edit(ImportBatchesViewModelItem model) { model.ValidateEntry(db, ModelState); if (ModelState.IsValid) { if (model.Current) { ImportBatch currentBatch = db.ImportBatches.FirstOrDefault(x => x.Current && x.ImportBatchId != model.ImportBatchId); if (currentBatch != null) { currentBatch.Current = false; db.Entry(currentBatch).State = EntityState.Modified; } } var item = model.ToEntity(); db.Entry(item).State = EntityState.Modified; db.SaveChanges(); ShowGenericSavedMessage(); return(RedirectToAction("Index")); } return(View(model)); }