Пример #1
0
        public async Task <IActionResult> Post(UpdateRolePermissionModel model)
        {
            var role = await RoleSvc.GetByNameAsync(model.Name);

            if (role != null)
            {
                if (role.Id != model.Id)
                {
                    return(new JsonResult(new APIResult <int> {
                        ErrorMsg = "该角色已存在"
                    })
                    {
                        StatusCode = 400
                    });
                }
            }
            UpdateRolePermissionDTO dto = new UpdateRolePermissionDTO();

            dto.Description = model.Description;
            dto.Id          = model.Id;
            dto.Name        = model.Name;
            await RoleSvc.UpdateAsync(dto);

            return(Ok());
        }
Пример #2
0
        public async Task <IActionResult> Add(AddRoleModel model)
        {
            using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                AddRolePermissionModel addrole = new AddRolePermissionModel();
                addrole.Description = model.Description;
                addrole.Name        = model.Name;
                long roleId = await RoleSvc.AddNewAsync(addrole);

                if (roleId < 1)
                {
                    return(Json(new AjaxResult {
                        Status = "error", ErrorMsg = RoleSvc.ErrorMsg
                    }));
                }
                UpdateRoleOrPermissionModel update = new UpdateRoleOrPermissionModel();
                update.Id  = roleId;
                update.Ids = model.Ids;
                if (!await PerSvc.UpdateRoleToPermissesAsync(update))
                {
                    return(Json(new AjaxResult {
                        Status = "error", ErrorMsg = RoleSvc.ErrorMsg
                    }));
                }
                scope.Complete();
                return(Json(new AjaxResult {
                    Status = "ok"
                }));
            }
        }
Пример #3
0
 public async Task <IActionResult> Edit(UpdateRoleModel model)
 {
     using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
     {
         UpdateRolePermissionModel editrole = new UpdateRolePermissionModel();
         editrole.Description = model.Description;
         editrole.Name        = model.Name;
         editrole.Id          = model.Id;
         if (!await RoleSvc.UpdateAsync(editrole))
         {
             return(Json(new AjaxResult {
                 Status = "error", ErrorMsg = RoleSvc.ErrorMsg
             }));
         }
         UpdateRoleOrPermissionModel update = new UpdateRoleOrPermissionModel();
         update.Id  = editrole.Id;
         update.Ids = model.Ids;
         if (!await PerSvc.UpdateRoleToPermissesAsync(update))
         {
             return(Json(new AjaxResult {
                 Status = "error", ErrorMsg = RoleSvc.ErrorMsg
             }));
         }
         scope.Complete();
         return(Json(new AjaxResult {
             Status = "ok"
         }));
     }
 }
Пример #4
0
 public async Task <IActionResult> GetAll()
 {
     return(new JsonResult(new APIResult <List <ListRolePermissionDTO> > {
         Data = await RoleSvc.GetAllAsync()
     })
     {
     });
 }
Пример #5
0
        public async Task GetPageDataTest()
        {
            var mockSet     = new Mock <DbSet <Role> >().SetupList(_sampleList);
            var mockContext = new Mock <LiveShowDBContext>();

            mockContext.Setup(x => x.Role).Returns(mockSet.Object);
            var mockSvc = new RoleSvc(mockContext.Object);
            var result  = await mockSvc.GetPageDataAsync(new RoleQueryModel());

            Assert.Equal(_sampleList.Count(), result.List.Count());
        }
Пример #6
0
        public async Task <IActionResult> UpdateAdminUserRoles(UpdateRoleOrPermissionModel model)
        {
            //string token = JWTHelper.GetToken(HttpContext, "token");
            //if (!JWTHelper.Decrypt(token, out ListAdminUserDTO adminUser))
            //{
            //    return new JsonResult(new APIResult<long> { ErrorMsg = "请先登录!" }) { StatusCode = 401 };
            //}
            await RoleSvc.UpdateAdminUserToRolesAsync(model.Id, model.Ids);

            return(Ok());
        }
Пример #7
0
        public async Task <IActionResult> GetPageData(int pageIndex = 1, int pageDataCount = 10)
        {
            var roles = await RoleSvc.GetPageDataAsync(pageIndex, pageDataCount);

            var totalCount = await RoleSvc.TotalCountAsync();

            return(new JsonResult(new APIResult <ListModel <ListRolePermissionDTO> > {
                Data = new ListModel <ListRolePermissionDTO> {
                    Datas = roles, TotalCount = totalCount
                }
            }));
        }
