From fadb0fd1b7a13d1c6210e11f2db2add7c8fd45a9 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 17 Dec 2020 11:59:52 +0200 Subject: Reworked RoleController and RoleService to be consistent with the app structure --- src/DevHive.Web/Controllers/RoleController.cs | 35 +++++++++++++++++++++------ 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'src/DevHive.Web/Controllers/RoleController.cs') diff --git a/src/DevHive.Web/Controllers/RoleController.cs b/src/DevHive.Web/Controllers/RoleController.cs index 610d370..1664f4f 100644 --- a/src/DevHive.Web/Controllers/RoleController.cs +++ b/src/DevHive.Web/Controllers/RoleController.cs @@ -25,33 +25,52 @@ namespace DevHive.Web.Controllers } [HttpPost] - public Task Create(CreateRoleWebModel createRoleWebModel) + public async Task Create([FromBody] CreateRoleWebModel createRoleWebModel) { RoleServiceModel roleServiceModel = this._roleMapper.Map(createRoleWebModel); - return this._roleService.CreateRole(roleServiceModel); + bool result = await this._roleService.CreateRole(roleServiceModel); + + if (!result) + return new BadRequestObjectResult("Could not create role!"); + + return new OkResult(); } [HttpGet] - public Task GetById(Guid id) + public async Task GetById(Guid id) { - return this._roleService.GetRoleById(id); + RoleServiceModel roleServiceModel = await this._roleService.GetRoleById(id); + RoleWebModel roleWebModel = this._roleMapper.Map(roleServiceModel); + + return new OkObjectResult(roleWebModel); } [HttpPut] - public Task Update(UpdateRoleWebModel updateRoleWebModel) + public async Task Update(Guid id, [FromBody] UpdateRoleWebModel updateRoleWebModel) { RoleServiceModel roleServiceModel = this._roleMapper.Map(updateRoleWebModel); + roleServiceModel.Id = id; + + bool result = await this._roleService.UpdateRole(roleServiceModel); - return this._roleService.UpdateRole(roleServiceModel); + if (!result) + return new BadRequestObjectResult("Could not update role!"); + + return new OkResult(); } [HttpDelete] - public Task Delete(Guid id) + public async Task Delete(Guid id) { - return this._roleService.DeleteRole(id); + bool result = await this._roleService.DeleteRole(id); + + if (!result) + return new BadRequestObjectResult("Could nor delete role!"); + + return new OkResult(); } } } -- cgit v1.2.3