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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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());
        }
Пример #6
0
        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);
        }
Пример #7
0
 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;
 }
Пример #8
0
        private void barButtonRoles_ItemClick(object sender, ItemClickEventArgs e)
        {
            RoleForm xform1 = new RoleForm(_FlexSys)
            {
                MdiParent = this
            };

            xform1.Show();
        }
Пример #9
0
 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;
 }
Пример #11
0
            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));
     }
 }
Пример #13
0
            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);
            }
Пример #14
0
            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);
            }
Пример #15
0
        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));
        }
Пример #16
0
        private void roleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MdiChildren.Length > 0)
            {
                return;
            }

            var role = new RoleForm
            {
                MdiParent = this
            };

            role.Show();
        }
Пример #17
0
        /// <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;
                }
            }
        }
Пример #18
0
        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);
        }
Пример #20
0
 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());
 }
Пример #21
0
        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));
        }
Пример #22
0
        private void Role_btn_Click(object sender, EventArgs e)
        {
            RoleForm roleFrm = new RoleForm();

            roleFrm.ShowDialog();
        }
Пример #23
0
        public async Task <IActionResult> Update([FromRoute] Guid id, [FromBody] RoleForm form)
        {
            var updatedRole = await _RoleService.UpdateAsync(id, form);

            return(Ok(updatedRole));
        }
Пример #24
0
        public async Task <IActionResult> Create([FromBody] RoleForm form)
        {
            var createdRole = await _RoleService.CreateAsync(form);

            return(CreatedAtAction(nameof(this.Get), new { id = createdRole.Id }, createdRole));
        }
Пример #25
0
 public RoleController()
 {
     Form = new RoleForm();
     SearchForms.Add(new RoleSearchForm(Url));
     TitlePlural = "Roles";
 }
Пример #26
0
 private void Role_btn_Click(object sender, EventArgs e)
 {
     Com.Nidec.Mes.GlobalMasterMaintenance.RoleForm roleform = new RoleForm();
     roleform.Show();
 }