Last change
on this file since 4e72684 was 4e72684, checked in by DimitarSlezenkovski <dslezenkovski@…>, 4 years ago |
Add services
|
-
Property mode
set to
100644
|
File size:
1.6 KB
|
Rev | Line | |
---|
[de2baac] | 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 | }
|
---|
[4e72684] | 24 | //Just for users
|
---|
| 25 | public IEnumerable<Pharmacy> GetAll()
|
---|
| 26 | {
|
---|
| 27 | return _context.Pharmacies.OrderBy(x => x.Name);
|
---|
| 28 | }
|
---|
[de2baac] | 29 |
|
---|
| 30 | public ICollection<Pharmacy> GetPharmacies()
|
---|
| 31 | {
|
---|
| 32 | return (ICollection<Pharmacy>)_context.Pharmacies.Select(pharmacy => new
|
---|
| 33 | {
|
---|
| 34 | pharmacy.Name,
|
---|
| 35 | pharmacy.Address,
|
---|
| 36 | pharmacy.Location,
|
---|
| 37 | pharmacy.WorkAllTime
|
---|
| 38 | });
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | public void Remove(Pharmacy pharmacy)
|
---|
| 42 | {
|
---|
| 43 | var pharma = _context.Pharmacies.Where(pharm => pharm.Equals(pharmacy));
|
---|
| 44 | _context.Pharmacies.Remove((Pharmacy)pharma);
|
---|
| 45 | _context.SaveChangesAsync();
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | public void UpdatePharmacy(Pharmacy pharmacy, string Name)
|
---|
| 49 | {
|
---|
| 50 | var oldPharmacy = _context.Pharmacies.Where(pharma => pharma.Name.Equals(Name));
|
---|
| 51 | _context.Pharmacies.Remove((Pharmacy)oldPharmacy);
|
---|
| 52 | _context.Pharmacies.Add(pharmacy);
|
---|
| 53 | _context.SaveChangesAsync();
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.