public async Task<IActionResult> Edit(Guid id) { var menuItem = await _menuService.GetMenuItemByIdAsync(id); if (menuItem == null) { return NotFound(id); } var viewModel = new EditMenuItemViewModel { ItemId = menuItem.Id, Caption = menuItem.Caption, CssClass = menuItem.CssClass, Url = menuItem.Url }; return View(viewModel); }
public async Task<IActionResult> Edit(EditMenuItemViewModel viewModel) { if (ModelState.IsValid) { var updateCommand = new UpdateMenuItemCommand { Id = viewModel.ItemId, CssClass = viewModel.CssClass, Url = viewModel.Url, Caption = viewModel.Caption }; var result = await _commandDispacher.ExecuteAsync(updateCommand); if (result.Success) { return RedirectToAction("Index", "Menu"); } ModelState.AddCommandErrors(result); } return View(viewModel); }