source: FarmatikoData/FarmatikoRepo/PharmacyRepository.cs@ a55ef91

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

Update & add service

  • Property mode set to 100644
File size: 1.6 KB
Line 
1using FarmatikoData.FarmatikoRepoInterfaces;
2using FarmatikoData.Models;
3using System.Collections.Generic;
4using System.Linq;
5
6namespace 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.