public bool AddPermission(List <PermissionViewModel> listPermissionVM) { foreach (var item in listPermissionVM) { var permission = Mapper.Map <PermissionViewModel, Permission>(item); _permissionRepository.Add(permission); } return(true); }
public void CreateIfNotExist(IList <CreatePermissionRequest> pers) { using (App.Common.Data.IUnitOfWork uow = new App.Common.Data.UnitOfWork(RepositoryType.MSSQL)) { IPermissionRepository perRepository = IoC.Container.Resolve <IPermissionRepository>(uow); foreach (CreatePermissionRequest perRequest in pers) { try { this.ValidateCreatePermissionRequest(perRequest); Permission permission = new Permission(perRequest.Name, perRequest.Key, perRequest.Description); perRepository.Add(permission); } catch (ValidationException ex) { if (ex.HasExceptionKey("security.addPermission.validation.nameAlreadyExist")) { continue; } if (ex.HasExceptionKey("security.addPermission.validation.keyAlreadyExist")) { continue; } } } uow.Commit(); } }
public async Task HandleAsync(CreatePermissionCommand message, CancellationToken token = default(CancellationToken)) { var permission = Permission.Create(message.PermissionId, message.Name, message.Code); _permissions.Add(permission); await _permissions.SaveChangesAsync(token); }
/// <summary> /// 添加权限 /// </summary> /// <param name="dto">传入权限信息</param> public void AddPermission(PermissionDto dto) { Permission entity = dto.ToEntity <Permission>(); Permission parent = _permissionRepository.Get(dto.ParentId); entity.Parent = parent; _permissionRepository.Add(entity); }
public async Task <Permission> Handle(CreatePermissionCommand message, CancellationToken cancellationToken) { var permission = await Permission.Factory.CreateNewEntry(_repository, message.Name, message.Description); await _repository.Add(permission); return(permission); }
public Permission AddPermission(Guid roleId, Guid workingEntityOperationId, Guid ruleId) { var permission = _permissionFactory.Create(roleId, workingEntityOperationId, ruleId); _permissionRepository.Add(permission); return(permission); }
public async Task <Guid> CreatePermissionAsync(CreatePermissionCommand command) { var permission = new Permission(command.Code, command.Name, command.Description, command.IsEnabled); _permissionRepository.Add(permission); await _unitOfWork.CommitAsync(); return(permission.Id); }
public void Create() { if (input.Any()) { var domain = new List <Permission>(); var allFatherPermissions = input.GroupBy(x => x.ServerName).Select(x => x.Key).ToList(); if (!allFatherPermissions.Any()) { throw new DomainException("服务名无效!"); } repository.Delete(x => true);//直接删除所有 allFatherPermissions.ForEach(x => { var permission = new Permission(); permission.CreatePermission(Guid.Empty, x, ""); repository.Add(permission); var child = input.Where(y => y.ServerName == x).ToList(); if (!child.Any()) { throw new DomainException($"服务{x}下没有有效接口!"); } else { child.ForEach(y => { if (string.IsNullOrEmpty(y.Path)) { throw new DomainException($"服务{x}下没有有效接口地址!"); } var childpermission = new Permission(); childpermission.CreatePermission(permission.Id, y.PermissionName, y.Path); repository.Add(childpermission); }); } }); } else { throw new DomainException("请至少输入一个权限"); } }
public BaseContent CreatePermission(BaseContent permission) { CreatePermissionValidation(permission); using (App.Common.Data.IUnitOfWork uow = new App.Common.Data.UnitOfWork(new App.Context.AppDbContext(IOMode.Write))) { IPermissionRepository perRepository = IoC.Container.Resolve <IPermissionRepository>(uow); Permission per = new Permission(permission); perRepository.Add(per); uow.Commit(); return(per); } }
public CreatePermissionResponse Create(CreatePermissionRequest permission) { this.ValidateCreatePermissionRequest(permission); using (App.Common.Data.IUnitOfWork uow = new App.Common.Data.UnitOfWork(RepositoryType.MSSQL)) { IPermissionRepository perRepository = IoC.Container.Resolve <IPermissionRepository>(uow); Permission per = new Permission(permission.Name, permission.Key, permission.Description); perRepository.Add(per); uow.Commit(); return(ObjectHelper.Convert <CreatePermissionResponse>(per)); } }
public async Task <ActionResult> Add(PermissionViewModel permissionViewModel) { if (!ModelState.IsValid) { return(CustomResponse(permissionViewModel)); } var permission = _mapper.Map <Permission>(permissionViewModel); permission = await _permissionRepository.Add(permission); return(CustomResponse(_mapper.Map <PermissionViewModel>(permission))); }
/// <summary> /// Adds new permission to the database /// </summary> /// <param name="permission">Permission information to be added. Instance of <see cref="PermissionDomain"/></param> /// <returns>PermissionId of the newly created permission</returns> public int AddPermission(PermissionDomain permission) { ValidatePermissionModel(permission); //Check if code exists var permissionWithProvidedCode = _permissionRepository.GetByCode(permission.Code.SafeTrim()); if (permissionWithProvidedCode != null) { throw new NsiArgumentException(MembershipMessages.PermissionCodeAlreadyExists, Common.Enumerations.SeverityEnum.Warning); } return(_permissionRepository.Add(permission)); }
public void SavePermission(List <PermissionViewModel> permissions, Guid roleId) { var allPermissions = _permissionRepository.FindAll(x => x.RoleId == roleId); _permissionRepository.RemoveMultiple(allPermissions.ToList()); if (permissions.Count > 0) { var permissionModels = Mapper.Map <List <PermissionViewModel>, List <Permission> >(permissions); foreach (var pm in permissionModels) { _permissionRepository.Add(pm); } } }
public void UpdatePermission(List <PermissionViewModel> permissionViewModels, Guid roleId) { var permissions = Mapper.Map <List <PermissionViewModel>, List <Permission> >(permissionViewModels); var oldPermissions = _permissionRepository.FindAll().Where(r => r.RoleId.Equals(roleId)).ToList(); if (oldPermissions.Count > 0) { _permissionRepository.RemoveMultiple(oldPermissions); } foreach (var permission in permissions) { _permissionRepository.Add(permission); } }
public async Task <MessageModel <string> > Post([FromBody] Permission permission) { var data = new MessageModel <string>(); var id = (await _permissionRepository.Add(permission)); data.success = id > 0; if (data.success) { data.response = id.ObjToString(); data.msg = "添加成功"; } return(data); }
public void SavePermission(List <PermissionViewModel> permissionVms, Guid roleId) { var permissions = Mapper.Map <List <PermissionViewModel>, List <Permission> >(permissionVms); var oldPermission = _permissionRepository.FindAll().Where(x => x.RoleId == roleId).ToList(); if (oldPermission.Count > 0) { _permissionRepository.RemoveMultiple(oldPermission); } foreach (var permission in permissions) { _permissionRepository.Add(permission); } _unitOfWork.Commit(); }
public async Task <IActionResult> CreateUserAsync([FromBody] Permission permission) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var createdPermission = await _permissionRepository.Add(permission); return(CreatedAtAction( nameof(GetByIdAsync), new { id = createdPermission.PermissionId }, createdPermission )); }
public void CreateIfNotExist(IList <Permission> pers) { using (App.Common.Data.IUnitOfWork uow = new App.Common.Data.UnitOfWork(new App.Context.AppDbContext(IOMode.Write))) { IPermissionRepository perRepository = IoC.Container.Resolve <IPermissionRepository>(uow); foreach (Permission per in pers) { if (perRepository.GetByKey(per.Key) != null) { continue; } perRepository.Add(per); } uow.Commit(); } }
public async Task SavePermission(List <PermissionViewModel> permissionVms, Guid roleId) { var permissions = new PermissionViewModel().Map(permissionVms); var oldPermission = (await _permissionRepository.FindAll()).AsParallel().AsOrdered().WithDegreeOfParallelism(2).Where(x => x.RoleId == roleId); if (oldPermission.ToList().Any()) { await _permissionRepository.RemoveMultiple(oldPermission.ToList()); } foreach (var permission in permissions) { await _permissionRepository.Add(permission); } _unitOfWork.Commit(); }
public CreateResult <int> CreatePermission(BaseEntityDto permissionDto) { var result = GetDefault <CreateResult <int> >(); if (IsExisted(permissionDto.Name)) { result.Message = "FUNC_NAME_HAS_EXIST"; return(result); } var permission = new Permission() { Name = permissionDto.Name }; _permissionRepository.Add(permission); _permissionRepository.Commit(); result.IsCreated = true; result.Id = permission.Id; return(result); }
public CreatePermissionResponse CreatePermission(CreatePermissionRequest request) { CreatePermissionResponse response = new CreatePermissionResponse(); Permission permission = new Permission(); permission.PermissionName = request.PermissionName; permission.PermissionDescription = request.PermissionDescription; permission.ControllerName = request.ControllerName; permission.ActionName = request.ActionName; permission.IsAnonymous = request.IsAnonymous; permission.IsDefaultAllow = request.IsDefaultAllow; permission.Roles = request.Roles.ConvertToRoles(); permission.Users = request.Users.ConvertToUsers(); if (permission.GetBrokenRules().Count() > 0) { response.Errors = permission.GetBrokenRules().ToList(); } else { try { _permissionRepository.Add(permission); _uow.Commit(); response.Errors = new List <BusinessRule>(); } catch (Exception ex) { List <BusinessRule> errors = new List <BusinessRule>(); do { errors.Add(new BusinessRule("DAL", "DAL_ERROR: " + ex.Message)); ex = ex.InnerException; } while (ex != null); response.Errors = errors; } } return(response); }
public GeneralResponse AddPermission(AddPermissionRequest request) { GeneralResponse response = new GeneralResponse(); try { Permission permission = new Permission(); permission.ID = Guid.NewGuid(); permission.CreateDate = PersianDateTime.Now; permission.CreateEmployee = _employeeRepository.FindBy(request.CreateEmployeeID); permission.Group = request.Group; permission.Key = request.Key; permission.Title = request.Title; permission.RowVersion = 1; _permissionRepository.Add(permission); _uow.Commit(); // Validation if (permission.GetBrokenRules().Count() > 0) { foreach (BusinessRule businessRule in permission.GetBrokenRules()) { response.ErrorMessages.Add(businessRule.Rule); } return(response); } } catch (Exception ex) { response.ErrorMessages.Add(ex.Message); } return(response); }
public void Add(Permissions permissions) { _permissionsRepository.Add(permissions); _unitOfWork.Commit(); }
public void Add(Permission permission) { _permissionRepository.Add(permission); }
public ActionResult <Permission> Add(Permission permission) { _permissionRepository.Add(permission); _permissionRepository.Commit(); return(permission); }
public void Add(PermissionViewModel permission) { _permissionRepository.Add(_mapper.Map <Permission>(permission)); }
public void Create(Permission permission) { _permissionRepository.Add(permission); _unitOfWork.Commit(); }
/// <summary> /// Add a new permission /// </summary> /// <param name="permission"></param> public void Add(Permission permission) { permission.Name = StringUtils.SafePlainText(permission.Name); _permissionRepository.Add(permission); }
public void Add(Permission obj) { _repo.Add(obj); _uow.Commit(); }
public ActionResult <ApiResponse <UserDto> > Update(int id, UserDto item) { var response = new ApiResponse <UserDto>(); UserUpdateDto userDto = _mapper.Map <UserUpdateDto>(item); HierarchyUpdateDto hierarchyUpdateDto = _mapper.Map <HierarchyUpdateDto>(item.Hierarchies[0]); var permissions = _mapper.Map <List <PermissionUpdateDto> >(item.Hierarchies[0].Permissions); try { var user = _userRepository.Find(c => c.Id == id); //TODO Pending validate District Id if (user == null) { response.Message = $"User id { id } Not Found"; return(NotFound(response)); } var hie = _hierarchyRepository.Find(h => h.Id == item.Hierarchies[0].Id); if (hie == null) { response.Message = $"User id { id } Not Found"; return(NotFound(response)); } //var per = _permissionRepository.FindBy(p => p.HierarchyId == item.Hierarchies[0].Id); //if (hie == null) //{ // response.Message = $"User id { id } Not Found"; // return NotFound(response); //} int i = 0; foreach (PermissionUpdateDto permission in permissions) { var per = _permissionRepository.Find(p => p.Id == item.Hierarchies[0].Permissions[i].Id); if (per == null) { //insert Permission permissioncreate = _permissionRepository.Add(_mapper.Map <Permission>(permission)); //response.Result = _mapper.Map<UserDto>(user); } else { //update _mapper.Map(permission, per); _permissionRepository.Update(per, item.Hierarchies[0].Permissions[i].Id); } i += 1; } _mapper.Map(hierarchyUpdateDto, hie); _hierarchyRepository.Update(hie, item.Hierarchies[0].Id); _mapper.Map(userDto, user); _userRepository.Update(user, id); response.Result = _mapper.Map <UserDto>(_userRepository.Find(u => u.Id == id)); //Hierarchy hierarchy = _mapper.Map<Hierarchy>(item.Hierarchies[0]); //_hierarchyRepository.Update(hierarchy, hierarchy.Id); } catch (Exception ex) { response.Result = null; response.Success = false; response.Message = "Internal server error"; _logger.LogError($"Something went wrong: { ex.ToString() }"); return(StatusCode(500, response)); } return(Ok(response)); }