diff options
| author | transtrike <transtrike@gmail.com> | 2021-02-13 16:20:18 +0200 |
|---|---|---|
| committer | transtrike <transtrike@gmail.com> | 2021-02-13 16:20:18 +0200 |
| commit | 98e17766b203734a1817eed94338e2d25f4395f7 (patch) | |
| tree | 1266385a56cba56fd55c7faf661dd844bbdf5705 /src/DevHive.Services/Services/RoleService.cs | |
| parent | 1ab34accfda22ee3ce5c7700e3b97ff3e932d649 (diff) | |
| download | DevHive-98e17766b203734a1817eed94338e2d25f4395f7.tar DevHive-98e17766b203734a1817eed94338e2d25f4395f7.tar.gz DevHive-98e17766b203734a1817eed94338e2d25f4395f7.zip | |
Project Restructure P.1
Diffstat (limited to 'src/DevHive.Services/Services/RoleService.cs')
| -rw-r--r-- | src/DevHive.Services/Services/RoleService.cs | 70 |
1 files changed, 0 insertions, 70 deletions
diff --git a/src/DevHive.Services/Services/RoleService.cs b/src/DevHive.Services/Services/RoleService.cs deleted file mode 100644 index a8b8e17..0000000 --- a/src/DevHive.Services/Services/RoleService.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.Threading.Tasks; -using AutoMapper; -using DevHive.Data.Interfaces.Repositories; -using DevHive.Data.Models; -using DevHive.Services.Interfaces; -using DevHive.Services.Models.Identity.Role; -using DevHive.Services.Models.Language; - -namespace DevHive.Services.Services -{ - public class RoleService : IRoleService - { - private readonly IRoleRepository _roleRepository; - private readonly IMapper _roleMapper; - - public RoleService(IRoleRepository roleRepository, IMapper mapper) - { - this._roleRepository = roleRepository; - this._roleMapper = mapper; - } - - public async Task<Guid> CreateRole(CreateRoleServiceModel roleServiceModel) - { - if (await this._roleRepository.DoesNameExist(roleServiceModel.Name)) - throw new ArgumentException("Role already exists!"); - - Role role = this._roleMapper.Map<Role>(roleServiceModel); - bool success = await this._roleRepository.AddAsync(role); - - if (success) - { - Role newRole = await this._roleRepository.GetByNameAsync(roleServiceModel.Name); - return newRole.Id; - } - else - return Guid.Empty; - - } - - public async Task<RoleServiceModel> GetRoleById(Guid id) - { - Role role = await this._roleRepository.GetByIdAsync(id) - ?? throw new ArgumentException("Role does not exist!"); - - return this._roleMapper.Map<RoleServiceModel>(role); - } - - public async Task<bool> UpdateRole(UpdateRoleServiceModel updateRoleServiceModel) - { - if (!await this._roleRepository.DoesRoleExist(updateRoleServiceModel.Id)) - throw new ArgumentException("Role does not exist!"); - - if (await this._roleRepository.DoesNameExist(updateRoleServiceModel.Name)) - throw new ArgumentException("Role name already exists!"); - - Role role = this._roleMapper.Map<Role>(updateRoleServiceModel); - return await this._roleRepository.EditAsync(updateRoleServiceModel.Id, role); - } - - public async Task<bool> DeleteRole(Guid id) - { - if (!await this._roleRepository.DoesRoleExist(id)) - throw new ArgumentException("Role does not exist!"); - - Role role = await this._roleRepository.GetByIdAsync(id); - return await this._roleRepository.DeleteAsync(role); - } - } -} |
