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()); }
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" })); } }
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" })); } }
public async Task <IActionResult> GetAll() { return(new JsonResult(new APIResult <List <ListRolePermissionDTO> > { Data = await RoleSvc.GetAllAsync() }) { }); }
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()); }
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()); }
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 } })); }
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" })); }
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); }
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)); }
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()); }
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 })); }
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()); }
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) })); }
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)); }
/// <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 }
public RoleController() { _svc = new RoleSvc(); }
public RoleServiceTests() { _fixture = new MockRepositorySpecification(); _roleSvc = new RoleSvc(() => _fixture.GetListener(nameof(RoleServiceTests)), _fixture.Repository, _fixture.Dispatcher); }
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 }
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 }
public async Task <IActionResult> Delete(long id) { await RoleSvc.MarkDeleteAsync(id); return(Ok()); }