aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Services/Services
diff options
context:
space:
mode:
Diffstat (limited to 'src/DevHive.Services/Services')
-rw-r--r--src/DevHive.Services/Services/RoleService.cs24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/DevHive.Services/Services/RoleService.cs b/src/DevHive.Services/Services/RoleService.cs
index c38ac74..0945624 100644
--- a/src/DevHive.Services/Services/RoleService.cs
+++ b/src/DevHive.Services/Services/RoleService.cs
@@ -1,14 +1,15 @@
using System;
using System.Threading.Tasks;
using AutoMapper;
-using DevHive.Common.Models.Identity;
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
+ public class RoleService : IRoleService
{
private readonly IRoleRepository _roleRepository;
private readonly IMapper _roleMapper;
@@ -19,25 +20,34 @@ namespace DevHive.Services.Services
this._roleMapper = mapper;
}
- public async Task<bool> CreateRole(RoleModel roleServiceModel)
+ public async Task<Guid> CreateRole(RoleServiceModel 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;
- return await this._roleRepository.AddAsync(role);
}
- public async Task<RoleModel> GetRoleById(Guid id)
+ 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<RoleModel>(role);
+ return this._roleMapper.Map<RoleServiceModel>(role);
}
- public async Task<bool> UpdateRole(RoleModel roleServiceModel)
+ public async Task<bool> UpdateRole(RoleServiceModel roleServiceModel)
{
if (!await this._roleRepository.DoesRoleExist(roleServiceModel.Id))
throw new ArgumentException("Role does not exist!");