public async Task <IActionResult> EditRestaurantCategory(EditRestaurantCategoryViewModel model) { if (ModelState.IsValid) { try { var category = await restaurantApi.GetRestaurantCaregoryById(model.Id); if (category == null) { return(NotFound()); } category.Name = model.Name; category.Priority = model.Priority; await restaurantApi.UpdateRestaurantCategory(category); return(RedirectToAction("GetAllRestaurantCategories")); } catch (Exception ex) { ViewBag.Error = "Failed to Edit a Area"; return(RedirectToAction("EditRestaurantCategory", new { id = model.Id })); } } return(View(model)); }
public async Task <IActionResult> EditRestaurantCategory([FromRoute] int id = 0) { if (id == 0) { return(BadRequest("Id is null!")); } var category = await restaurantApi.GetRestaurantCaregoryById(id); if (category == null) { return(NotFound()); } EditRestaurantCategoryViewModel editAreaViewModel = new EditRestaurantCategoryViewModel() { Name = category.Name, Priority = category.Priority, }; return(View(editAreaViewModel)); }