|
1 | | -namespace HRManagementSystem.UI.Controllers |
| 1 | +using HRManagementSystem.Business.Interfaces; |
| 2 | +using HRManagementSystem.Dtos; |
| 3 | +using HRManagementSystem.UI.Extensions; |
| 4 | +using Microsoft.AspNetCore.Authorization; |
| 5 | +using Microsoft.AspNetCore.Mvc; |
| 6 | + |
| 7 | +namespace HRManagementSystem.UI.Controllers |
2 | 8 | { |
3 | | - public class ApplicationController |
| 9 | + [Authorize(Roles = "Admin")] |
| 10 | + public class ApplicationController : Controller |
4 | 11 | { |
| 12 | + private readonly IAdvertisementService _advertisementService; |
| 13 | + |
| 14 | + public ApplicationController(IAdvertisementService advertisementService) |
| 15 | + { |
| 16 | + _advertisementService = advertisementService; |
| 17 | + } |
| 18 | + |
| 19 | + public async Task<IActionResult> List() |
| 20 | + { |
| 21 | + var response = await _advertisementService.GetAllAsync(); |
| 22 | + return this.ResponseView(response); |
| 23 | + } |
| 24 | + |
| 25 | + public IActionResult Create() |
| 26 | + { |
| 27 | + return View(new AdvertisementCreateDto()); |
| 28 | + } |
| 29 | + |
| 30 | + |
| 31 | + [HttpPost] |
| 32 | + public async Task<IActionResult> Create(AdvertisementCreateDto dto) |
| 33 | + { |
| 34 | + var response = await _advertisementService.CreateAsync(dto); |
| 35 | + return this.ResponseRedirectAction(response, "List"); |
| 36 | + } |
| 37 | + |
| 38 | + public async Task<IActionResult> Update(int id) |
| 39 | + { |
| 40 | + var response = await _advertisementService.GetByIdAsync<AdvertisementUpdateDto>(id); |
| 41 | + return this.ResponseView(response); |
| 42 | + } |
| 43 | + |
| 44 | + [HttpPost] |
| 45 | + public async Task<IActionResult> Update(AdvertisementUpdateDto dto) |
| 46 | + { |
| 47 | + var response = await _advertisementService.UpdateAsync(dto); |
| 48 | + return this.ResponseRedirectAction(response, "List"); |
| 49 | + } |
| 50 | + |
| 51 | + public async Task<IActionResult> Remove(int id) |
| 52 | + { |
| 53 | + var response = await _advertisementService.RemoveAsync(id); |
| 54 | + return this.ResponseRedirectAction(response, "List"); |
| 55 | + } |
| 56 | + |
5 | 57 | } |
6 | 58 | } |
0 commit comments