public async Task <AjaxResponse> SaveRoleModel(RoleInput model) { var isRepeat = _sysRolesRepository.GetAllList(w => w.RoleName == model.RoleName && w.Id != model.ID).Any(); if (isRepeat) { throw new UserFriendlyException("角色名称重复", "您设置的角色名称" + model.RoleName + "重复!"); } if (model.ID == null) { SysRoles modelInput = ObjectMapper.Map <SysRoles>(model); await _sysRolesRepository.InsertAndGetIdAsync(modelInput); } else { long id = Convert.ToInt64(model.ID); //获取需要更新的数据 SysRoles data = _sysRolesRepository.Get(id); //映射需要修改的数据对象 SysRoles m = ObjectMapper.Map(model, data); //提交修改(实际上属于同一个工作单元执行修改可以忽略) await _sysRolesRepository.UpdateAsync(m); //修改角色信息后移除缓存 _cacheManagerExtens.RemoveRoleToPermissionCache(id); } return(new AjaxResponse { Success = true }); }
public async Task <AjaxResponse> SaveRoleModel(RoleInput model) { if (model.ID == null) { SysRoles modelInput = model.MapTo <SysRoles>(); await _sysRolesRepository.InsertAndGetIdAsync(modelInput); } else { long id = Convert.ToInt64(model.ID); //获取需要更新的数据 SysRoles data = _sysRolesRepository.Get(id); //映射需要修改的数据对象 SysRoles m = ObjectMapper.Map(model, data); //提交修改(实际上属于同一个工作单元执行修改可以忽略) await _sysRolesRepository.UpdateAsync(m); //修改角色信息后移除缓存 _cacheManagerExtens.RemoveRoleToPermissionCache(id); } return(new AjaxResponse { Success = true }); }