source: FarmatikoData/FarmatikoRepo/MedicineListRepository.cs@ d8fafb8

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

Update & add service

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