public int Update(UpdateRole updateRole) { string sql = "UPDATE UpdateRoles " + "SET " + " OldVersion = @OldVersion" + ", NewVersion = @NewVersion" + ", CreateDate = @CreateDate" + ", UpdateType = @UpdateType" + ", UpdateFileID = @UpdateFileID" + ", Description = @Description" + ", CreateUserID = @CreateUserID" + " WHERE ID = @ID"; SqlParameter[] para = new SqlParameter[] { new SqlParameter("@ID", updateRole.ID) , new SqlParameter("@OldVersion", ToDBValue(updateRole.OldVersion)) , new SqlParameter("@NewVersion", ToDBValue(updateRole.NewVersion)) , new SqlParameter("@CreateDate", ToDBValue(updateRole.CreateDate)) , new SqlParameter("@UpdateType", ToDBValue(updateRole.UpdateType)) , new SqlParameter("@UpdateFileID", ToDBValue(updateRole.UpdateFileID)) , new SqlParameter("@Description", ToDBValue(updateRole.Description)) , new SqlParameter("@CreateUserID", ToDBValue(updateRole.CreateUserID)) }; return(SqlHelper.ExecuteNonQuery(sql, para)); }
public void Can_update_role() { _authCommands.CreatePermission(new CreatePermission { Name = "Test", Module = "Test" }); var createRole = new CreateRole { RoleId = Guid.NewGuid(), Permissions = _authQueries.GetPermissions().Select(p => p.Id).ToList() }; _authCommands.CreateRole(createRole); _authCommands.CreatePermission(new CreatePermission { Name = "Test1", Module = "Test1" }); var updateRole = new UpdateRole { RoleId = createRole.RoleId, Permissions = _authQueries.GetPermissions().Select(p => p.Id).ToList() }; _authCommands.UpdateRole(updateRole); var role = _authRepository.Roles.Single(r => r.Id == createRole.RoleId); role.Permissions.Count.Should().Be(updateRole.Permissions.Count); }
public static void CanUpdate(UpdateRole command, IAppEntity app) { Guard.NotNull(command, nameof(command)); var roles = app.Roles; CheckRoleExists(roles, command.Name); Validate.It(e => { if (string.IsNullOrWhiteSpace(command.Name)) { e(Not.Defined(nameof(command.Name)), nameof(command.Name)); } else if (Roles.IsDefault(command.Name)) { e(T.Get("apps.roles.defaultRoleNotUpdateable")); } if (command.Permissions == null) { e(Not.Defined(nameof(command.Permissions)), nameof(command.Permissions)); } }); }
public void Not_registered_permission_is_not_valid_for_role_editing() { _authCommands.CreatePermission(new CreatePermission { Name = "Test", Module = "Test" }); var createRole = new CreateRole { RoleId = Guid.NewGuid(), Permissions = _authQueries.GetPermissions().Select(p => p.Id).ToList() }; _authCommands.CreateRole(createRole); var model = new UpdateRole { RoleId = createRole.RoleId, Permissions = new List <Guid> { Guid.NewGuid(), _authQueries.GetPermissions().Single().Id } }; var result = _authQueries.GetValidationResult(model); result.IsValid.Should().BeFalse(); result.Errors.Single().ErrorMessage.Should().Be(ErrorsCodes.PermissionIsNotRegistered.ToString()); }
public void UpdateRole(UpdateRole command) { var role = roleDatabase.Single(x => x.Id == command.RoleId); role.Name = command.Name; role.Permissions = command.Permissions; role.Modified = DateTime.Now; }
public void CanUpdate_should_throw_exception_if_role_does_not_exists() { var command = new UpdateRole { Name = roleName, Permissions = new[] { "P1" } }; Assert.Throws <DomainObjectNotFoundException>(() => GuardAppRoles.CanUpdate(roles_0, command)); }
public async Task <IActionResult> CreatRole(UpdateRole request) { var creat = await _roleConnectAPI.CreatRole(request); return(Json(new { status = true, })); }
public void CanUpdate_should_not_throw_exception_if_properties_is_null() { var roles_1 = roles_0.Add(roleName); var command = new UpdateRole { Name = roleName, Permissions = new[] { "P1" } }; GuardAppRoles.CanUpdate(roles_1, command); }
public void CanUpdate_should_not_throw_exception_if_role_exist_with_valid_command() { var roles_1 = roles_0.Add(roleName); var command = new UpdateRole { Name = roleName, Permissions = new[] { "P1" } }; GuardAppRoles.CanUpdate(roles_1, command); }
public void CanUpdate_should_throw_exception_if_name_empty() { var roles_1 = roles_0.Add(roleName); var command = new UpdateRole { Name = null, Permissions = new[] { "P1" } }; ValidationAssert.Throws(() => GuardAppRoles.CanUpdate(roles_1, command), new ValidationError("Name is required.", "Name")); }
public void CanUpdate_should_throw_exception_if_permission_is_null() { var roles_1 = roles_0.Add(roleName); var command = new UpdateRole { Name = roleName, Permissions = null }; ValidationAssert.Throws(() => GuardAppRoles.CanUpdate(roles_1, command), new ValidationError("Permissions is required.", "Permissions")); }
public void CanUpdate_should_throw_exception_if_default_role() { var roles_1 = roles_0.Add(Role.Developer); var command = new UpdateRole { Name = Role.Developer, Permissions = new[] { "P1" } }; ValidationAssert.Throws(() => GuardAppRoles.CanUpdate(roles_1, command), new ValidationError("Cannot update a default role.")); }
public async Task TestEmailInvalid() { Dictionary <string, StringValues> parameters = new Dictionary <string, StringValues>() { { "email", "invalidEmail@@@.com" } }; var request = CreateHttpRequest(parameters); var response = (JsonResult)await UpdateRole.Run(request, logger); Assert.Equal(400, response.StatusCode); }
public async Task <bool> CreatRole(UpdateRole request) { var json = JsonConvert.SerializeObject(request); var jsonstring = new StringContent(json, Encoding.UTF8, "application/json"); var creat = _httpClientFactory.CreateClient(); creat.BaseAddress = new Uri("https://localhost:44318"); var post = await creat.PostAsync("api/Role/CreatRole", jsonstring); return(post.IsSuccessStatusCode); }
public async Task TestTokenInvalid() { Dictionary <string, StringValues> parameters = new Dictionary <string, StringValues>() { { "email", "*****@*****.**" }, { "refresh_token", "123" } }; var request = CreateHttpRequest(parameters); var response = (JsonResult)await UpdateRole.Run(request, logger); Assert.Equal(400, response.StatusCode); }
public UpdateRole ToModel(SqlDataReader reader) { UpdateRole updateRole = new UpdateRole(); updateRole.ID = (int)ToModelValue(reader, "ID"); updateRole.OldVersion = (string)ToModelValue(reader, "OldVersion"); updateRole.NewVersion = (string)ToModelValue(reader, "NewVersion"); updateRole.CreateDate = (DateTime?)ToModelValue(reader, "CreateDate"); updateRole.UpdateType = (int?)ToModelValue(reader, "UpdateType"); updateRole.UpdateFileID = (int?)ToModelValue(reader, "UpdateFileID"); updateRole.Description = (string)ToModelValue(reader, "Description"); updateRole.CreateUserID = (int?)ToModelValue(reader, "CreateUserID"); return(updateRole); }
public async Task <object> Put(UpdateRole request) { var response = new BaseResponse(); Expression <Func <Role, bool> > keySelector = x => x.SystemName == request.SystemName; var entity = await _roleService.GetById(keySelector : keySelector); request.ToEntity(entity); var result = await _roleService.Update(entity); response.Success = true; response.Message = "Update role success"; response.StatusCode = (int)HttpStatusCode.OK; response.Results = result.ConvertTo <RoleDto>(); return(response); }
public async Task SetRole(UpdateRole r) { Account a = _unitOfWork.Account.GetByEmail(r.Email); if (!r.State) { a.Roles.Remove(a.Roles.Find(ro => ro.Name == r.Role)); } else if (a.Roles.Find(ro => ro.Name == r.Email) == null) { a.Roles.Add(_unitOfWork.Role.GetByName(r.Role)); } _unitOfWork.SaveChanges(); }
// PUT: api/AppSystem/5 public async Task <HandleResult> Put(string id, [FromBody] UpdateRole dto) { var command = new UpdateRole( id, dto.Name, dto.RoleType, dto.IsEnabled, dto.ReMark); var result = await ExecuteCommandAsync(command); if (result.IsSuccess()) { return(HandleResult.FromSuccess("更新成功")); } return(HandleResult.FromFail(result.GetErrorMessage())); }
public async Task <IHttpActionResult> UpdateRole(UpdateRole role) { var user = await UserManager.FindByNameAsync(role.EmployeeId); //UserManager.FindById(role.EmployeeId); var oldRoleName = UserManager.GetRoles(user.Id).FirstOrDefault(); if (oldRoleName.Equals(role.Role)) { return(BadRequest("The Role is already assign to this employee")); } UserManager.RemoveFromRole(user.Id, oldRoleName); UserManager.AddToRole(user.Id, role.Role); return(Ok()); }
public async Task TestSuccess() { Dictionary <string, StringValues> parameters = new Dictionary <string, StringValues>() { { "email", "*****@*****.**" }, { "refresh_token", TestConfig.AdminToken }, // token of admin { "role", "subscriber" } }; var request = CreateHttpRequest(parameters); var response = (JsonResult)await UpdateRole.Run(request, logger); Assert.Equal(200, response.StatusCode); var isSuccess = response.Value.GetType().GetProperty("success")?.GetValue(response.Value, null) as bool?; Assert.True(isSuccess); }
public void UpdateRole(UpdateRole model) { var result = _authQueries.GetValidationResult(model); if (result.IsValid == false) { throw new ApplicationException(result.Errors.First().ErrorMessage); } var role = _repository .Roles .Include(r => r.Permissions) .Single(r => r.Id == model.RoleId); role.Permissions.Clear(); role.Permissions = _repository.Permissions.Where(p => model.Permissions.Contains(p.Id)).ToList(); _repository.SaveChanges(); }
public void Invalid_roleId_is_not_valid_for_role_editing() { _authCommands.CreatePermission(new CreatePermission { Name = "Test", Module = "Test" }); var model = new UpdateRole { RoleId = Guid.NewGuid(), Permissions = _authQueries.GetPermissions().Select(p => p.Id).ToList() }; var result = _authQueries.GetValidationResult(model); result.IsValid.Should().BeFalse(); result.Errors.Single().ErrorMessage.Should().Be(ErrorsCodes.RoleNotFound.ToString()); }
public UpdateRole Add (UpdateRole updateRole) { string sql = "INSERT INTO UpdateRoles (ID, OldVersion, NewVersion, CreateDate, UpdateType, UpdateFileID, Description, CreateUserID) VALUES (@ID, @OldVersion, @NewVersion, @CreateDate, @UpdateType, @UpdateFileID, @Description, @CreateUserID)"; SqlParameter[] para = new SqlParameter[] { new SqlParameter("@ID", ToDBValue(updateRole.ID)), new SqlParameter("@OldVersion", ToDBValue(updateRole.OldVersion)), new SqlParameter("@NewVersion", ToDBValue(updateRole.NewVersion)), new SqlParameter("@CreateDate", ToDBValue(updateRole.CreateDate)), new SqlParameter("@UpdateType", ToDBValue(updateRole.UpdateType)), new SqlParameter("@UpdateFileID", ToDBValue(updateRole.UpdateFileID)), new SqlParameter("@Description", ToDBValue(updateRole.Description)), new SqlParameter("@CreateUserID", ToDBValue(updateRole.CreateUserID)), }; SqlHelper.ExecuteNonQuery(sql, para); return(updateRole); }
public async Task UpdateRole_should_create_events_and_update_state() { var command = new UpdateRole { Name = roleName, Permissions = new[] { "clients.read" } }; await ExecuteCreateAsync(); await ExecuteAddRoleAsync(); var result = await sut.ExecuteAsync(CreateCommand(command)); result.ShouldBeEquivalent(sut.Snapshot); LastEvents .ShouldHaveSameEvents( CreateEvent(new AppRoleUpdated { Name = roleName, Permissions = new[] { "clients.read" } }) ); }
public async Task UpdateRole_should_create_events_and_update_role() { var command = new UpdateRole { Name = roleName, Permissions = new[] { "clients.read" }, Properties = JsonValue.Object() }; await ExecuteCreateAsync(); await ExecuteAddRoleAsync(); var result = await PublishIdempotentAsync(command); result.ShouldBeEquivalent(sut.Snapshot); LastEvents .ShouldHaveSameEvents( CreateEvent(new AppRoleUpdated { Name = roleName, Permissions = command.Permissions, Properties = command.Properties }) ); }
protected void btnSubmit_Click(object sender, EventArgs e) { //将升级规则信息保存到数据库中 AdminUser user = Session["users"] as AdminUser; if (user != null) { UpdateRole updateRole = new UpdateRole(); updateRole.CreateDate = DateTime.Now; updateRole.CreateUserID = Convert.ToInt32(user.UserID); updateRole.Description = textDescription.Text; updateRole.OldVersion = textAllowVersion.Text; updateRole.NewVersion = textNewToVersion.Text; updateRole.UpdateFileID = 0; //在上传更新文件的时候需要将文件的相关信息存储到数据库中 updateRole.UpdateType = 0; // } else { JqHelper.ResponseScript("alert(\"登录超时,请重新登陆!\");window.close();");//未获取到用户信息,则关闭当前的窗口 } }
public async Task <IActionResult> UpdateRole([FromRoute] int id, [FromBody] UpdateRole roles) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != roles.EmployeeId) { return(BadRequest()); } try { _employee.UpdateRoleOfEmployee(roles); } catch (Exception ex) { throw ex; } return(Ok()); }
public static void CanUpdate(Roles roles, UpdateRole command) { Guard.NotNull(command, nameof(command)); GetRoleOrThrow(roles, command.Name); Validate.It(() => "Cannot delete role.", e => { if (string.IsNullOrWhiteSpace(command.Name)) { e(Not.Defined("Name"), nameof(command.Name)); } else if (Role.IsDefaultRole(command.Name)) { e("Cannot update a default role."); } if (command.Permissions == null) { e(Not.Defined("Permissions"), nameof(command.Permissions)); } }); }
public async Task <IActionResult> CreatRole(UpdateRole request) { var creat = await _roleConnectAPI.CreatRole(request); var annount = new AnnouncementViewModel() { UserName = User.Identity.Name, Content = "Creat Role", DateCreated = DateTime.Now, DeCripstion = "Successfull" }; var ann = _mapper.Map <AnnouncementViewModel, Announcement>(annount); _context.Announcements.Add(ann); await _context.SaveChangesAsync(); await _hubContext.Clients.All.SendAsync("ReceiveMessage", annount); return(Json(new { status = true, })); }