46 lines
2.1 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(IModuleService moduleService, 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);
}
}
}