source: FarmatikoData/FarmatikoRepo/MedicineListRepository.cs@ 5d02859

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

Update Models, Repos, Services and Controllers

  • Property mode set to 100644
File size: 2.5 KB
Line 
1using FarmatikoData.Models;
2using Microsoft.EntityFrameworkCore;
3using System.Collections.Generic;
4using System.Linq;
5
6namespace 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.Take(50).Select(x => new MedicineList
32 {
33 Medicine = x.Medicine,
34 HasMedicine = x.HasMedicine
35 }).OrderBy(x => x.Medicine.Name);
36 }
37
38 public ICollection<MedicineList> GetByManufacturer(string Manufacturer)
39 {
40 return (ICollection<MedicineList>)_context.MedicineLists.Take(50)
41 .Where(x => x.Medicine.Manufacturer.Contains(Manufacturer))
42 .Select(x => new MedicineList
43 {
44 Medicine = x.Medicine,
45 HasMedicine = x.HasMedicine
46 })
47 .OrderBy(x => x.Medicine.Name)
48 .Cast<ICollection<MedicineList>>();
49 }
50 public ICollection<MedicineList> GetByName(string Name)
51 {
52 return (ICollection<MedicineList>)_context.MedicineLists.Take(50)
53 .Where(x => x.Medicine.Name.Contains(Name))
54 .Select(x => new MedicineList
55 {
56 Medicine = x.Medicine,
57 HasMedicine = x.HasMedicine
58 })
59 .OrderBy(x => x.Medicine.Name)
60 .Cast<ICollection<MedicineList>>();
61 }
62
63 public void Remove(MedicineList medicineList)
64 {
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 }
71 }
72 }
73}
Note: See TracBrowser for help on using the repository browser.