TekH e9527ca61e Refactor namespaces and update DTO structures
Updated namespaces for DTOs and services to improve project organization. Marked several interfaces as obsolete in favor of MediatR for better request handling. Simplified `BaseUpdateDto` and other DTOs by removing `IUnique<int>` implementation. Changed return types of `CreateAsync` methods to return corresponding read DTOs. Removed reference to `DigitalData.Core.DTO` in the project file, reflecting a shift in architecture for maintainability.
2025-06-25 17:14:24 +02:00

73 lines
2.8 KiB
C#

using AutoMapper;
using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.GroupOfUser;
using DigitalData.UserManager.Domain.Entities;
using DigitalData.UserManager.Application.Contracts.Repositories;
using DigitalData.Core.Abstraction.Application.DTO;
namespace DigitalData.UserManager.Application.Services
{
[Obsolete("Use MediatR")]
public class GroupOfUserService : BaseService<IGroupOfUserRepository, GroupOfUserCreateDto, GroupOfUserReadDto, GroupOfUser>, IGroupOfUserService
{
public GroupOfUserService(IGroupOfUserRepository repository, IMapper mapper) : base(repository, mapper)
{
}
public async Task<Result> DeleteAsyncByGroupUserId(int groupId, int userId)
{
var mous = await _repository.ReadByGroupUserIdAsync(groupId, userId);
foreach (var mou in mous)
{
await _repository.DeleteAsync(mou);
}
return Result.Success();
}
public async Task<DataResult<IEnumerable<GroupOfUserReadDto>>> ReadAllAsyncWith(bool user, bool group)
{
IEnumerable<GroupOfUser> entities;
if(user && group)
{
entities = await _repository.ReadAllAsyncWithGroupAndUser();
}
else if (user)
{
entities = await _repository.ReadAllAsyncWithUser();
}
else if (group)
{
entities = await _repository.ReadAllAsyncWithGroup();
}
else
{
entities = await _repository.ReadAllAsync();
}
var gouReadDtos = _mapper.Map<IEnumerable<GroupOfUserReadDto>>(entities);
return Result.Success(gouReadDtos);
}
public async Task<Result> HasGroup(string username, string groupname, bool caseSensitive = true)
{
var gous = await _repository.ReadAllAsyncWithGroupAndUser();
if(caseSensitive)
gous = gous.Where(gous => gous.User?.Username == username && gous.Group?.Name == groupname);
else
gous = gous.Where(gous => gous.User?.Username.ToLower() == username.ToLower() && gous.Group?.Name?.ToLower() == groupname.ToLower());
return gous.Any() ? Result.Success() : Result.Fail();
}
public async Task<DataResult<IEnumerable<GroupOfUserReadDto>>> ReadByUsernameAsync(string username)
{
var groups = await _repository.ReadByUsernameAsync(username);
var groupDtos = _mapper.Map<IEnumerable<GroupOfUserReadDto>>(groups);
return Result.Success(groupDtos);
}
}
}