source: FarmatikoData/FarmatikoRepo/MedicineRepository.cs@ a55ef91

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

Update & add service

  • Property mode set to 100644
File size: 1.2 KB
Line 
1using FarmatikoData.FarmatikoRepoInterfaces;
2using FarmatikoData.Models;
3using System;
4using System.Linq;
5
6namespace FarmatikoData.FarmatikoRepo
7{
8 public class MedicineRepository : IMedicineRepository
9 {
10 private FarmatikoDataContext _context;
11 public MedicineRepository(FarmatikoDataContext context)
12 {
13 _context = context;
14 }
15 public void Add(Medicine Medicine)
16 {
17 _context.Medicines.Add(Medicine);
18 _context.SaveChangesAsync();
19 }
20
21 public IQueryable<Medicine> GetAll()
22 {
23 return _context.Medicines.OrderBy(x => x.Name);
24 }
25
26 public IQueryable<Medicine> GetByManufacturer(string Manufacturer)
27 {
28 return _context.Medicines.Where(x => x.Name.Contains(Manufacturer)).OrderBy(x => x.Manufacturer);
29 }
30
31 public IQueryable<Medicine> GetByName(string Name)
32 {
33 return _context.Medicines.Where(medicine => medicine.Name.Contains(Name)).OrderBy(x => x.Name);
34 }
35
36 public void Remove(string medicine)
37 {
38 Medicine med = (Medicine)_context.Medicines.Where(medicine => medicine.Name.Equals(medicine));
39 _context.Medicines.Remove(med);
40 }
41 }
42}
Note: See TracBrowser for help on using the repository browser.