public IHttpActionResult Edit(PermissionEditViewModel model) { var response = ResponseModelFactory.CreateInstance; using (_dbContext) { if (_dbContext.Permissions.Any(x => x.ActionCode == model.ActionCode && x.Code != model.Code)) { response.SetFailed("权限操作码已存在"); return(Ok(response)); } var entity = _dbContext.Permissions.FirstOrDefault(x => x.Code == model.Code); if (entity == null) { response.SetFailed("权限不存在"); return(Ok(response)); } entity.Name = model.Name; entity.ActionCode = model.ActionCode; entity.MenuId = model.MenuId; entity.IsDeleted = model.IsDeleted; entity.ModifiedByUserId = AuthContextService.CurrentUser.UserId; entity.ModifiedByUserName = AuthContextService.CurrentUser.DisplayName; entity.ModifiedOn = DateTime.Now; entity.Status = model.Status; entity.Description = model.Description; _dbContext.SaveChanges(); response.SetSuccess(); return(Ok(response)); } }
public IActionResult Edit(PermissionEditViewModel model) { var response = ResponseModelFactory.CreateInstance; using (_dbContext) { if (_dbContext.DncPermission.Count(x => x.ActionCode == model.ActionCode && x.Id != model.Id) > 0) { response.SetFailed("权限操作码已存在"); return(Ok(response)); } var entity = _dbContext.DncPermission.FirstOrDefault(x => x.Id == model.Id); entity.Name = model.Name; entity.ActionCode = model.ActionCode; entity.MenuGuid = model.MenuGuid; entity.IsDeleted = model.IsDeleted; entity.ModifiedByUserId = 0; entity.ModifiedByUserName = ""; entity.ModifiedOn = DateTime.Now; entity.Status = model.Status; entity.Description = model.Description; _dbContext.SaveChanges(); response.SetSuccess(); return(Ok(response)); } }
public IActionResult SaveEdit(PermissionEditViewModel model) { HttpResponseModel response = ResponseModelFactory.CreateInstance; using (this.DbContext) { if (this.DbContext.Permission.Count(x => x.ActionCode == model.ActionCode && x.Id != model.Code) > 0) { response.SetFailed("权限操作码已存在"); return(this.Ok(response)); } Permission entity = this.DbContext.Permission.FirstOrDefault(x => x.Id == model.Code); if (entity == null) { response.SetFailed("权限不存在"); return(this.Ok(response)); } entity.Name = model.Name; entity.ActionCode = model.ActionCode; entity.MenuId = model.MenuId; entity.IsEnable = model.IsEnable.Value; entity.UpdateByUserId = 1; entity.UpdateByUserName = AuthenticationContextService.CurrentUser.DisplayName; entity.CreateTime = DateTime.Now; entity.Status = model.Status; entity.Description = model.Description; this.DbContext.SaveChanges(); response.SetSuccess(); return(this.Ok(response)); } }
public IActionResult Edit(string code) { using (this.DbContext) { Permission entity = this.DbContext.Permission.FirstOrDefault(x => x.Id == code); HttpResponseModel response = ResponseModelFactory.CreateInstance; PermissionEditViewModel model = this.Mapper.Map <Permission, PermissionEditViewModel>(entity); Menu menu = this.DbContext.Menu.FirstOrDefault(x => x.Id == entity.MenuId); model.MenuName = menu.Name; response.SetData(model); return(this.Ok(response)); } }
public IActionResult Edit(PermissionEditViewModel model) { var response = ResponseModelFactory.CreateInstance; if (ConfigurationManager.AppSettings.IsTrialVersion) { response.SetIsTrial(); return(Ok(response)); } using (_dbContext) { if (_dbContext.SystemPermission.Count(x => x.ActionCode == model.ActionCode && x.SystemPermissionUuid != model.SystemPermissionUuid) > 0) { response.SetFailed("权限操作码已存在"); return(Ok(response)); } var entity = _dbContext.SystemPermission.FirstOrDefault(x => x.SystemPermissionUuid == model.SystemPermissionUuid); if (entity == null) { response.SetFailed("权限不存在"); return(Ok(response)); } if (_dbContext.SystemPermission.Count(x => x.Name == model.Name && x.SystemMenuUuid == model.SystemMenuUuid) > 1) { response.SetFailed("权限名称已存在"); return(Ok(response)); } entity.Name = model.Name; entity.ActionCode = model.ActionCode; entity.SystemMenuUuid = model.SystemMenuUuid; entity.IsDeleted = model.IsDeleted; entity.ModifiedByUserGuid = AuthContextService.CurrentUser.Guid; entity.ModifiedByUserName = AuthContextService.CurrentUser.DisplayName; entity.ModifiedOn = DateTime.Now.ToString("yyyy-MM-dd"); entity.Status = model.Status; entity.Type = model.Type; entity.Description = model.Description; int res = _dbContext.SaveChanges(); if (res > 0) { ToLog.AddLog("编辑", "成功:编辑:系统权限信息一条数据", _dbContext); } response.SetSuccess(); return(Ok(response)); } }
public async Task EditByViewModelAsync(PermissionEditViewModel viewModel) { if (viewModel == null) { throw new ArgumentNullException(nameof(viewModel)); } var permission = await FindByIdAsync(viewModel.Id); if (permission == null) { throw new ServiceException(); } _mapper.Map(viewModel, permission); await _unitOfWork.SaveAllChangesAsync(); _eventPublisher.EntityUpdated(permission); }
public async Task <ActionResult <ResponseModel> > Edit(PermissionEditViewModel model) { var response = ResponseModelFactory.CreateInstance; if (ConfigurationManager.AppSettings.IsTrialVersion) { response.SetIsTrial(); return(Ok(response)); } await using (_dbContext) { if (await _dbContext.DncPermission.CountAsync(x => x.ActionCode == model.ActionCode && x.Code != model.Code) > 0) { response.SetFailed("权限操作码已存在"); return(Ok(response)); } var entity = await _dbContext.DncPermission. FirstOrDefaultAsync(x => x.Code == model.Code); if (entity == null) { response.SetFailed("权限不存在"); return(Ok(response)); } entity.Name = model.Name; entity.ActionCode = model.ActionCode; entity.MenuGuid = model.MenuGuid; entity.IsDeleted = model.IsDeleted; entity.ModifiedByUserGuid = AuthContextService.CurrentUser.Guid; entity.ModifiedByUserName = AuthContextService.CurrentUser.DisplayName; entity.ModifiedOn = DateTime.Now; entity.Status = model.Status; entity.Description = model.Description; await _dbContext.SaveChangesAsync(); response.SetSuccess(); return(Ok(response)); } }
public ActionResult Edit(PermissionEditViewModel item) { var out_pg = CreateViewModel<PermissionEditViewModel>(); out_pg.Permission = item.Permission; string err_msg = string.Empty; bool IsSomethingToChange = false; var oldname = _userPermissionGroupRepository.FindById(item.Permission.Id).Name; if (ModelState.IsValid) { try { UpdateUserPermission(item.Permission.Id, item.Permission.Name, oldname); GroupUpdateUserPermission(item.Permission.Id, item.Permission.Name, oldname); UpdateNewOwnerName(item.Permission.Id, item.Permission.UserID); //_userPermissionGroupService.UpdateUserPermission(item.Permission.Id, item.Permission.Name); //_userPermissionGroupService.GroupUpdateUserPermission(item.Permission.Id, item.Permission.Name, oldname); } catch (Exception ex) { err_msg = ex.Message; ModelState.AddModelError("", err_msg); } if (_userPermissionGroupRepository.FindAll().Where(x => x.Name.Trim().Contains(item.Permission.Name.Trim())).Any()) { IsSomethingToChange = true; } } return Json(new { item = item.Permission, Change = IsSomethingToChange, IsSucceed = ModelState.IsValid, Msg = ModelState.IsValid ? ViewResources.SharedStrings.TimeZonesEditMessage : err_msg, DisplayMessage = !string.IsNullOrEmpty(err_msg), viewData = ModelState.IsValid ? null : this.RenderPartialView("Edit", out_pg) }); }
public void EditAdditional(PermissionEditViewModel item) { }