source: Farmatiko/Controllers/AdminController.cs@ 1db5673

Last change on this file since 1db5673 was 1db5673, checked in by DimitarSlezenkovski <dslezenkovski@…>, 4 years ago

Fix bugs, add some more

  • Property mode set to 100644
File size: 2.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Threading.Tasks;
5using FarmatikoData.Models;
6using FarmatikoServices.FarmatikoServiceInterfaces;
7using Microsoft.AspNetCore.Authorization;
8using Microsoft.AspNetCore.Mvc;
9
10namespace Farmatiko.Controllers
11{
12 [ApiController]
13 [Authorize(Roles = "Admin")]
14 public class AdminController : Controller
15 {
16 private readonly IAdminService _adminService;
17 private readonly IService _service;
18 private readonly IPHService _phservice;
19 public AdminController(IAdminService adminService, IService service, IPHService phservice)
20 {
21 _adminService = adminService;
22 _service = service;
23 _phservice = phservice;
24 }
25
26 //GET
27 [HttpGet]
28 [Route("api/pharmacyhead")]
29 public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeads()
30 {
31 return await _adminService.GetPharmacyHeads();
32 }
33
34 [HttpGet]
35 [Route("api/pharmacyhead/requests")]
36 public async Task<IEnumerable<RequestPharmacyHead>> GetClaimingRequests()
37 {
38 return await _adminService.GetClaimingRequests();
39 }
40
41
42 //POST
43 [HttpPost]
44 [Route("api/pharmacyhead/add")]
45 public async Task<IActionResult> AddPharmacyHead([FromBody]PharmacyHead pharmacyHead)
46 {
47 await _service.AddPharmacyHead(pharmacyHead);
48 return Ok();
49 }
50
51 [HttpDelete]
52 [Route("api/pharmacyhead/delete/{Id}")]
53 public async Task<IActionResult> RemovePharmacyHead([FromRoute] int Id)
54 {
55 await _service.RemovePharmacyHead(Id);
56 return Ok();
57 }
58 [HttpDelete]
59 [Route("api/pharmacyhead/requests/{Id}")]
60 public IActionResult RejectRequest([FromRoute] int Id)
61 {
62 bool Success = _adminService.RejectRequest(Id);
63 return Ok(Success);
64 }
65 [HttpPost]
66 [Route("api/pharmacyhead/{Id}")]
67 public async Task<IActionResult> ApproveRequest([FromRoute]int Id, [FromBody]PharmacyHead pharmacyHead)
68 {
69 int id = Id;
70 await _phservice.UpdatePharmacyHead(pharmacyHead);
71 return Ok();
72 }
73
74 }
75}
Note: See TracBrowser for help on using the repository browser.