[37c8d1d] | 1 | using FarmatikoData.Models;
|
---|
[a55ef91] | 2 | using Microsoft.EntityFrameworkCore;
|
---|
[37c8d1d] | 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 | }
|
---|
[a55ef91] | 20 | /*public MedicineList CheckMedicine(string Name)
|
---|
[e42f61a] | 21 | {
|
---|
| 22 | return (MedicineList)_context.MedicineLists
|
---|
| 23 | .Where(medicineList => medicineList.Medicine.Name.Contains(Name))
|
---|
[a55ef91] | 24 | .OrderBy(x => x.Medicine.Name)
|
---|
| 25 | .Include(x => x.HasMedicine)
|
---|
| 26 | .Cast<MedicineList>();
|
---|
| 27 | }*/
|
---|
| 28 |
|
---|
| 29 | public IQueryable<MedicineList> GetAll()
|
---|
[37c8d1d] | 30 | {
|
---|
[4e72684] | 31 | return _context.MedicineLists.OrderBy(x => x.Medicine.Name);
|
---|
[37c8d1d] | 32 | }
|
---|
| 33 |
|
---|
[e42f61a] | 34 | public ICollection<MedicineList> GetByManufacturer(string Manufacturer)
|
---|
| 35 | {
|
---|
| 36 | return (ICollection<MedicineList>)_context.MedicineLists
|
---|
| 37 | .Where(x => x.Medicine.Manufacturer.Contains(Manufacturer))
|
---|
[a55ef91] | 38 | .OrderBy(x => x.Medicine.Name)
|
---|
| 39 | .Cast<ICollection<MedicineList>>();
|
---|
[e42f61a] | 40 | }
|
---|
| 41 | public ICollection<MedicineList> GetByName(string Name)
|
---|
[37c8d1d] | 42 | {
|
---|
[e42f61a] | 43 | return (ICollection<MedicineList>)_context.MedicineLists
|
---|
| 44 | .Where(x => x.Medicine.Name.Contains(Name))
|
---|
[a55ef91] | 45 | .OrderBy(x => x.Medicine.Name)
|
---|
| 46 | .Cast<ICollection<MedicineList>>();
|
---|
[37c8d1d] | 47 | }
|
---|
| 48 |
|
---|
| 49 | public void Remove(MedicineList medicineList)
|
---|
| 50 | {
|
---|
[a55ef91] | 51 | var list = (MedicineList)_context.MedicineLists.Where(x => x.Medicine.Equals(medicineList.Medicine));
|
---|
[4e72684] | 52 | _context.MedicineLists.Remove(list);
|
---|
[e42f61a] | 53 | }
|
---|
[37c8d1d] | 54 | }
|
---|
| 55 | }
|
---|