Пример #8
0
 public async Task <IActionResult> Delete(long id)
 {
     if (!await RoleSvc.DeleteAsync(id))
     {
         return(Json(new AjaxResult {
             Status = "error", ErrorMsg = RoleSvc.ErrorMsg
         }));
     }
     return(Json(new AjaxResult {
         Status = "ok"
     }));
 }
Пример #9
0
        public async Task GetSingleDataTest()
        {
            Mapper.Initialize(x => x.AddProfile <CustomizeProfile>());
            var mockSet     = new Mock <DbSet <Role> >().SetupList(_sampleList);
            var mockContext = new Mock <LiveShowDBContext>();

            mockContext.Setup(x => x.Role).Returns(mockSet.Object);
            var mockSvc = new RoleSvc(mockContext.Object);
            var result  = await mockSvc.GetSingleDataAsync(1);

            Assert.Equal(1, result.Data.Id);
        }
Пример #10
0
        public async Task <IActionResult> List(int pageIndex = 1, int pageDataCount = 10)
        {
            var model = await RoleSvc.GetPageDataAsync(pageIndex, pageDataCount);

            if (model == null)
            {
                return(Content(RoleSvc.ErrorMsg));
            }
            NoRainPage page = new NoRainPage();

            page.DataCount   = model.TotalCount;
            page.PageIndex   = pageIndex;
            page.Url         = "/role/List?pageIndex=@parms";
            ViewData["Page"] = page.GetPaging();
            return(View(model));
        }
Пример #11
0
        public async Task EditTest()
        {
            var mockSet     = new Mock <DbSet <Role> >().SetupList(_sampleList);
            var mockContext = new Mock <LiveShowDBContext>();

            mockContext.Setup(x => x.Role).Returns(mockSet.Object);
            var mockSvc = new RoleSvc(mockContext.Object);
            var dto     = new RoleDto()
            {
                Id = 1, Name = "Test1.5", CreateTime = DateTime.Now, IsDeleted = false, Status = 1
            };
            await mockSvc.Edit(dto);

            mockSet.Verify(x => x.Update(It.IsAny <Role>()), Times.Once());
            mockContext.Verify(x => x.SaveChanges(), Times.Once());
        }
Пример #12
0
        public async Task <IActionResult> GetByAdminUserId(long adminUserId)
        {
            var model = await RoleSvc.GetByAdminUserIdAsync(adminUserId);

            if (model == null)
            {
                return(new JsonResult(new APIResult <long> {
                    ErrorMsg = "id不存在"
                })
                {
                    StatusCode = 400
                });
            }
            return(new JsonResult(new APIResult <List <ListRolePermissionDTO> > {
                Data = model
            }));
        }
Пример #13
0
        public void AddTest()
        {
            Mapper.Initialize(x => x.AddProfile <CustomizeProfile>());
            var mockSet     = new Mock <DbSet <Role> >();
            var mockContext = new Mock <LiveShowDBContext>();

            mockContext.Setup(x => x.Role).Returns(mockSet.Object);
            var mockSvc = new RoleSvc(mockContext.Object);

            var dto = new RoleDto()
            {
                Name = "Test", IsDeleted = false, CreateTime = DateTime.Now, Status = 1
            };

            mockSvc.Add(dto);

            mockContext.Verify(x => x.Add(It.IsAny <Role>()), Times.Once());
            mockContext.Verify(x => x.SaveChanges(), Times.Once());
        }
Пример #14
0
        public async Task <IActionResult> Put(AddRolePermissionModel model)
        {
            if (await RoleSvc.GetByNameAsync(model.Name) != null)
            {
                return(new JsonResult(new APIResult <int> {
                    ErrorMsg = "该权限已存在"
                })
                {
                    StatusCode = 400
                });
            }
            AddRolePermissionDTO dto = new AddRolePermissionDTO();

            dto.Name        = model.Name;
            dto.Description = model.Description;
            return(new JsonResult(new APIResult <long> {
                Data = await RoleSvc.AddNewAsync(dto)
            }));
        }
Пример #15
0
        public async Task <IActionResult> Edit(long id)
        {
            var role = await RoleSvc.GetByIdAsync(id);

            if (role == null)
            {
                return(NotFound());
            }
            var rolePers = await PerSvc.GetByRoleIdAsync(role.Id);

            var pers = await PerSvc.GetAllAsync <List <ListRolePermissionDTO> >();

            RoleListModel model = new RoleListModel();

            model.Role     = role;
            model.RolePers = rolePers;
            model.Pers     = pers;
            return(View(model));
        }
