public async Task <PermissionDto> Put(PermissionDto permission) { var model = _mapper.Map <PermissionModel>(permission); var entity = _mapper.Map <PermissionEntity>(model); var result = await _repository.UpdateAsync(entity); return(_mapper.Map <PermissionDto>(result)); }
public void Should_not_have_error_when_Name_is_specified() { var model = new PermissionDto { Name = "Jadhiel" }; var result = validator.TestValidate(model); result.ShouldNotHaveValidationErrorFor(p => p.Name); }
public async Task <IActionResult> Post([FromBody] PermissionDto permission) { if (permission.Id != 0) { return(StatusCode(StatusCodes.Status400BadRequest, "Identity insert is not permitted.")); } return(await SaveAndReturnEntityAsync(async() => await _permissionService.SaveAndReturnEntityAsync(permission))); }
public void Should_not_have_error_when_Date_is_specified() { var model = new PermissionDto { Date = DateTime.Now }; var result = validator.TestValidate(model); result.ShouldNotHaveValidationErrorFor(p => p.Date); }
public async Task <IActionResult> Put(int id, [FromBody] PermissionDto permission) { if (id == 0 || permission.Id == 0) { return(StatusCode(StatusCodes.Status400BadRequest, "Id needs to be greater than 0.")); } return(await SaveAndReturnEntityAsync(async() => await _permissionService.SaveAndReturnEntityAsync(permission))); }
public void Should_have_error_when_Name_is_null() { var model = new PermissionDto { Name = null }; var result = validator.TestValidate(model); result.ShouldHaveValidationErrorFor(p => p.Name); }
public bool Remove(PermissionDto Permission) { ResponseDto response = PermissionServiceAdapter.Execute(s => s.Delete(Permission)); if (response.Response.HasException) { return(false); } return(true); }
public async Task <bool> EditAsync(PermissionDto model) { if (model == null) { return(false); } var entity = model.MapTo <PermissionInfo>(); return(permssionManage.EditTo(entity) ? await context.SaveChangesAsync() > 0 : false); }
private void match(TreeNode node, IList <String> permissionIds) { PermissionDto p = (PermissionDto)node.Tag; node.Checked = permissionIds.Contains(p.id); foreach (TreeNode leaf in node.Nodes) { match(leaf, permissionIds); } }
[HttpPut, HttpPost] // ToDo: temporary - Allow HttpPost because permission can be created from edit mode public async Task <PermissionDto> UpdateAsync(PermissionDto permission) { if (permission?.Id == emptyId) { permission.Id = null; return(await CreateAsync(permission)); } return(ObjectMapper.Map <PermissionDto>(await _shaPermissionManager.EditPermissionAsync(permission))); }
public static Permission To(PermissionDto dto) { return(new Permission { Id = dto.Id, Name = dto.Name, Value = dto.Value, Users = dto.Users != null?dto.Users.Select(UserDtoMapper.To).ToList() : null, }); }
internal static Permission FromDto(PermissionDto dto) { return(new Permission { Id = dto.Id, Name = dto.Name, RoleId = dto.RoleId, IsGranted = dto.IsGranted }); }
public Response <PermissionDto> Update(PermissionDto data, int id) { var permission = _permissions.Include(pt => pt.PermissionType).SingleOrDefault(p => p.Id == id); var response = new Response <PermissionDto> { Action = "Update" }; if (permission == null) { response.Error = new Error { Name = "NotFound", Detail = "The permission your are trying to edit can not be found" }; return(response); } var permissionLogData = new PermissionDto { PermissionType = new PermissionTypeDto { Description = permission.PermissionType.Description, Id = permission.PermissionType.Id }, EmployeeLastName = permission.EmployeeLastName, EmployeeName = permission.EmployeeName }; permission.EmployeeLastName = data.EmployeeLastName; permission.EmployeeName = data.EmployeeName; permission.PermissionTypeId = data.PermissionType.Id; try { SavePermission(); response.Succeed = true; response.Body.Add(data); var responseLog = _permissionLogServices.Create(permissionLogData, "Update"); if (!responseLog.Succeed) { response.Error = new Error { Name = "¡Permission Log Error!", Detail = "We could not add log for this action" }; } return(response); } catch (Exception e) { response.Error = new Error { Name = e.Source, Detail = e.Message }; return(response); } }
/// <summary> /// 删除权限 /// </summary> /// <param name="dto">传入权限信息</param> public void DeletePermission(PermissionDto dto) { Permission permission = _permissionRepository.Get(dto.Id); List <Permission> children = _permissionRepository.Table.Where(t => t.ParentId == dto.Id).ToList(); //递归删除子集 children.ForEach(p => DeletePermission(new PermissionDto { Id = p.Id })); _permissionRepository.Delete(permission); }
/// <summary> /// 修改权限 /// </summary> /// <param name="dto">传入权限信息</param> public void ModifyPermission(PermissionDto dto) { Permission parentPermission = _permissionRepository.Get(dto.ParentId); Permission entity = _permissionRepository.Get(dto.Id); entity.MenuId = dto.MenuId; entity.ActionId = dto.ActionId; entity.Name = dto.Name; entity.Parent = parentPermission; _permissionRepository.Update(entity); }
/// <summary> /// Saves changes in PermissionDto. /// </summary> /// <param name="dto">The dto.</param> public static void SavePermission(PermissionDto dto) { if (dto == null) { throw new ArgumentNullException("dto", String.Format("PermissionDto can not be null")); } PermissionAdmin admin = new PermissionAdmin(dto); admin.Save(); }
public void Handle(CreatePermissionEvent @event) { var permissionDto = new PermissionDto { Id = @event.Id, Name = @event.Name, Pattern = @event.Pattern }; this._permissionDocumentService.Add(permissionDto); }
public PermissionDto Insert(PermissionDto Permission) { PermissionDto result = (PermissionDto)PermissionServiceAdapter.Execute(s => s.Insert(Permission)); if (result.Response.HasException) { return(null); } Permission.PermissionId = result.PermissionId; return(Permission); }
public static Permission ToPermission(this PermissionDto vm) { return(new Permission() { DisplayName = vm.displayName, Level = vm.level, Name = vm.name, ParentId = vm.parentId, ID = vm.permissionID, }); }
public static PermissionDto Map(this Permission source) { var target = new PermissionDto { Id = source.Id, Key = source.Key, PermissionTypeId = source.PermissionTypeId }; return(target); }
public PermissionDto GetPermission(int PermissionId) { Core.Entities.Permission.Permission permission = _permissionRepository.Get(PermissionId); if (permission.IsDeleted) { return(null); } PermissionDto permissionDto = Mapper.Map <PermissionDto>(permission); return(permissionDto); }
public async Task <PermissionDto> GetPermissionTreeViewAsync(string[] checkedPermissions) { List <PermissionDto> permissions = await GetAllPermissionDto(); foreach (PermissionDto permission in permissions) { permission.Checked = checkedPermissions.Contains(permission.Key); } PermissionDto rootNode = permissions.ToTreeView("rootkey"); return(rootNode); }
public async Task <bool> UpdatePermissionAsync(PermissionDto permissionDto) { var permission = await this._permissionRep.GetAsync(permissionDto.Id); permission .ChangeName(permissionDto.Name) .ChangeOrSetUrl(permissionDto.Url) .SyncObjectState(ObjectState.Modified); // Same with SyncObjectState(ObjectState.Modified) // this._permissionRep.Update(permission); return(await Task.FromResult(true)); }
public async Task <PermissionDto> AddPermission(PermissionDto permissionDto) { var permission = _mapper.Map <Permission>(permissionDto); permission.PermissionType = await _unitOfWork.PermissionTypeRepository.GetByIdAsync(permission.PermissionType.Id); await _unitOfWork.PermissionRepository.AddAsync(permission); await _unitOfWork.SaveAsync(); return(_mapper.Map <PermissionDto>(permission)); }
private bool SetPermission(PermissionDto dto) { CheckPermission(dto);//检查用户输入 if (dto.Id != Guid.Empty) { PermissionDto dbDto = Dbc.Db.GetById <PermissionDto>(dto.Id); ExHelper.ThrowIfNull(dbDto, "查找更新记录失败."); dbDto.CopyTo(dto, a => a.Id); } Dbc.Db.Set(dto); return(true); }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs) { PermissionDto ds = new PermissionDto(); global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); global::System.Xml.Schema.XmlSchemaAny any = new global::System.Xml.Schema.XmlSchemaAny(); any.Namespace = ds.Namespace; sequence.Items.Add(any); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte()));) { ; } if ((s1.Position == s1.Length)) { return(type); } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return(type); }
public JsonResult CreateOrUpdate(PermissionDto model) { if (model.Id == 0) { this.Create(model); } else { this.Update(model); } return(Json(1, JsonRequestBehavior.AllowGet)); }
private void AddChild(PermissionDto perm, List <PermissionDto> list) { var child = list.Where(x => x.ParentName == perm.Name).ToList(); perm.Child = child; child.ForEach(x => { x.Parent = null; list.Remove(x); AddChild(x, list); }); }
public void PermissionDto_Extension_AsEntity_Null() { // Arrange PermissionDto permission = null; // Act var result = permission.AsEntity(); // Assert Assert.IsNull(result); Assert.AreEqual(null, result); }
public static PermissionDto Map(Permission entity) { var dto = new PermissionDto(); dto.Id = entity.Id; dto.Description = entity.Description; dto.CreatedOn = entity.CreatedOn; dto.LastModifiedOn = entity.LastModifiedOn; dto.Deleted = entity.Deleted; //todo: don't do LastModifiedBy in here, have a 'MapWithLastModifiedBy' method - otherwise infinately recursive call. //todo: don't do CreatedBy in here, have a 'MapWithCreatedBy' method - otherwise infinately recursive call. return(dto); }
public async Task AddOrUpdate(PermissionDto permission) { await permissionRepository.InsertOrUpdateAsync(permission.MapTo<PermissionInfo>()); }