Developer 02 0abdbfa705 Refaktorisierung der Lokalisierung und DTO-Integration
- Ersetzung von ITranslateService durch IStringLocalizer<X> für verbesserte Lokalisierung.
- Aktualisierung der DTO-Klassen entsprechend der neuesten Core.DTO-Struktur.
- Integration der neuen Klassen Result und DataResult aus Core.DTO für standardisierte Serviceantworten.
2024-05-02 17:36:53 +02:00

32 lines
1.3 KiB
C#

using AutoMapper;
using DigitalData.Core.Application;
using DigitalData.Core.DTO;
using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.Group;
using DigitalData.UserManager.Domain.Entities;
using DigitalData.UserManager.Infrastructure.Contracts;
using Microsoft.Extensions.Localization;
namespace DigitalData.UserManager.Application.Services
{
public class GroupService : CRUDService<IGroupRepository, GroupCreateDto, GroupReadDto, GroupUpdateDto, Group, int>, IGroupService
{
public GroupService(IGroupRepository repository, IStringLocalizer<Resource> localizer, IMapper mapper) : base(repository, localizer, mapper)
{
}
public async Task<DataResult<int>> CreateAsync(DirectoryGroupDto adGroup)
{
var group = _mapper.MapOrThrow<Group>(adGroup);
if (await HasEntity(group.Guid))
return Result.Fail<int>().Message(_localizer[Key.GroupAlreadyExists.ToString()]);
var createdGroup = await _repository.CreateAsync(group);
if (createdGroup is null)
return Result.Fail<int>();
else
return Result.Success(KeyValueOf(createdGroup));
}
}
}