public async Task <IActionResult> Edit(Guid id, EditConcernViewModel model) { if (id != model.Id) { return(NotFound()); } if (await ConcernNameExistsAsync(model.Name, id)) { ModelState.AddModelError("Name", "The name already exists."); } string msg; if (ModelState.IsValid) { var item = new Concern() { Id = model.Id, Name = model.Name, Active = model.Active }; try { _cache.Remove(CacheKeys.AreasOfConcernSelectList); _context.Update(item); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!(await ConcernExists(model.Id))) { return(NotFound()); } else { throw; } } msg = string.Format("The {0} was updated.", objectDisplayName); TempData.SaveAlertForSession(msg, AlertStatus.Success, "Success"); return(RedirectToAction("Details", new { id = model.Id })); } msg = string.Format("The {0} was not updated. Please fix the errors shown below.", objectDisplayName); ViewData["AlertMessage"] = new AlertViewModel(msg, AlertStatus.Error, "Error"); return(View(model)); }
public async Task <IActionResult> Edit(Guid id) { if (id == null) { return(NotFound()); } var item = await _context.LookupConcerns.AsNoTracking() .Where(m => m.Id == id) .SingleOrDefaultAsync(); if (item == null) { return(NotFound()); } var model = new EditConcernViewModel(item); return(View(model)); }