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