public async Task UpdateRole_StateUnderTest_ExpectedBehavior_Remove() { // Arrange var unitUnderTest = this.CreateUsersController(); RoleForm role = new RoleForm() { Email = "sample", Add = false }; User userobj = new User() { Email = "sample", FirstName = "SampleName", Id = new Guid() }; // setup all needed values this.mockUserBusiness.Setup(r => r.GetUserByEmailAsync(role.Email)).ReturnsAsync(userobj); (bool Succeeded, string ErrorMessage)retVal = (false, ""); this.mockUserBusiness.Setup(r => r.RemoveFromRoleAsync(userobj.Id, "Pmo")).ReturnsAsync(retVal); // Act var result = await unitUnderTest.UpdateRole(role); // Assert Assert.IsType <NoContentResult>(result); }
public List <RoleForm> GetListRolform(int roleId) { var rs = new List <RoleForm>(); string sql = string.Format("select * from RoleForm where RoleId = {0}", roleId); var dt = db.GetDataTable(sql); foreach (DataRow row in dt.Rows) { RoleForm Roleform = new RoleForm() { Id = int.Parse(row["Id"].ToString()), RoleId = int.Parse(row["RoleId"].ToString()), FormId = int.Parse(row["FormId"].ToString()), TruyCap = bool.Parse(row["TruyCap"].ToString()), Them = bool.Parse(row["Them"].ToString()), Sua = bool.Parse(row["Sua"].ToString()), Xoa = bool.Parse(row["Xoa"].ToString()), In_DL = bool.Parse(row["In_DL"].ToString()), Nhap = bool.Parse(row["Nhap"].ToString()), Xuat = bool.Parse(row["Xuat"].ToString()) }; rs.Add(Roleform); } return(rs); }
public List <RoleForm> GetList(int MAVT) { var rs = new List <RoleForm>(); SqlParameter[] p = { new SqlParameter("@MAVT", SqlDbType.NVarChar, 50), }; p[0].Value = MAVT; var tb = ExecuteQuery("LayBangPhanQuyen", p); foreach (DataRow row in tb.Rows) { var RoleForm = new RoleForm() { DienGiaiVT = row["DienGiaiVT"].ToString(), MaBPQ = int.Parse(row["MaBPQ"].ToString()), MAVT = int.Parse(row["MAVT"].ToString()), MaForm = int.Parse(row["MaForm"].ToString()), TruyCap = bool.Parse(row["TruyCap"].ToString()), Them = bool.Parse(row["Them"].ToString()), Xoa = bool.Parse(row["Xoa"].ToString()), Sua = bool.Parse(row["Sua"].ToString()), Inn = bool.Parse(row["Inn"].ToString()), Nhap = bool.Parse(row["Nhap"].ToString()), Xuat = bool.Parse(row["Xuat"].ToString()), }; rs.Add(RoleForm); } return(rs); }
public List <RoleForm> GetRolesForm(string roleId, string userId) { List <RoleForm> rolesform = new List <RoleForm>(); RoleForm roleform; SqlDataReader roles = SqlHelper.ExecuteReader(MySettings.ConnEAMAdmin , "dbo.admin_GetUserRoles" , roleId , userId); if (roles.HasRows) { while (roles.Read()) { roleform = new RoleForm(); roleform.userId = roles["userid"].ToString(); roleform.roleId = roles["roleid"].ToString(); roleform.Active = true; roleform.Nombre = roles["rolenombre"].ToString(); roleform.Group = roles["grupo"].ToString(); rolesform.Add(roleform); } } roles.Close(); return(rolesform); }
public async Task <IActionResult> UpdateRole([FromBody] RoleForm role) { var user = await _user.GetUserByEmailAsync(role.Email); if (user == null) { return(NotFound()); } try { if (role.Add) { await _user.AddToRoleAsync(user.Id, "Pmo"); } else { await _user.RemoveFromRoleAsync(user.Id, "Pmo"); } } catch (DbUpdateConcurrencyException) { //if (!await UserExists(user.Id)) //{ // return NotFound(); //} //else //{ // throw; //} throw; } return(NoContent()); }
public List <RoleForm> GetList(int roleId) { var rs = new List <RoleForm>(); string sql = string.Format("select * from [RoleForm] where RoleId = '{0}'", roleId); var tb = db.GetData(sql); if (tb != null && tb.Rows.Count > 0) { foreach (DataRow row in tb.Rows) { var roleForm = new RoleForm() { Id = int.Parse(row["Id"].ToString()), RoleId = int.Parse(row["RoleId"].ToString()), FormId = int.Parse(row["FormId"].ToString()), Access = bool.Parse(row["Access"].ToString()), Insert = bool.Parse(row["Insert"].ToString()), Delete = bool.Parse(row["Delete"].ToString()), Update = bool.Parse(row["Update"].ToString()), Print = bool.Parse(row["Print"].ToString()), Import = bool.Parse(row["Import"].ToString()), Export = bool.Parse(row["Export"].ToString()) }; rs.Add(roleForm); } } return(rs); }
public void EnnableFunction(RoleForm roleForm) { btnthem.Enabled = roleForm.Insert; btnsua.Enabled = roleForm.Update; btnxoa.Enabled = roleForm.Delete; btnnhap.Enabled = roleForm.Import; btnxuat.Enabled = roleForm.Export; }
private void barButtonRoles_ItemClick(object sender, ItemClickEventArgs e) { RoleForm xform1 = new RoleForm(_FlexSys) { MdiParent = this }; xform1.Show(); }
public void EnnableFunction(RoleForm roleForm) { ucbtnthem.Enabled = roleForm.Them; ucbtnsua.Enabled = roleForm.Sua; ucbtnxoa.Enabled = roleForm.Xoa; ucbtnin.Enabled = roleForm.In_DL; ucbtnnhap.Enabled = roleForm.Nhap; ucbtnxuat.Enabled = roleForm.Xuat; }
public void VisibleFunctions(RoleForm roleForm) { btnLoadData.Visible = roleForm.Access; btnInsert.Visible = roleForm.Insert; btnUpdate.Visible = roleForm.Update; btnDelete.Visible = roleForm.Delete; btnPrint.Visible = roleForm.Print; btnImport.Visible = roleForm.Import; btnExport.Visible = roleForm.Export; }
public void InBoundUrl_WithNonPutAndPostMethods_IsNotRouted() { var model = new RoleForm { EntityId = Guid.NewGuid() }; var url = new RolesRouter.PutRoute().Url.ToAppRelativeUrl() .Replace("{entityId}", model.EntityId.ToString()); url.WithMethodsExcept(HttpVerbs.Put, HttpVerbs.Post).ShouldMapToNothing(); }
public IActionResult Insert([FromBody, SwaggerRequestBody("Form to create a new role", Required = true)] RoleForm form) { try { int idCreated = _service.Create(form.ToServiceLayerRoleInsert()); return(Ok(idCreated)); } catch (ArgumentException e) { return(new BadRequestObjectResult(e.Message)); } }
public void OutBoundUrl_IsNotRouted() { var model = new RoleForm { EntityId = Guid.NewGuid() }; Expression <Func <RolesController, ActionResult> > action = controller => controller.Put(model); var url = new RolesRouter.PutRoute().Url.ToAppRelativeUrl() .Replace("{entityId}", model.EntityId.ToString()); OutBoundRoute.Of(action).InArea(Area).AppRelativeUrl().ShouldNotEqual(url); }
public void InBoundUrl_WithPutAndPostMethods_IsRouted() { var model = new RoleForm { EntityId = Guid.NewGuid() }; Expression <Func <RolesController, ActionResult> > action = controller => controller.Put(model); var url = new RolesRouter.PutRoute().Url.ToAppRelativeUrl() .Replace("{entityId}", model.EntityId.ToString()); url.WithMethod(HttpVerbs.Put).AndMethodArg("model", model).ShouldMapTo(action); url.WithMethod(HttpVerbs.Post).AndMethodArg("model", model).ShouldMapTo(action); }
public async Task <Role> CreateAsync(RoleForm form) { if (!(await _authorizationService.AuthorizeAsync(_user, null, new FullRightsRequirement())).Succeeded) { throw new ForbiddenException(); } var roleEntity = Mapper.Map <RoleEntity>(form); _context.Roles.Add(roleEntity); await _context.SaveChangesAsync(); return(Mapper.Map <Role>(roleEntity)); }
private void roleToolStripMenuItem_Click(object sender, EventArgs e) { if (MdiChildren.Length > 0) { return; } var role = new RoleForm { MdiParent = this }; role.Show(); }
/// <summary> /// Open the Role form for the record indicated in the parameter. /// </summary> /// <param name="Id">The id (primary key) of the record to open.</param> /// <remarks>Created: Theo Crous 24/07/2012</remarks> protected override void OnOpenRecord(long Id) { try { base.OnOpenRecord(Id); RoleForm childForm = new RoleForm(Id); ShowForm(childForm); } catch (Exception ex) { if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; } } }
public async Task <Role> UpdateAsync(Guid id, RoleForm form) { if (!(await _authorizationService.AuthorizeAsync(_user, null, new FullRightsRequirement())).Succeeded) { throw new ForbiddenException(); } var roleToUpdate = await _context.Roles.SingleOrDefaultAsync(v => v.Id == id); if (roleToUpdate == null) { throw new EntityNotFoundException <Role>(); } Mapper.Map(form, roleToUpdate); _context.Roles.Update(roleToUpdate); await _context.SaveChangesAsync(); return(await GetAsync(roleToUpdate.Id)); }
public async Task UpdateRole_StateUnderTest_ExpectedBehavior_NoUser() { // Arrange var unitUnderTest = this.CreateUsersController(); RoleForm input = new RoleForm() { Email = "Sample", Add = true }; // setup all needed values User outp = null; this.mockUserBusiness.Setup(r => r.GetUserByEmailAsync(input.Email)).ReturnsAsync(outp); // Act var result = await unitUnderTest.UpdateRole(input); // Assert Assert.IsType <NotFoundResult>(result); }
public virtual ActionResult Put(RoleForm model) { if (model != null) { if (ModelState.IsValid) { var command = new UpdateRoleCommand(User) { EntityId = model.EntityId, Description = model.Description, RevokedUserEntityIds = model.Grants.Where(g => g.IsDeleted).Select(g => g.User.EntityId), GrantedUserEntityIds = model.Grants.Where(g => !g.IsDeleted).Select(g => g.User.EntityId), }; _services.UpdateHandler.Handle(command); SetFeedbackMessage(command.ChangeCount > 0 ? "Role has been successfully saved." : "No changes were made."); return(Redirect(model.ReturnUrl)); } return(View(Views.form, model)); } return(HttpNotFound()); }
public async Task <Role> CreateAsync(RoleForm form) { if (!(await _authorizationService.AuthorizeAsync(_user, null, new FullRightsRequirement())).Succeeded) { throw new ForbiddenException(); } // Ensure role with this name does not already exist var role = await _context.Roles .ProjectTo <Role>(_mapper.ConfigurationProvider) .SingleOrDefaultAsync(o => o.Name == form.Name); if (role != null) { throw new ConflictException("A role with that name already exists."); } var roleEntity = _mapper.Map <RoleEntity>(form); _context.Roles.Add(roleEntity); await _context.SaveChangesAsync(); return(_mapper.Map <Role>(roleEntity)); }
private void Role_btn_Click(object sender, EventArgs e) { RoleForm roleFrm = new RoleForm(); roleFrm.ShowDialog(); }
public async Task <IActionResult> Update([FromRoute] Guid id, [FromBody] RoleForm form) { var updatedRole = await _RoleService.UpdateAsync(id, form); return(Ok(updatedRole)); }
public async Task <IActionResult> Create([FromBody] RoleForm form) { var createdRole = await _RoleService.CreateAsync(form); return(CreatedAtAction(nameof(this.Get), new { id = createdRole.Id }, createdRole)); }
public RoleController() { Form = new RoleForm(); SearchForms.Add(new RoleSearchForm(Url)); TitlePlural = "Roles"; }
private void Role_btn_Click(object sender, EventArgs e) { Com.Nidec.Mes.GlobalMasterMaintenance.RoleForm roleform = new RoleForm(); roleform.Show(); }