using System.Threading.Tasks; using DevHive.Data.Repositories; using DevHive.Services.Services; using Microsoft.AspNetCore.Mvc; using DevHive.Web.Models.Identity.Role; using AutoMapper; using DevHive.Services.Models.Identity.Role; using System; namespace DevHive.Web.Controllers { [ApiController] [Route("/api/[controller]")] public class RoleController { private readonly RoleService _roleService; private readonly IMapper _roleMapper; public RoleController(DevHiveContext context, IMapper mapper) { this._roleService = new RoleService(context, mapper); this._roleMapper = mapper; } [HttpPost] public Task Create(CreateRoleWebModel createRoleWebModel) { RoleServiceModel roleServiceModel = this._roleMapper.Map(createRoleWebModel); return this._roleService.CreateRole(roleServiceModel); } [HttpGet] public Task GetById(Guid id) { return this._roleService.GetRoleById(id); } [HttpPut] public Task Update(UpdateRoleWebModel updateRoleWebModel) { RoleServiceModel roleServiceModel = this._roleMapper.Map(updateRoleWebModel); return this._roleService.UpdateRole(roleServiceModel); } [HttpDelete] public Task Delete(Guid id) { return this._roleService.DeleteRole(id); } } }