[37c8d1d] | 1 | using FarmatikoData.Models;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 |
|
---|
| 5 | namespace FarmatikoData.FarmatikoRepo
|
---|
| 6 | {
|
---|
| 7 | public class MedicineListRepository : IMedicineListRepository
|
---|
| 8 | {
|
---|
| 9 | private FarmatikoDataContext _context;
|
---|
| 10 | public MedicineListRepository(FarmatikoDataContext context)
|
---|
| 11 | {
|
---|
| 12 | _context = context;
|
---|
| 13 | }
|
---|
| 14 | public void Add(MedicineList medicineList)
|
---|
| 15 | {
|
---|
| 16 | _context.MedicineLists.Add(medicineList);
|
---|
| 17 | _context.SaveChangesAsync();
|
---|
| 18 | }
|
---|
[4e72684] | 19 | public MedicineList CheckMedicine(string Name)
|
---|
[e42f61a] | 20 | {
|
---|
| 21 | return (MedicineList)_context.MedicineLists
|
---|
| 22 | .Where(medicineList => medicineList.Medicine.Name.Contains(Name))
|
---|
| 23 | .OrderBy(x => x.Medicine.Name);
|
---|
[4e72684] | 24 | }
|
---|
[37c8d1d] | 25 |
|
---|
[4e72684] | 26 | public IEnumerable<MedicineList> GetAll()
|
---|
[37c8d1d] | 27 | {
|
---|
[4e72684] | 28 | return _context.MedicineLists.OrderBy(x => x.Medicine.Name);
|
---|
[37c8d1d] | 29 | }
|
---|
| 30 |
|
---|
[e42f61a] | 31 | public ICollection<MedicineList> GetByManufacturer(string Manufacturer)
|
---|
| 32 | {
|
---|
| 33 | return (ICollection<MedicineList>)_context.MedicineLists
|
---|
| 34 | .Where(x => x.Medicine.Manufacturer.Contains(Manufacturer))
|
---|
| 35 | .OrderBy(x => x.Medicine.Name);
|
---|
| 36 | }
|
---|
| 37 | public ICollection<MedicineList> GetByName(string Name)
|
---|
[37c8d1d] | 38 | {
|
---|
[e42f61a] | 39 | return (ICollection<MedicineList>)_context.MedicineLists
|
---|
| 40 | .Where(x => x.Medicine.Name.Contains(Name))
|
---|
| 41 | .OrderBy(x => x.Medicine.Name);
|
---|
[37c8d1d] | 42 | }
|
---|
| 43 |
|
---|
| 44 | public void Remove(MedicineList medicineList)
|
---|
| 45 | {
|
---|
[e42f61a] | 46 | var list = (MedicineList)_context.MedicineLists.Where(x => x.Equals(medicineList));
|
---|
[4e72684] | 47 | _context.MedicineLists.Remove(list);
|
---|
[e42f61a] | 48 | }
|
---|
| 49 |
|
---|
[4e72684] | 50 | public bool SetHasMedicine(MedicineList medicineList, bool HasMedicine)
|
---|
[e42f61a] | 51 | {
|
---|
[4e72684] | 52 | MedicineList medicine = (MedicineList)_context.MedicineLists.Where(x => x.Medicine.Name.Equals(medicineList.Medicine.Name));
|
---|
| 53 |
|
---|
| 54 | if (medicine != null || medicineList != null)
|
---|
| 55 | {
|
---|
| 56 | if (HasMedicine == true)
|
---|
| 57 | {
|
---|
| 58 | medicine.HasMedicine = HasMedicine;
|
---|
| 59 | _context.MedicineLists.Add(medicine);
|
---|
| 60 | _context.SaveChangesAsync();
|
---|
| 61 | return true;
|
---|
| 62 | }
|
---|
| 63 | else
|
---|
| 64 | {
|
---|
| 65 | medicine.HasMedicine = HasMedicine;
|
---|
| 66 | _context.MedicineLists.Add(medicine);
|
---|
| 67 | _context.SaveChangesAsync();
|
---|
| 68 | return true;
|
---|
| 69 | }
|
---|
| 70 | }else
|
---|
| 71 | {
|
---|
| 72 | return false;
|
---|
| 73 | }
|
---|
[37c8d1d] | 74 | }
|
---|
| 75 | }
|
---|
| 76 | }
|
---|