source: FarmatikoData/FarmatikoRepo/MedicineRepository.cs@ c406ae5

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

Update Models, Repos, Services and Controllers

  • Property mode set to 100644
File size: 2.4 KB
Line 
1using FarmatikoData.FarmatikoRepoInterfaces;
2using FarmatikoData.Models;
3using System;
4using System.Linq;
5
6namespace FarmatikoData.FarmatikoRepo
7{
8 public class MedicineRepository : IMedicineRepository
9 {
10 private FarmatikoDataContext _context;
11 public MedicineRepository(FarmatikoDataContext context)
12 {
13 _context = context;
14 }
15 public void Add(Medicine Medicine)
16 {
17 _context.Medicines.Add(Medicine);
18 _context.SaveChangesAsync();
19 }
20
21 public IQueryable<Medicine> GetAll()
22 {
23 return _context.Medicines.Take(50).Select(x => new Medicine
24 {
25 Name = x.Name,
26 Strength = x.Strength,
27 Form = x.Form,
28 WayOfIssuing = x.WayOfIssuing,
29 Manufacturer = x.Manufacturer,
30 Price = x.Price,
31 Packaging = x.Packaging
32 }).OrderBy(x => x.Name);
33 }
34
35 public IQueryable<Medicine> GetByManufacturer(string Manufacturer)
36 {
37 return _context.Medicines.Take(50).Where(x => x.Name.Contains(Manufacturer))
38 .Select(x => new Medicine
39 {
40 Name = x.Name,
41 Strength = x.Strength,
42 Form = x.Form,
43 WayOfIssuing = x.WayOfIssuing,
44 Manufacturer = x.Manufacturer,
45 Price = x.Price,
46 Packaging = x.Packaging
47 }).OrderBy(x => x.Manufacturer);
48 }
49
50 public IQueryable<Medicine> GetByName(string Name)
51 {
52 return _context.Medicines.Take(50).Where(medicine => medicine.Name.Contains(Name))
53 .Select(x => new Medicine
54 {
55 Name = x.Name,
56 Strength = x.Strength,
57 Form = x.Form,
58 WayOfIssuing = x.WayOfIssuing,
59 Manufacturer = x.Manufacturer,
60 Price = x.Price,
61 Packaging = x.Packaging
62 }).OrderBy(x => x.Name);
63 }
64
65 public void Remove(Medicine medicine)
66 {
67 Medicine med = _context.Medicines.Where(medicine => medicine.Name.Equals(medicine.Name)).FirstOrDefault();
68 if (med != null)
69 {
70 _context.Medicines.Remove(med);
71 _context.SaveChangesAsync();
72 }
73
74 }
75 }
76}
Note: See TracBrowser for help on using the repository browser.