aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Web/Controllers/RoleController.cs
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-01-21 22:13:16 +0200
committertranstrike <transtrike@gmail.com>2021-01-21 22:13:16 +0200
commit13a2ceda912f961a232c87236f1b29aa29bb6160 (patch)
tree59f8d2bf63b03bacc76f98114d2aed78e420ddcd /src/DevHive.Web/Controllers/RoleController.cs
parenta47ea20ab91017da53437f750ed8e0f939f5cdba (diff)
parentbda98b96433d7a9952524fab4ec65f96998b55de (diff)
downloadDevHive-13a2ceda912f961a232c87236f1b29aa29bb6160.tar
DevHive-13a2ceda912f961a232c87236f1b29aa29bb6160.tar.gz
DevHive-13a2ceda912f961a232c87236f1b29aa29bb6160.zip
Merge branch 'refactor_user_updating' into dev
Diffstat (limited to 'src/DevHive.Web/Controllers/RoleController.cs')
-rw-r--r--src/DevHive.Web/Controllers/RoleController.cs30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/DevHive.Web/Controllers/RoleController.cs b/src/DevHive.Web/Controllers/RoleController.cs
index 8ea2711..227b877 100644
--- a/src/DevHive.Web/Controllers/RoleController.cs
+++ b/src/DevHive.Web/Controllers/RoleController.cs
@@ -3,8 +3,8 @@ 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
{
@@ -23,36 +23,36 @@ 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.Id = id;
+ UpdateRoleServiceModel updateRoleServiceModel =
+ this._roleMapper.Map<UpdateRoleServiceModel>(updateRoleWebModel);
+ updateRoleServiceModel.Id = id;
- bool result = await this._roleService.UpdateRole(roleServiceModel);
+ bool result = await this._roleService.UpdateRole(updateRoleServiceModel);
if (!result)
return new BadRequestObjectResult("Could not update role!");