source: Farmatiko/Controllers/AdminController.cs@ dae4cde

Last change on this file since dae4cde was e0cdea2, checked in by Dimitar Slezenkovski <dslezenkovski@…>, 4 years ago

Fix all bugs

  • Property mode set to 100644
File size: 2.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Threading.Tasks;
5using FarmatikoData.DTOs;
6using FarmatikoData.Models;
7using FarmatikoServices.FarmatikoServiceInterfaces;
8using Microsoft.AspNetCore.Authorization;
9using Microsoft.AspNetCore.Mvc;
10
11namespace 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}
Note: See TracBrowser for help on using the repository browser.