39 lines
1.5 KiB
C#
39 lines
1.5 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
|
|
{
|
|
private readonly IStringLocalizer<Resource> _localizer;
|
|
public GroupService(IGroupRepository repository, IStringLocalizer<Resource> localizer, IMapper mapper) : base(repository, mapper)
|
|
{
|
|
_localizer = localizer;
|
|
}
|
|
|
|
public override Task<DataResult<int>> CreateAsync(GroupCreateDto createDto)
|
|
{
|
|
return base.CreateAsync(createDto);
|
|
}
|
|
|
|
public async Task<DataResult<int>> CreateAsync(DirectoryGroupDto adGroup)
|
|
{
|
|
var group = _mapper.MapOrThrow<Group>(adGroup);
|
|
|
|
if (await HasEntity(group.Id))
|
|
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));
|
|
}
|
|
}
|
|
} |