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

52 lines
2.0 KiB
C#

using AutoMapper;
using DigitalData.Core.Abstraction.Application.DTO;
using DigitalData.Core.Abstraction.Application.Repository;
using DigitalData.Core.Application;
using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.Base;
using DigitalData.UserManager.Application.DTOs.User;
using DigitalData.UserManager.Domain.Entities;
namespace DigitalData.UserManager.Application.Services
{
[Obsolete("Use MediatR")]
public class BaseService<TCRUDRepository, TCreateDto, TReadDto, TBaseEntity> : CRUDService<TCRUDRepository, TCreateDto, TReadDto, TBaseEntity, int>, IBaseService<TCreateDto, TReadDto, TBaseEntity>
where TCRUDRepository : ICRUDRepository<TBaseEntity, int>
where TCreateDto : BaseCreateDto
where TReadDto : class
where TBaseEntity : BaseEntity
{
public BaseService(TCRUDRepository repository, IMapper mapper) : base(repository, mapper)
{
}
private Lazy<Task<UserReadDto?>>? _lazyUserAsync = null;
public Func<Task<UserReadDto?>> UserFactoryAsync { set => _lazyUserAsync = new Lazy<Task<UserReadDto?>>(value); }
public async Task<UserReadDto?> GetUserAsync() => _lazyUserAsync is null ? null : await _lazyUserAsync.Value;
public override async Task<DataResult<TReadDto>> CreateAsync(TCreateDto createDto)
{
var user = await GetUserAsync();
if(user is not null)
{
createDto.AddedWho = user.Username;
}
return await base.CreateAsync(createDto);
}
// made without generic type
public override async Task<Result> UpdateAsync<TUpdateDto>(TUpdateDto updateDto)
{
var user = await GetUserAsync();
if (user is not null && updateDto is BaseUpdateDto baseUpdateDto)
{
baseUpdateDto.ChangedWho = user.Username;
}
return await base.UpdateAsync(updateDto);
}
}
}