public async Task <ActionResult> Edit(ProcedureCategoryViewModel procedureCategoryViewModel) { if (ModelState.IsValid) { await _procedureCategoryService.Edit(procedureCategoryViewModel.MapToDto()); return(RedirectToAction("Index")); } return(View(procedureCategoryViewModel)); }
public static ProcedureCategoryDto MapToDto(this ProcedureCategoryViewModel viewModel) { if (viewModel == null) { return(null); } return(new ProcedureCategoryDto { Id = viewModel.Id, Name = viewModel.Name, Description = viewModel.Description }); }
public ActionResult Create(ProcedureCategoryViewModel categoryViewModel) { ProcedureCategory category = null; if (ModelState.IsValid) { category = new ProcedureCategory() { Name = categoryViewModel.Name, Description = categoryViewModel.Description }; db.ProcedureCategories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(categoryViewModel)); }
public ActionResult Edit(ProcedureCategoryViewModel categoryViewModel) { ProcedureCategory category = null; if (ModelState.IsValid) { category = new ProcedureCategory() { Id = category.Id, Name = category.Name, Description = category.Description }; db.Entry(category).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(categoryViewModel)); }
// GET: Categories/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProcedureCategory category = db.ProcedureCategories.Find(id); if (category == null) { return(NotFound()); } ProcedureCategoryViewModel viewModel = new ProcedureCategoryViewModel() { Id = category.Id, Name = category.Name, Description = category.Description }; return(View(viewModel)); }
// GET: Category/Create public ActionResult Create() { ProcedureCategoryViewModel viewModel = new ProcedureCategoryViewModel(); return(View(viewModel)); }