diff options
Diffstat (limited to 'src/DevHive.Web/Controllers/RoleController.cs')
| -rw-r--r-- | src/DevHive.Web/Controllers/RoleController.cs | 30 |
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!"); |
