[37c8d1d] | 1 | using FarmatikoData.FarmatikoRepoInterfaces;
|
---|
| 2 | using FarmatikoData.Models;
|
---|
[a55ef91] | 3 | using System;
|
---|
[37c8d1d] | 4 | using System.Linq;
|
---|
| 5 |
|
---|
| 6 | namespace 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 | {
|
---|
[a55ef91] | 17 | _context.Medicines.Add(Medicine);
|
---|
[37c8d1d] | 18 | _context.SaveChangesAsync();
|
---|
| 19 | }
|
---|
| 20 |
|
---|
[a55ef91] | 21 | public IQueryable<Medicine> GetAll()
|
---|
[37c8d1d] | 22 | {
|
---|
[c406ae5] | 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);
|
---|
[37c8d1d] | 33 | }
|
---|
| 34 |
|
---|
[a55ef91] | 35 | public IQueryable<Medicine> GetByManufacturer(string Manufacturer)
|
---|
[37c8d1d] | 36 | {
|
---|
[c406ae5] | 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);
|
---|
[e42f61a] | 48 | }
|
---|
| 49 |
|
---|
[a55ef91] | 50 | public IQueryable<Medicine> GetByName(string Name)
|
---|
[e42f61a] | 51 | {
|
---|
[c406ae5] | 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);
|
---|
[37c8d1d] | 63 | }
|
---|
| 64 |
|
---|
[c406ae5] | 65 | public void Remove(Medicine medicine)
|
---|
[37c8d1d] | 66 | {
|
---|
[c406ae5] | 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 |
|
---|
[37c8d1d] | 74 | }
|
---|
| 75 | }
|
---|
| 76 | }
|
---|