1 | using FarmatikoData.FarmatikoRepoInterfaces;
|
---|
2 | using FarmatikoData.Models;
|
---|
3 | using Microsoft.EntityFrameworkCore;
|
---|
4 | using System.Collections.Generic;
|
---|
5 | using System.Linq;
|
---|
6 | using System.Threading.Tasks;
|
---|
7 |
|
---|
8 | namespace FarmatikoData.FarmatikoRepo
|
---|
9 | {
|
---|
10 | public class PHRepo : IPHRepo
|
---|
11 | {
|
---|
12 | private readonly FarmatikoDataContext _context;
|
---|
13 | public PHRepo(FarmatikoDataContext context)
|
---|
14 | {
|
---|
15 | _context = context;
|
---|
16 | }
|
---|
17 | //GET
|
---|
18 | public async Task<PharmacyHead> GetPharmacyHeadByIdAsync(int id)
|
---|
19 | {
|
---|
20 | var Phead = await _context.PharmacyHeads.Where(x => x.Id == id).FirstOrDefaultAsync();
|
---|
21 | return Phead;
|
---|
22 | }
|
---|
23 |
|
---|
24 | public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo()
|
---|
25 | {
|
---|
26 | var PHeadInfo = await _context.PharmacyHeads.Take(10).Where(x => x.DeletedOn == null)
|
---|
27 | .Select(x => new PharmacyHead
|
---|
28 | {
|
---|
29 | Id = x.Id,
|
---|
30 | Name = x.Name,
|
---|
31 | Email = x.Email,
|
---|
32 | Password = x.Password,
|
---|
33 | MedicineLists = x.MedicineLists,
|
---|
34 | PharmaciesList = x.PharmaciesList
|
---|
35 | }).ToListAsync();
|
---|
36 | return PHeadInfo;
|
---|
37 | }
|
---|
38 | //POST
|
---|
39 | public async Task UpdatePharmacyHead(PharmacyHead pharmacyHead)
|
---|
40 | {
|
---|
41 | var EditedPHead = await _context.PharmacyHeads.Where(x => x.Id == pharmacyHead.Id).FirstOrDefaultAsync();
|
---|
42 | EditedPHead.Email = pharmacyHead.Email;
|
---|
43 | EditedPHead.Name = pharmacyHead.Name;
|
---|
44 | EditedPHead.Password = pharmacyHead.Password;
|
---|
45 | EditedPHead.MedicineLists = pharmacyHead.MedicineLists;
|
---|
46 | EditedPHead.PharmaciesList = pharmacyHead.PharmaciesList;
|
---|
47 | await _context.SaveChangesAsync();
|
---|
48 | }
|
---|
49 | public async Task ClaimPharmacy(RequestPharmacyHead pharmacy)
|
---|
50 | {
|
---|
51 | await _context.PHRequests.AddAsync(pharmacy);
|
---|
52 | await _context.SaveChangesAsync();
|
---|
53 | }
|
---|
54 | public async Task Add(PharmacyHead pharmacyHead)
|
---|
55 | {
|
---|
56 | await _context.PharmacyHeads.AddAsync(pharmacyHead);
|
---|
57 | await _context.SaveChangesAsync();
|
---|
58 | }
|
---|
59 |
|
---|
60 | public async Task Remove(PharmacyHead phead)
|
---|
61 | {
|
---|
62 | var Phead = await _context.PharmacyHeads.Where(x => x.Id == phead.Id).FirstOrDefaultAsync();
|
---|
63 | Phead.DeletedOn = phead.DeletedOn;
|
---|
64 | await _context.SaveChangesAsync();
|
---|
65 | }
|
---|
66 |
|
---|
67 | public async Task RemoveClaimingRequest(int id)
|
---|
68 | {
|
---|
69 | var req = await _context.PHRequests.Where(r => r.Id == id).FirstOrDefaultAsync();
|
---|
70 | _context.PHRequests.Remove(req);
|
---|
71 | await _context.SaveChangesAsync();
|
---|
72 | }
|
---|
73 | }
|
---|
74 | }
|
---|