Last change
on this file since ee137aa was a55ef91, checked in by DimitarSlezenkovski <dslezenkovski@…>, 4 years ago |
Update & add service
|
-
Property mode
set to
100644
|
File size:
1.6 KB
|
Line | |
---|
1 | using FarmatikoData.FarmatikoRepoInterfaces;
|
---|
2 | using FarmatikoData.Models;
|
---|
3 | using System.Collections.Generic;
|
---|
4 | using System.Linq;
|
---|
5 |
|
---|
6 | namespace FarmatikoData.FarmatikoRepo
|
---|
7 | {
|
---|
8 | public class PharmacyRepository : IPharmacyRepository
|
---|
9 | {
|
---|
10 | private FarmatikoDataContext _context;
|
---|
11 |
|
---|
12 | public PharmacyRepository(FarmatikoDataContext context)
|
---|
13 | {
|
---|
14 | _context = context;
|
---|
15 | }
|
---|
16 |
|
---|
17 | public void Add(Pharmacy pharmacy)
|
---|
18 | {
|
---|
19 | _context.Pharmacies.Add(pharmacy);
|
---|
20 | _context.SaveChangesAsync();
|
---|
21 | }
|
---|
22 | //Just for users
|
---|
23 | public IQueryable<Pharmacy> GetAll()
|
---|
24 | {
|
---|
25 | return _context.Pharmacies.OrderBy(x => x.Name);
|
---|
26 | }
|
---|
27 |
|
---|
28 | public ICollection<Pharmacy> GetPharmacies()
|
---|
29 | {
|
---|
30 | return (ICollection<Pharmacy>)_context.Pharmacies.Select(pharmacy => new
|
---|
31 | {
|
---|
32 | pharmacy.Name,
|
---|
33 | pharmacy.Address,
|
---|
34 | pharmacy.Location,
|
---|
35 | pharmacy.WorkAllTime
|
---|
36 | }).OrderBy(x => x.Name);
|
---|
37 | }
|
---|
38 |
|
---|
39 | public void Remove(Pharmacy pharmacy)
|
---|
40 | {
|
---|
41 | var pharma = _context.Pharmacies.Where(pharm => pharm.Name.Equals(pharmacy.Name)).Cast<Pharmacy>();
|
---|
42 | _context.Pharmacies.Remove((Pharmacy)pharma);
|
---|
43 | _context.SaveChangesAsync();
|
---|
44 | }
|
---|
45 |
|
---|
46 | public void UpdatePharmacy(Pharmacy pharmacy, string Name)
|
---|
47 | {
|
---|
48 | var oldPharmacy = _context.Pharmacies.Where(pharma => pharma.Name.Equals(Name)).Cast<Pharmacy>();
|
---|
49 | _context.Pharmacies.Remove((Pharmacy)oldPharmacy);
|
---|
50 | _context.Pharmacies.Add(pharmacy);
|
---|
51 | _context.SaveChangesAsync();
|
---|
52 | }
|
---|
53 | }
|
---|
54 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.