using Yi.RBAC.Application.Contracts.Identity; using NET.AutoWebApi.Setting; using Yi.RBAC.Application.Contracts.Identity.Dtos; using Yi.RBAC.Domain.Identity.Entities; using Yi.Framework.Ddd.Services; using Yi.RBAC.Domain.Shared.Identity.ConstClasses; using Yi.RBAC.Domain.Identity; using Yi.Framework.Uow; using Yi.Framework.Ddd.Dtos; using Yi.RBAC.Domain.Identity.Repositories; namespace Yi.RBAC.Application.Identity { /// /// User服务实现 /// [AppService] public class UserService : CrudAppService, IUserService, IAutoApiService { [Autowired] private UserManager _userManager { get; set; } [Autowired] private IUnitOfWorkManager _unitOfWorkManager { get; set; } [Autowired] private IUserRepository _userRepository { get; set; } /// /// 查询用户 /// /// /// public override async Task> GetListAsync(UserGetListInputVo input) { var entity = await MapToEntityAsync(input); var entities = await _userRepository.SelctGetListAsync(entity, input); var result = new PagedResultDto(); result.Items = await MapToGetListOutputDtosAsync(entities); result.Total = await _repository.CountAsync(_ => true); return result; } /// /// 添加用户 /// /// /// /// public async override Task CreateAsync(UserCreateInputVo input) { if (string.IsNullOrEmpty(input.Password)) { throw new UserFriendlyException(UserConst.添加失败_密码为空); } if (await _repository.IsAnyAsync(u => input.UserName.Equals(u.UserName))) { throw new UserFriendlyException(UserConst.添加失败_用户存在); } var entities = await MapToEntityAsync(input); entities.BuildPassword(); using (var uow = _unitOfWorkManager.CreateContext()) { var returnEntity = await _repository.InsertReturnEntityAsync(entities); await _userManager.GiveUserSetRoleAsync(new List { returnEntity.Id }, input.RoleIds); await _userManager.GiveUserSetPostAsync(new List { returnEntity.Id }, input.PostIds); uow.Commit(); var result = await MapToGetOutputDtoAsync(returnEntity); return result; } } } }