aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Web/Controllers/RoleController.cs
blob: e27c33054171f57b6da917ef327bd252782e092b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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)
		{
<<<<<<< HEAD
			this._service = new RoleService(context, mapper);
			this._roleMapper = mapper;
=======
			this._roleService = new RoleService(context, mapper);
>>>>>>> 791c559712a161c745a407a87d0f7e8d1f00492c
		}

		[HttpPost]
		public Task<IActionResult> Create(CreateRoleWebModel createRoleWebModel)
		{
			RoleServiceModel roleServiceModel = 
				this._roleMapper.Map<RoleServiceModel>(createRoleWebModel); 
			
			return this._roleService.CreateRole(roleServiceModel);
		}

		[HttpGet]
		public Task<IActionResult> GetById(Guid id)
		{
			return this._roleService.GetRoleById(id);
		}

		[HttpPut]
		public Task<IActionResult> Update(UpdateRoleWebModel updateRoleWebModel)
		{
			RoleServiceModel roleServiceModel = 
				this._roleMapper.Map<RoleServiceModel>(updateRoleWebModel);

			return this._roleService.UpdateRole(roleServiceModel);
		}

		[HttpDelete]
		public Task<IActionResult> Delete(Guid id)
		{
			return this._roleService.DeleteRole(id);
		}
	}
}