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:
1.5 KB
|
Rev | Line | |
---|
[37c8d1d] | 1 | using FarmatikoData.FarmatikoRepoInterfaces;
|
---|
| 2 | using System.Linq;
|
---|
| 3 | using FarmatikoData.Models;
|
---|
| 4 |
|
---|
| 5 | namespace FarmatikoData.FarmatikoRepo
|
---|
| 6 | {
|
---|
| 7 | public class HealthFacilityRepository : IHealthFacilityRepository
|
---|
| 8 | {
|
---|
| 9 | private FarmatikoDataContext _context;
|
---|
| 10 |
|
---|
| 11 | public HealthFacilityRepository(FarmatikoDataContext context)
|
---|
| 12 | {
|
---|
| 13 | _context = context;
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | public void Add(HealthFacilities healthFacility)
|
---|
| 17 | {
|
---|
[c406ae5] | 18 | _context.HealthFacilities.Add(healthFacility);
|
---|
| 19 | _context.SaveChangesAsync();
|
---|
[37c8d1d] | 20 | }
|
---|
| 21 |
|
---|
[a55ef91] | 22 | public IQueryable<HealthFacilities> GetAll()
|
---|
[37c8d1d] | 23 | {
|
---|
[c406ae5] | 24 | return _context.HealthFacilities.Take(50).Select(x => new HealthFacilities
|
---|
| 25 | {
|
---|
| 26 | Name = x.Name,
|
---|
| 27 | Municipality = x.Municipality,
|
---|
| 28 | Address = x.Address,
|
---|
| 29 | Type = x.Type,
|
---|
| 30 | Email = x.Email,
|
---|
| 31 | Phone = x.Phone
|
---|
| 32 | }).OrderBy(x => x.Name);
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | public IQueryable<HealthFacilities> GetByName(string Name)
|
---|
| 36 | {
|
---|
| 37 | return _context.HealthFacilities.Where(x => x.Name.Equals(Name));
|
---|
[37c8d1d] | 38 | }
|
---|
| 39 |
|
---|
[a55ef91] | 40 | public void Remove(HealthFacilities healthFacility)
|
---|
| 41 | {
|
---|
[c406ae5] | 42 | var facility = _context.HealthFacilities.Where(x => x.Name.Equals(healthFacility.Name)).FirstOrDefault();
|
---|
| 43 | if (facility != null)
|
---|
| 44 | {
|
---|
| 45 | _context.HealthFacilities.Remove(facility);
|
---|
| 46 | _context.SaveChangesAsync();
|
---|
| 47 | }
|
---|
| 48 |
|
---|
[a55ef91] | 49 | }
|
---|
[37c8d1d] | 50 | }
|
---|
| 51 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.