source: FarmatikoData/FarmatikoRepo/PHRepo.cs@ 993189e

Last change on this file since 993189e was 6f203af, checked in by DimitarSlezenkovski <dslezenkovski@…>, 4 years ago

Change methods & add error controller

  • Property mode set to 100644
File size: 2.7 KB
Line 
1using FarmatikoData.FarmatikoRepoInterfaces;
2using FarmatikoData.Models;
3using Microsoft.EntityFrameworkCore;
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 }
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}
Note: See TracBrowser for help on using the repository browser.