using AutoMapper; using DigitalData.Core.Application; using DigitalData.Core.Contracts.Application; using DigitalData.Core.Contracts.CultureServices; using DigitalData.UserManager.Application.Contracts; using DigitalData.UserManager.Application.DTOs.User; using DigitalData.UserManager.Domain.Entities; using DigitalData.UserManager.Infrastructure.Contracts; namespace DigitalData.UserManager.Application.Services { public class UserService : CRUDService, IUserService { public UserService(IUserRepository repository, IKeyTranslationService translationService, IMapper mapper) : base(repository, translationService, mapper) { } public async Task>> ReadByModuleIdAsync(int moduleId) { var users = await _repository.ReadByModuleIdAsync(moduleId); IEnumerable readDTOs = _mapper.MapOrThrow>(users); return Successful(readDTOs); } public async Task>> ReadByGroupIdAsync(int groupId) { var users = await _repository.ReadByGroupIdAsync(groupId); IEnumerable readDTOs = _mapper.MapOrThrow>(users); return Successful(readDTOs); } public async Task>> ReadUnassignedByModuleIdAsync(int moduleId) { var users = await _repository.ReadUnassignedByModuleIdAsync(moduleId); IEnumerable readDTOs = _mapper.MapOrThrow>(users); return Successful(readDTOs); } public async Task>> ReadUnassignedByGroupIdAsync(int groupId) { var users = await _repository.ReadUnassignedByGroupIdAsync(groupId); IEnumerable readDTOs = _mapper.MapOrThrow>(users); return Successful(readDTOs); } public async Task> CreateAsync(UserPrincipalDto upDto) { var user = _mapper.MapOrThrow(upDto); if (await HasEntity(user.Guid)) return Failed(MessageKey.UserAlreadyExists.ToString()); var createdUser = await _repository.CreateAsync(user); if (createdUser is null) return Failed(); else return Successful(KeyValueOf(createdUser)); } } }