1 | using FarmatikoData.Models;
|
---|
2 | using Microsoft.EntityFrameworkCore;
|
---|
3 | using System.Collections.Generic;
|
---|
4 | using System.Linq;
|
---|
5 |
|
---|
6 | namespace FarmatikoData.FarmatikoRepo
|
---|
7 | {
|
---|
8 | public class MedicineListRepository : IMedicineListRepository
|
---|
9 | {
|
---|
10 | private FarmatikoDataContext _context;
|
---|
11 | public MedicineListRepository(FarmatikoDataContext context)
|
---|
12 | {
|
---|
13 | _context = context;
|
---|
14 | }
|
---|
15 | public void Add(MedicineList medicineList)
|
---|
16 | {
|
---|
17 | _context.MedicineLists.Add(medicineList);
|
---|
18 | _context.SaveChangesAsync();
|
---|
19 | }
|
---|
20 | /*public MedicineList CheckMedicine(string Name)
|
---|
21 | {
|
---|
22 | return (MedicineList)_context.MedicineLists
|
---|
23 | .Where(medicineList => medicineList.Medicine.Name.Contains(Name))
|
---|
24 | .OrderBy(x => x.Medicine.Name)
|
---|
25 | .Include(x => x.HasMedicine)
|
---|
26 | .Cast<MedicineList>();
|
---|
27 | }*/
|
---|
28 |
|
---|
29 | public IQueryable<MedicineList> GetAll()
|
---|
30 | {
|
---|
31 | return _context.MedicineLists.OrderBy(x => x.Medicine.Name);
|
---|
32 | }
|
---|
33 |
|
---|
34 | public ICollection<MedicineList> GetByManufacturer(string Manufacturer)
|
---|
35 | {
|
---|
36 | return (ICollection<MedicineList>)_context.MedicineLists
|
---|
37 | .Where(x => x.Medicine.Manufacturer.Contains(Manufacturer))
|
---|
38 | .OrderBy(x => x.Medicine.Name)
|
---|
39 | .Cast<ICollection<MedicineList>>();
|
---|
40 | }
|
---|
41 | public ICollection<MedicineList> GetByName(string Name)
|
---|
42 | {
|
---|
43 | return (ICollection<MedicineList>)_context.MedicineLists
|
---|
44 | .Where(x => x.Medicine.Name.Contains(Name))
|
---|
45 | .OrderBy(x => x.Medicine.Name)
|
---|
46 | .Cast<ICollection<MedicineList>>();
|
---|
47 | }
|
---|
48 |
|
---|
49 | public void Remove(MedicineList medicineList)
|
---|
50 | {
|
---|
51 | var list = (MedicineList)_context.MedicineLists.Where(x => x.Medicine.Equals(medicineList.Medicine));
|
---|
52 | _context.MedicineLists.Remove(list);
|
---|
53 | }
|
---|
54 | }
|
---|
55 | }
|
---|