aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Web/Controllers/RoleController.cs
diff options
context:
space:
mode:
authorSyndamia <kamen.d.mladenov@protonmail.com>2021-01-17 14:45:48 +0200
committerSyndamia <kamen.d.mladenov@protonmail.com>2021-01-17 14:45:48 +0200
commit8d1d0b40d56f90248f948e474330258bf57cf0b6 (patch)
treeab4431208ea495c6b8c5de0b91cb85cdef66d20e /src/DevHive.Web/Controllers/RoleController.cs
parent83f63ad729d585d597bdcf0afc05b7d56344223e (diff)
downloadDevHive-8d1d0b40d56f90248f948e474330258bf57cf0b6.tar
DevHive-8d1d0b40d56f90248f948e474330258bf57cf0b6.tar.gz
DevHive-8d1d0b40d56f90248f948e474330258bf57cf0b6.zip
Fixed role implementation by bringing back and improving all role models
Diffstat (limited to 'src/DevHive.Web/Controllers/RoleController.cs')
-rw-r--r--src/DevHive.Web/Controllers/RoleController.cs28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/DevHive.Web/Controllers/RoleController.cs b/src/DevHive.Web/Controllers/RoleController.cs
index 8ea2711..5b3dca5 100644
--- a/src/DevHive.Web/Controllers/RoleController.cs
+++ b/src/DevHive.Web/Controllers/RoleController.cs
@@ -3,12 +3,12 @@ using Microsoft.AspNetCore.Mvc;
using DevHive.Web.Models.Identity.Role;
using AutoMapper;
using System;
-using DevHive.Common.Models.Identity;
using DevHive.Services.Interfaces;
+using DevHive.Services.Models.Identity.Role;
namespace DevHive.Web.Controllers
{
- [ApiController]
+ [ApiController]
[Route("/api/[controller]")]
//[Authorize(Roles = "Admin")]
public class RoleController
@@ -23,33 +23,33 @@ namespace DevHive.Web.Controllers
}
[HttpPost]
- public async Task<IActionResult> Create([FromBody] CreateRoleModel createRoleModel)
+ public async Task<IActionResult> Create([FromBody] CreateRoleWebModel createRoleWebModel)
{
- RoleModel roleServiceModel =
- this._roleMapper.Map<RoleModel>(createRoleModel);
+ RoleServiceModel roleServiceModel =
+ this._roleMapper.Map<RoleServiceModel>(createRoleWebModel);
- bool result = await this._roleService.CreateRole(roleServiceModel);
+ Guid id = await this._roleService.CreateRole(roleServiceModel);
- if (!result)
- return new BadRequestObjectResult("Could not create role!");
+ return id == Guid.Empty ?
+ new BadRequestObjectResult($"Could not create role {createRoleWebModel.Name}") :
+ new OkObjectResult(new { Id = id });
- return new OkResult();
}
[HttpGet]
public async Task<IActionResult> GetById(Guid id)
{
- RoleModel roleServiceModel = await this._roleService.GetRoleById(id);
- RoleModel roleWebModel = this._roleMapper.Map<RoleModel>(roleServiceModel);
+ RoleServiceModel roleServiceModel = await this._roleService.GetRoleById(id);
+ RoleWebModel roleWebModel = this._roleMapper.Map<RoleWebModel>(roleServiceModel);
return new OkObjectResult(roleWebModel);
}
[HttpPut]
- public async Task<IActionResult> Update(Guid id, [FromBody] UpdateRoleModel updateRoleModel)
+ public async Task<IActionResult> Update(Guid id, [FromBody] UpdateRoleWebModel updateRoleWebModel)
{
- RoleModel roleServiceModel =
- this._roleMapper.Map<RoleModel>(updateRoleModel);
+ RoleServiceModel roleServiceModel =
+ this._roleMapper.Map<RoleServiceModel>(updateRoleWebModel);
roleServiceModel.Id = id;
bool result = await this._roleService.UpdateRole(roleServiceModel);