source: FarmatikoData/FarmatikoRepo/MedicineListRepository.cs@ a55ef91

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

Update & add service

  • Property mode set to 100644
File size: 1.9 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.OrderBy(x => x.Medicine.Name);
32 }
33
34 public ICollection<MedicineList> GetByManufacturer(string Manufacturer)
35 {
36 return (ICollection<MedicineList>)_context.MedicineLists
37 .Where(x => x.Medicine.Manufacturer.Contains(Manufacturer))
38 .OrderBy(x => x.Medicine.Name)
39 .Cast<ICollection<MedicineList>>();
40 }
41 public ICollection<MedicineList> GetByName(string Name)
42 {
43 return (ICollection<MedicineList>)_context.MedicineLists
44 .Where(x => x.Medicine.Name.Contains(Name))
45 .OrderBy(x => x.Medicine.Name)
46 .Cast<ICollection<MedicineList>>();
47 }
48
49 public void Remove(MedicineList medicineList)
50 {
51 var list = (MedicineList)_context.MedicineLists.Where(x => x.Medicine.Equals(medicineList.Medicine));
52 _context.MedicineLists.Remove(list);
53 }
54 }
55}
Note: See TracBrowser for help on using the repository browser.