60 lines
2.6 KiB
C#
60 lines
2.6 KiB
C#
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<IUserRepository, UserCreateDto, UserReadDto, UserUpdateDto, User, int>, IUserService
|
|
{
|
|
public UserService(IUserRepository repository, IKeyTranslationService translationService, IMapper mapper) : base(repository, translationService, mapper)
|
|
{
|
|
}
|
|
|
|
public async Task<IServiceResult<IEnumerable<UserReadDto>>> ReadByModuleIdAsync(int moduleId)
|
|
{
|
|
var users = await _repository.ReadByModuleIdAsync(moduleId);
|
|
IEnumerable<UserReadDto> readDTOs = _mapper.MapOrThrow<IEnumerable<UserReadDto>>(users);
|
|
return Successful(readDTOs);
|
|
}
|
|
|
|
public async Task<IServiceResult<IEnumerable<UserReadDto>>> ReadByGroupIdAsync(int groupId)
|
|
{
|
|
var users = await _repository.ReadByGroupIdAsync(groupId);
|
|
IEnumerable<UserReadDto> readDTOs = _mapper.MapOrThrow<IEnumerable<UserReadDto>>(users);
|
|
return Successful(readDTOs);
|
|
}
|
|
|
|
public async Task<IServiceResult<IEnumerable<UserReadDto>>> ReadUnassignedByModuleIdAsync(int moduleId)
|
|
{
|
|
var users = await _repository.ReadUnassignedByModuleIdAsync(moduleId);
|
|
IEnumerable<UserReadDto> readDTOs = _mapper.MapOrThrow<IEnumerable<UserReadDto>>(users);
|
|
return Successful(readDTOs);
|
|
}
|
|
|
|
public async Task<IServiceResult<IEnumerable<UserReadDto>>> ReadUnassignedByGroupIdAsync(int groupId)
|
|
{
|
|
var users = await _repository.ReadUnassignedByGroupIdAsync(groupId);
|
|
IEnumerable<UserReadDto> readDTOs = _mapper.MapOrThrow<IEnumerable<UserReadDto>>(users);
|
|
return Successful(readDTOs);
|
|
}
|
|
|
|
public async Task<IServiceResult<int>> CreateAsync(UserPrincipalDto upDto)
|
|
{
|
|
var user = _mapper.MapOrThrow<User>(upDto);
|
|
|
|
if (await HasEntity(user.Guid))
|
|
return Failed<int>(MessageKey.UserAlreadyExists.ToString());
|
|
|
|
var createdUser = await _repository.CreateAsync(user);
|
|
if (createdUser is null)
|
|
return Failed<int>();
|
|
else
|
|
return Successful(KeyValueOf(createdUser));
|
|
}
|
|
}
|
|
} |