source: FarmatikoServices/Services/PHService.cs@ ad60966

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

Add SystemService, Auth, fix a lil bugs :)

  • Property mode set to 100644
File size: 3.0 KB
Line 
1using FarmatikoData.FarmatikoRepoInterfaces;
2using FarmatikoData.Models;
3using FarmatikoServices.FarmatikoServiceInterfaces;
4using System;
5using System.Collections.Generic;
6using System.Linq;
7using System.Text;
8using System.Threading.Tasks;
9
10namespace FarmatikoServices.Services
11{
12 public class PHService : IPHService
13 {
14 private readonly IPHRepo _iPHRepo;
15 public PHService(IPHRepo iPHRepo)
16 {
17 _iPHRepo = iPHRepo;
18 }
19
20 public async Task<bool> ClaimPharmacy(RequestPharmacyHead pharmacy)
21 {
22 if (pharmacy != null)
23 {
24 await _iPHRepo.ClaimPharmacy(pharmacy);
25 return true;
26 }
27 return false;
28 }
29
30 public async Task<PharmacyHead> GetPharmacyHeadByIdAsync(int id)
31 {
32 PharmacyHead Phead = null;
33 if (id >= 0)
34 Phead = await _iPHRepo.GetPharmacyHeadByIdAsync(id);
35 if (Phead != null)
36 return Phead;
37 throw new Exception("No data found.");
38 }
39
40 public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo()
41 {
42 var PHeads = await _iPHRepo.GetPharmacyHeadInfo();
43 if (PHeads != null)
44 return PHeads;
45 throw new Exception("No Pharmacy heads found.");
46 }
47
48 public async Task<int> Login(PharmacyHead pharmacyHead)
49 {
50 var PHead = await _iPHRepo.GetPharmacyHeadByIdAsync(pharmacyHead.Id);
51 if (PHead.Password.Equals(pharmacyHead.Password))
52 return PHead.Id;
53 return -1;
54 }
55
56
57 public async Task UpdatePharmacyHead(PharmacyHead pharmacyHead)
58 {
59 if (pharmacyHead != null)
60 await _iPHRepo.UpdatePharmacyHead(pharmacyHead);
61 else throw new Exception("PharmacyHead has a null value.");
62 }
63 public async Task<bool> Add(PharmacyHead pharmacyHead)
64 {
65 if (pharmacyHead != null)
66 {
67 await _iPHRepo.Add(pharmacyHead);
68 return true;
69 }
70 return false;
71 }
72
73 public async Task<bool> Remove(int id)
74 {
75 PharmacyHead Phead = await _iPHRepo.GetPharmacyHeadByIdAsync(id);
76 if (Phead != null && id >= 0)
77 {
78 Phead.DeletedOn = DateTime.UtcNow;
79 await _iPHRepo.Remove(Phead);
80 return true;
81 }
82 return false;
83 }
84
85 public async Task<bool> RemoveClaimingRequest(int id)
86 {
87 if (id >= 0)
88 {
89 await _iPHRepo.RemoveClaimingRequest(id);
90 return true;
91 }
92 return false;
93 }
94
95 public PharmacyHead GetPharmacyHead(string userName)
96 {
97 if (userName != null)
98 {
99 return _iPHRepo.GetPharmacyHeadByUserName(userName);
100 }
101 return default;
102 }
103 }
104}
Note: See TracBrowser for help on using the repository browser.