Пример #16
0
        /// <summary>
        /// Displays the edit view of the project with a specified id.
        /// </summary>
        /// <param name="id">The id of the project.</param>
        public void ConfirmDelete(int roleId)
        {
            #region Logging
            if (log.IsDebugEnabled) log.Debug(Messages.MethodEnter);
            #endregion

            Role role = new RoleSvc().Get(roleId);
            Application application = new ApplicationSvc().Get(role.Application.Id);

            this.PropertyBag["role"] = role;

            this.AddToBreadcrumbTrail(new Link() { Text = "Home", Controller = "home", Action = "default" });
            this.AddToBreadcrumbTrail(new Link() { Text = application.Name, Controller = "application", Action = "display", QueryString = string.Format("applicationId={0}", application.Id) });
            this.AddToBreadcrumbTrail(new Link() { Text = "Roles", Controller = "role", Action = "default", QueryString = string.Format("applicationId={0}", application.Id) });
            this.AddToBreadcrumbTrail(new Link() { Text = role.Name, Controller = "role", Action = "display", QueryString = string.Format("roleId={0}", roleId) });
            this.AddToBreadcrumbTrail(new Link() { Text = "Delete" });
            this.RenderBreadcrumbTrail();

            this.RenderView("delete");

            #region Logging
            if (log.IsDebugEnabled) log.Debug(Messages.MethodLeave);
            #endregion
        }
Пример #17
0
 public RoleController()
 {
     _svc = new RoleSvc();
 }
Пример #18
0
        public RoleServiceTests()
        {
            _fixture = new MockRepositorySpecification();

            _roleSvc = new RoleSvc(() => _fixture.GetListener(nameof(RoleServiceTests)), _fixture.Repository, _fixture.Dispatcher);
        }
Пример #19
0
        public void Delete(int roleId)
        {
            #region Logging
            if (log.IsDebugEnabled) log.Debug(Messages.MethodEnter);
            #endregion

            RoleSvc roleSvc = new RoleSvc();

            Role role = roleSvc.Get(roleId);

            roleSvc.Delete(role);

            Hashtable args = new Hashtable();
            args["applicationId"] = role.Application.Id;
            this.RedirectToAction("default", args);

            #region Logging
            if (log.IsDebugEnabled) log.Debug(Messages.MethodLeave);
            #endregion
        }
Пример #20
0
        public void Edit(int roleId)
        {
            #region Logging
            if (log.IsDebugEnabled) log.Debug(Messages.MethodEnter);
            #endregion

            RoleSvc roleSvc = new RoleSvc();
            Role role = roleSvc.Get(roleId);
            Application application = new ApplicationSvc().Get(role.Application.Id);
            IList<SecurableObjectType> securableObjectTypes = new SecurableObjectTypeSvc().Get(application);
            SecurableObjectType securableObjectType = new SecurableObjectTypeSvc().Get(role.Application, role.SecurableObjectType.Id);
            RightCollection rights =
            new RightSvc().Get(securableObjectType);

            RoleRightAssignmentCollection roleRightAssignments =
                new RoleRightAssignmentSvc().Get(role);

            IList<GrantedRight> grantedRights = new List<GrantedRight>();

            foreach (Right right in rights)
            {
                GrantedRight grantedRight = new GrantedRight()
                {
                    Id = right.Id,
                    Name = right.Name,
                    Description = right.Description,
                    Application = right.Application,
                    SecurableObjectType = right.SecurableObjectType
                };

                foreach (RoleRightAssignment rra in roleRightAssignments)
                {
                    if (rra.Right.Id == right.Id)
                    {
                        grantedRight.IsGranted = true;
                        break;
                    }
                }

                grantedRights.Add(grantedRight);
            }

            this.PropertyBag["rights"] = grantedRights;
            this.PropertyBag["role"] = role;
            this.PropertyBag["securableObjectTypes"] = securableObjectTypes;

            this.AddToBreadcrumbTrail(new Link() { Text = "Home", Controller = "home", Action = "default" });
            this.AddToBreadcrumbTrail(new Link() { Text = application.Name, Controller = "application", Action = "display", QueryString = string.Format("applicationId={0}", application.Id) });
            this.AddToBreadcrumbTrail(new Link() { Text = "Roles", Controller = "role", Action = "default", QueryString = string.Format("applicationId={0}", application.Id) });
            this.AddToBreadcrumbTrail(new Link() { Text = role.Name, Controller = "role", Action = "display", QueryString = string.Format("roleId={0}", roleId) });
            this.AddToBreadcrumbTrail(new Link() { Text = "Edit" });
            this.RenderBreadcrumbTrail();

            #region Logging
            if (log.IsDebugEnabled) log.Debug(Messages.MethodLeave);
            #endregion
        }
Пример #21
0
        public async Task <IActionResult> Delete(long id)
        {
            await RoleSvc.MarkDeleteAsync(id);

            return(Ok());
        }