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