source: FarmatikoData/FarmatikoRepo/PHRepo.cs@ d23bf72

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

Add SystemService, Auth, fix a lil bugs :)

  • Property mode set to 100644
File size: 2.9 KB
RevLine 
[1454207]1using FarmatikoData.FarmatikoRepoInterfaces;
2using FarmatikoData.Models;
[6f203af]3using Microsoft.EntityFrameworkCore;
[1454207]4using System.Collections.Generic;
5using System.Linq;
6using System.Threading.Tasks;
7
8namespace FarmatikoData.FarmatikoRepo
9{
10 public class PHRepo : IPHRepo
11 {
12 private readonly FarmatikoDataContext _context;
13 public PHRepo(FarmatikoDataContext context)
14 {
15 _context = context;
16 }
[6f203af]17 //GET
18 public async Task<PharmacyHead> GetPharmacyHeadByIdAsync(int id)
[1454207]19 {
[6f203af]20 var Phead = await _context.PharmacyHeads.Where(x => x.Id == id).FirstOrDefaultAsync();
[1454207]21 return Phead;
22 }
23
[6f203af]24 public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo()
[1454207]25 {
[6f203af]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();
[1454207]36 return PHeadInfo;
37 }
[6f203af]38 //POST
[1454207]39 public async Task UpdatePharmacyHead(PharmacyHead pharmacyHead)
40 {
[6f203af]41 var EditedPHead = await _context.PharmacyHeads.Where(x => x.Id == pharmacyHead.Id).FirstOrDefaultAsync();
[1454207]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 }
[6f203af]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 }
[d23bf72]73
74 public PharmacyHead GetPharmacyHeadByUserName(string userName)
75 {
76 return _context.PharmacyHeads
77 .Where(x => x.Email.Equals(userName))
78 .FirstOrDefault();
79 }
[1454207]80 }
81}
Note: See TracBrowser for help on using the repository browser.