public async Task <Result <int> > CreateUserAsync([Required][FromBody] AdminUserCreateCommand request, CancellationToken cancellationToken = default) { var entity = mapper.Map <AdminUserCreateCommand, AdminUserEntity>(request); //角色操作 if (request.Roles != null && request.Roles.Length > 0) { //转换角色对象 并写入 entity.UserRoles = Array.ConvertAll(request.Roles, roleid => new AdminUserRoleEntity { RoleId = roleid, AdminId = entity.Id }); } var res = await db.AddAsync(entity, cancellationToken : cancellationToken); if (res > 0) { await mediator.Publish(new AdminUserCreateEvent(entity.Id, entity), cancellationToken); return(RestFull.Success(data: res)); } else { return(RestFull.Fail(data: res)); } }
public async Task <Result <AdminUserDto> > GetUserByAccountAsync([Required] AccountMode accountMode, [Required] string account, CancellationToken cancellationToken = default) { switch (accountMode) { case AccountMode.UserName: var res = await db.Context.AdminUser .Where(c => c.UserName.Equals(account)) .ProjectTo <AdminUserDto>(mapper.ConfigurationProvider) .FirstOrDefaultAsync(cancellationToken); return(RestFull.Success(data: res)); case AccountMode.Mobile: res = await db.Context.AdminUser .Where(c => c.Mobile.Equals(account)) .ProjectTo <AdminUserDto>(mapper.ConfigurationProvider) .FirstOrDefaultAsync(cancellationToken); return(RestFull.Success(data: res)); } return(RestFull.Fail(data: default(AdminUserDto))); }
public async Task <Result <int> > CreateRoleAsync([Required][FromBody] AdminRoleCreateCommand request, CancellationToken cancellationToken = default) { var entity = mapper.Map <AdminRoleCreateCommand, AdminRoleEntity>(request); //保存关联导航 if (request.MenuIds != null && request.MenuIds.Length > 0) { entity.RoleMenus = Array.ConvertAll(request.MenuIds, key => new AdminRoleMenuEntity { RoleId = entity.Id, MenuId = key }); } var res = await db.AddAsync(entity, cancellationToken : cancellationToken); if (res > 0) { return(RestFull.Success(data: res)); } else { return(RestFull.Fail(data: res)); } }
public async Task <Result <int> > UpdateRoleFieldAsync([Required] long id, [Required] string field, string value, CancellationToken cancellationToken = default) { var res = 0; switch (field.ToLower()) { case "name": res = await db.UpdateAsync <AdminRoleEntity>(c => c.Id == id, c => new AdminRoleEntity() { Name = value, Updated_At = DateTime.Now }, cancellationToken); break; default: res = 0; break; } if (res > 0) { return(RestFull.Success(data: res)); } else { return(RestFull.Fail(data: res)); } }
public async Task <Result <int> > UpdateRoleAsync([Required][FromBody] AdminRoleUpdateCommand request, CancellationToken cancellationToken = default) { var entity = await db.Context.AdminAuthRole.FirstOrDefaultAsync(c => c.Id == request.Id, cancellationToken); if (entity == null) { return(RestFull.Fail(data: 0)); } entity = mapper.Map(request, entity); //先清空导航集合,确保没有冗余信息 await db.DeleteAsync <AdminRoleMenuEntity>(c => c.RoleId == entity.Id); //保存关联导航 if (request.MenuIds != null && request.MenuIds.Length > 0) { entity.RoleMenus = Array.ConvertAll(request.MenuIds, key => new AdminRoleMenuEntity { RoleId = entity.Id, MenuId = key }); } var res = db.Update(entity); if (res > 0) { return(RestFull.Success(data: res)); } else { return(RestFull.Fail(data: res)); } }
public async Task <Result <int> > UpdateUserAsync([Required][FromBody] AdminUserUpdatePasswordCommand request, CancellationToken cancellationToken = default) { var admin = await db.Context.AdminUser.FindAsync(request.Id); request.NewPassword = Encrypt.Md5By32(request.NewPassword); request.OldPassword = Encrypt.Md5By32(request.OldPassword); if (!admin.Password.Equals(request.OldPassword)) { Failure.Error("旧密码错误"); } var res = await db.UpdateAsync <AdminUserEntity>(c => c.Id == request.Id, c => new AdminUserEntity { Password = request.NewPassword }, cancellationToken); if (res > 0) { return(RestFull.Success(data: res)); } else { return(RestFull.Fail(data: res)); } }
public async Task <Result <string> > VerifyTokenAsync(CancellationToken cancellationToken) { return(RestFull.Success(data: new { authService.AdminId, authService.AdminName }.ToJson())); }
public async Task <Result <IList <long> > > GetUserRelevanceRoleAsync([Required] long adminId, CancellationToken cancellationToken = default) { var res = await db.Context.AdminAuthUserRole .Where(c => c.AdminId == adminId) .Select(c => c.RoleId) .ToListAsync(cancellationToken); return(RestFull.Success(data: res.As <IList <long> >())); }
public async Task <Result <LoginTokenDto> > LoginAsync([Required][FromBody] AdminUserLoginCommand request, CancellationToken cancellationToken) { (var accessToken, var refreshToken) = await authService.LoginAsync(request, cancellationToken); return(RestFull.Success(data: new LoginTokenDto { Token = accessToken })); }
public async Task <Result <IList <AdminRoleDto> > > GetRoleAllAsync(CancellationToken cancellationToken = default) { var res = await db.Context.AdminAuthRole .Where(c => c.Status == Status.Show) .ProjectTo <AdminRoleDto>(mapper.ConfigurationProvider) .ToListAsync(cancellationToken); return(RestFull.Success(data: res.As <IList <AdminRoleDto> >())); }
public async Task <Result <AdminMenuDto> > GetMenuByIdAsync([Required] long id, CancellationToken cancellationToken = default) { var res = await db.Context.AdminAuthMenus .Where(c => c.Id == id) .ProjectTo <AdminMenuDto>(mapper.ConfigurationProvider) .FirstOrDefaultAsync(cancellationToken); return(RestFull.Success(data: res)); }
/// <summary> /// 管理员登录 /// </summary> /// <param name="command"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <Result <LoginTokenDto> > LoginAsync(AdminUserLoginCommand command, CancellationToken cancellationToken) { (var accessToken, var refreshToken) = await authService.LoginAsync(command, cancellationToken); return(RestFull.Success(data: new LoginTokenDto { Token = accessToken })); }
public async Task <Result <IList <AdminMenuDto> > > GetMenuListAsync([Required] bool isMenu = true, CancellationToken cancellationToken = default) { var res = await db.Context.AdminAuthMenus .Where(c => c.IsMenu == isMenu) .OrderByDescending(c => c.Weight) .ProjectTo <AdminMenuDto>(mapper.ConfigurationProvider) .ToListAsync(cancellationToken); return(RestFull.Success(data: res.As <IList <AdminMenuDto> >())); }
public async Task <Result <IList <AdminMenuTreeDto> > > GetMenuTreeAsync(CancellationToken cancellationToken = default) { var list = await db.Context.AdminAuthMenus .OrderByDescending(c => c.Weight) .ToListAsync(cancellationToken); var res = AuthMenuTree(list, 0); return(RestFull.Success(data: res)); }
public async Task <Result <IList <long> > > GetRoleRelevanceMenuAsync([Required] int roleId, CancellationToken cancellationToken = default) { var res = await db.Context.AdminAuthRoleMenus .Where(c => c.RoleId == roleId) .OrderBy(c => c.MenuId) .Select(c => c.MenuId) .ToListAsync(); return(RestFull.Success(data: res.As <IList <long> >())); }
public async Task <Result <int> > UpdateMenuFieldAsync([Required] long id, [Required] string field, string value, CancellationToken cancellationToken = default) { var res = 0; switch (field.ToLower()) { case "icon": res = await db.UpdateAsync <AdminMenuEntity>(c => c.Id == id, c => new AdminMenuEntity() { Icon = value, Updated_At = DateTime.Now }, cancellationToken); break; case "url": res = await db.UpdateAsync <AdminMenuEntity>(c => c.Id == id, c => new AdminMenuEntity() { Url = value, Updated_At = DateTime.Now }, cancellationToken); break; case "onlycode": res = await db.UpdateAsync <AdminMenuEntity>(c => c.Id == id, c => new AdminMenuEntity() { OnlyCode = value, Updated_At = DateTime.Now }, cancellationToken); break; case "weight": res = await db.UpdateAsync <AdminMenuEntity>(c => c.Id == id, c => new AdminMenuEntity() { Weight = value.ToInt(), Updated_At = DateTime.Now }, cancellationToken); break; default: res = 0; break; } if (res > 0) { return(RestFull.Success(data: res)); } else { return(RestFull.Fail(data: res)); } }
public async Task <Result <PagedModel <LoginRecordDto> > > GetRecordPageAsync([Required][FromQuery] LoginRecordQueryPagedCommand request, CancellationToken cancellationToken = default) { var res = await View.Create(db.Context) .WhereIf(c => c.Name.Contains(request.Search) || c.Mobile.Contains(request.Search) || c.UserName.Contains(request.Search), !string.IsNullOrEmpty(request.Search)) .OrderByBatch($"{request.Sort} {request.Order}", !request.Sort.IsEmpty() && !request.Order.IsEmpty()) .ProjectTo <LoginRecordDto>(mapper.ConfigurationProvider) .ToPagedListAsync(request.CurrentPage, request.PageSize, cancellationToken); return(RestFull.Success(data: res.ToModel())); }
public async Task <Result <int> > UpdateUserAsync([FromQuery] AdminUserUpdateFieldCommand command, CancellationToken cancellationToken = default) { var res = await bus.SendCommand(command, cancellationToken); if (res > 0) { return(RestFull.Success(data: res)); } else { return(RestFull.Fail(data: res)); } }
public async Task <Result <int> > CreateMenuAsync([FromBody] AdminMenuCreateCommand command, CancellationToken cancellationToken = default) { var res = await bus.SendCommand(command, cancellationToken); if (res > 0) { return(RestFull.Success(data: res)); } else { return(RestFull.Fail(data: res)); } }
/// <summary> /// 更新角色状态 /// </summary> /// <param name="ids"></param> /// <param name="status"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <Result <int> > UpdateRoleAsync(long[] ids, Status status, CancellationToken cancellationToken = default) { var res = await adminRoleService.UpdateAsync(ids, status, cancellationToken); if (res > 0) { return(RestFull.Success(data: res)); } else { return(RestFull.Fail(data: res)); } }
/// <summary> /// 账号关联角色 /// </summary> /// <param name="command"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <Result <int> > CreateUserRelevanceRoleIdAsync(AdminUserRelevanceRoleCommand command, CancellationToken cancellationToken = default) { var res = await adminUserService.RelevanceRoleAsync(command, cancellationToken); if (res > 0) { return(RestFull.Success(data: res)); } else { return(RestFull.Fail(data: res)); } }
/// <summary> /// 创建导航 /// </summary> /// <param name="command"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <Result <int> > CreateMenuAsync(AdminMenuCreateCommand command, CancellationToken cancellationToken = default) { var res = await adminMenuService.CreateAsync(command, cancellationToken); if (res > 0) { return(RestFull.Success(data: res)); } else { return(RestFull.Fail(data: res)); } }
/// <summary> /// 更新导航指定字段内容 /// </summary> /// <param name="id"></param> /// <param name="field"></param> /// <param name="value"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <Result <int> > UpdateMenuAsync(long id, string field, string value, CancellationToken cancellationToken = default) { var res = await adminMenuService.UpdateAsync(id, field, value, cancellationToken); if (res > 0) { return(RestFull.Success(data: res)); } else { return(RestFull.Fail(data: res)); } }
/// <summary> /// 删除导航(物理删除) /// </summary> /// <param name="ids"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <Result <int> > DeleteMenuAsync(long[] ids, CancellationToken cancellationToken = default) { var res = await adminMenuService.DeleteAsync(ids, cancellationToken); if (res > 0) { return(RestFull.Success(data: res)); } else { return(RestFull.Fail(data: res)); } }
public async Task <Result <int> > UpdateUserAsync([Required][FromBody] AdminUserUpdateInfoCommand request, CancellationToken cancellationToken = default) { var res = await adminUserService.UpdateAsync(request, cancellationToken); if (res > 0) { return(RestFull.Success(data: res)); } else { return(RestFull.Fail(data: res)); } }
/// <summary> /// 更新密码 /// </summary> /// <param name="command"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <Result <int> > UpdateUserAsync(AdminUserUpdatePasswordCommand command, CancellationToken cancellationToken = default) { var res = await adminUserService.UpdateAsync(command, cancellationToken); if (res > 0) { return(RestFull.Success(data: res)); } else { return(RestFull.Fail(data: res)); } }
public async Task <Result <LoginTokenDto> > Login([FromBody] AdminUserLoginCommand command, CancellationToken cancellationToken) { (var accessToken, var refreshToken) = await _adminManager.LoginAsync(command); // 设置 Swagger 自动登录 Web.HttpContext.SigninToSwagger(accessToken); // 设置刷新 token Web.HttpContext.Response.Headers["x-access-token"] = refreshToken; return(RestFull.Success(data: new LoginTokenDto { Token = accessToken })); }
public async Task <Result <IList <LoginRecordDto> > > GetRecordListAsync([Required] int limit, [Required] long adminId, CancellationToken cancellationToken = default) { var res = await View.Create(db.Context) .Where(c => c.AdminId == adminId) .OrderByDescending(c => c.LoginTime) .Take(limit) .ProjectTo <LoginRecordDto>(mapper.ConfigurationProvider) .ToListAsync(cancellationToken); return(RestFull.Success(data: res.As <IList <LoginRecordDto> >())); }
public async Task <Result <PagedModel <AdminRoleDto> > > GetRolePageAsync([Required][FromQuery] AdminRoleQueryPagedCommand request, CancellationToken cancellationToken = default) { var res = await db.Context.AdminAuthRole .WhereIf(c => c.Status == request.Status, request.Status != Status.Default) .WhereIf(c => c.Name.Contains(request.Search), !request.Search.IsEmpty()) .OrderByBatch($"{request.Sort} {request.Order}", !request.Sort.IsEmpty() && !request.Order.IsEmpty()) .ProjectTo <AdminRoleDto>(mapper.ConfigurationProvider) .ToPagedListAsync(request.CurrentPage, request.PageSize, cancellationToken); return(RestFull.Success(data: res.ToModel())); }
public async Task <Result <int> > DeleteMenuAsync([Required] long[] ids, CancellationToken cancellationToken = default) { var res = await db.DeleteAsync <AdminMenuEntity>(c => ids.Contains(c.Id), cancellationToken); if (res > 0) { await db.DeleteAsync <AdminRoleMenuEntity>(c => ids.Contains(c.MenuId), cancellationToken); return(RestFull.Success(data: res)); } else { return(RestFull.Fail(data: res)); } }