source: FarmatikoData/FarmatikoRepo/MedicineRepository.cs@ de18858

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

Add more services

  • Property mode set to 100644
File size: 1.4 KB
Line 
1using FarmatikoData.FarmatikoRepoInterfaces;
2using FarmatikoData.Models;
3using Microsoft.EntityFrameworkCore;
4using System;
5using System.Collections.Generic;
6using System.Linq;
7using System.Text;
8
9namespace FarmatikoData.FarmatikoRepo
10{
11 public class MedicineRepository : IMedicineRepository
12 {
13 private FarmatikoDataContext _context;
14 public MedicineRepository(FarmatikoDataContext context)
15 {
16 _context = context;
17 }
18 public void Add(Medicine Medicine)
19 {
20 _context.Add(Medicine);
21 _context.SaveChangesAsync();
22 }
23
24 public IEnumerable<Medicine> GetAll()
25 {
26 return _context.Medicines.Include(medicine => medicine.Name).Include(medicine => medicine.Strength).Include(medicine => medicine.Form);
27 }
28
29 public IEnumerable<Medicine> GetByManufacturer(string Manufacturer)
30 {
31 return _context.Medicines.Where(x => x.Name.Contains(Manufacturer)).OrderBy(x => x.Manufacturer);
32 }
33
34 public IEnumerable<Medicine> GetByName(string Name)
35 {
36 return (IEnumerable<Medicine>)_context.Medicines.Where(medicine => medicine.Name == Name);
37 }
38
39 public void Remove(string medicine)
40 {
41 Medicine med = (Medicine)_context.Medicines.Where(medicine => medicine.Name.Equals(medicine));
42 _context.Remove(med);
43 }
44 }
45}
Note: See TracBrowser for help on using the repository browser.