[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 | {
|
---|
[c406ae5] | 31 | return _context.MedicineLists.Take(50).Select(x => new MedicineList
|
---|
| 32 | {
|
---|
| 33 | Medicine = x.Medicine,
|
---|
| 34 | HasMedicine = x.HasMedicine
|
---|
| 35 | }).OrderBy(x => x.Medicine.Name);
|
---|
[37c8d1d] | 36 | }
|
---|
| 37 |
|
---|
[e42f61a] | 38 | public ICollection<MedicineList> GetByManufacturer(string Manufacturer)
|
---|
| 39 | {
|
---|
[c406ae5] | 40 | return (ICollection<MedicineList>)_context.MedicineLists.Take(50)
|
---|
[e42f61a] | 41 | .Where(x => x.Medicine.Manufacturer.Contains(Manufacturer))
|
---|
[c406ae5] | 42 | .Select(x => new MedicineList
|
---|
| 43 | {
|
---|
| 44 | Medicine = x.Medicine,
|
---|
| 45 | HasMedicine = x.HasMedicine
|
---|
| 46 | })
|
---|
[a55ef91] | 47 | .OrderBy(x => x.Medicine.Name)
|
---|
| 48 | .Cast<ICollection<MedicineList>>();
|
---|
[e42f61a] | 49 | }
|
---|
| 50 | public ICollection<MedicineList> GetByName(string Name)
|
---|
[37c8d1d] | 51 | {
|
---|
[c406ae5] | 52 | return (ICollection<MedicineList>)_context.MedicineLists.Take(50)
|
---|
[e42f61a] | 53 | .Where(x => x.Medicine.Name.Contains(Name))
|
---|
[c406ae5] | 54 | .Select(x => new MedicineList
|
---|
| 55 | {
|
---|
| 56 | Medicine = x.Medicine,
|
---|
| 57 | HasMedicine = x.HasMedicine
|
---|
| 58 | })
|
---|
[a55ef91] | 59 | .OrderBy(x => x.Medicine.Name)
|
---|
| 60 | .Cast<ICollection<MedicineList>>();
|
---|
[37c8d1d] | 61 | }
|
---|
| 62 |
|
---|
| 63 | public void Remove(MedicineList medicineList)
|
---|
| 64 | {
|
---|
[c406ae5] | 65 | var list = _context.MedicineLists.Where(x => x.Medicine.Equals(medicineList.Medicine)).FirstOrDefault();
|
---|
| 66 | if (list != null)
|
---|
| 67 | {
|
---|
| 68 | _context.MedicineLists.Remove(list);
|
---|
| 69 | _context.SaveChangesAsync();
|
---|
| 70 | }
|
---|
[e42f61a] | 71 | }
|
---|
[37c8d1d] | 72 | }
|
---|
| 73 | }
|
---|