public async Task <IActionResult> Edit(EditAreaViewModel model) { if (ModelState.IsValid) { try { var area = await areaApi.GetAreaById(model.Id); if (area == null) { return(NotFound()); } area.Name = model.Name; await areaApi.UpdateArea(area); return(RedirectToAction("Index")); } catch (Exception ex) { ViewBag.Error = "Failed to Edit a Area"; return(View(model)); } } return(View(model)); }
public async Task <IActionResult> Edit([FromRoute] int id = 0) { if (id == 0) { return(BadRequest("Id is null!")); } var area = await areaApi.GetAreaById(id); if (area == null) { return(NotFound()); } EditAreaViewModel editAreaViewModel = new EditAreaViewModel() { Name = area.Name, }; return(View(editAreaViewModel)); }