public ActionResult AddOrUpdate(MenuItemPostViewModel entity) { SetAddOrUpdateViewBags(entity.Id); if (ModelState.IsValid) { if (entity.Id.HasValue) { TempData["result"] = menuItemService.UpdateMenuItem(entity); } else { TempData["result"] = menuItemService.AddMenuItem(entity); } } return(View()); }
public ServiceResult AddMenuItem(MenuItemPostViewModel entity) { var userRoles = userRoleService.GetUserRolesByIds(entity.UserRoleIds); menuItemRepository.Add(new MenuItem { Title = entity.Title, Action = entity.Action, Controller = entity.Controller, Area = entity.Area, Icon = entity.Icon, RowIndex = entity.RowIndex, ParentMenuItemId = entity.ParentMenuItemId, MenuId = entity.MenuId, UserRoles = userRoles }); return(ServiceResult.GetAddResult(uow.Commit() > 0)); }
public ServiceResult UpdateMenuItem(MenuItemPostViewModel entity) { var userRoles = userRoleService.GetUserRolesByIds(entity.UserRoleIds); var menuItem = menuItemRepository.Get(w => w.Id == entity.Id.Value, i => i.UserRoles); menuItem.Title = entity.Title; menuItem.Action = entity.Action; menuItem.Controller = entity.Controller; menuItem.Area = entity.Area; menuItem.Icon = entity.Icon; menuItem.RowIndex = entity.RowIndex; menuItem.ParentMenuItemId = entity.ParentMenuItemId; menuItem.MenuId = entity.MenuId; menuItem.UserRoles = userRoles; menuItemRepository.Update(menuItem); return(ServiceResult.GetUpdateResult(uow.Commit() > 0)); }