source: FarmatikoData/FarmatikoRepo/MedicineListRepository.cs@ 4e72684

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

Add services

  • Property mode set to 100644
File size: 2.6 KB
Line 
1using FarmatikoData.Models;
2using System.Collections.Generic;
3using System.Linq;
4
5namespace 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 }
19 public MedicineList CheckMedicine(string Name)
20 {
21 return (MedicineList)_context.MedicineLists
22 .Where(medicineList => medicineList.Medicine.Name.Contains(Name))
23 .OrderBy(x => x.Medicine.Name);
24 }
25
26 public IEnumerable<MedicineList> GetAll()
27 {
28 return _context.MedicineLists.OrderBy(x => x.Medicine.Name);
29 }
30
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)
38 {
39 return (ICollection<MedicineList>)_context.MedicineLists
40 .Where(x => x.Medicine.Name.Contains(Name))
41 .OrderBy(x => x.Medicine.Name);
42 }
43
44 public void Remove(MedicineList medicineList)
45 {
46 var list = (MedicineList)_context.MedicineLists.Where(x => x.Equals(medicineList));
47 _context.MedicineLists.Remove(list);
48 }
49
50 public bool SetHasMedicine(MedicineList medicineList, bool HasMedicine)
51 {
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 }
74 }
75 }
76}
Note: See TracBrowser for help on using the repository browser.