source: FarmatikoData/FarmatikoRepo/HealthFacilityRepository.cs@ c406ae5

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

Update Models, Repos, Services and Controllers

  • Property mode set to 100644
File size: 1.5 KB
Line 
1using FarmatikoData.FarmatikoRepoInterfaces;
2using System.Linq;
3using FarmatikoData.Models;
4
5namespace 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 {
18 _context.HealthFacilities.Add(healthFacility);
19 _context.SaveChangesAsync();
20 }
21
22 public IQueryable<HealthFacilities> GetAll()
23 {
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));
38 }
39
40 public void Remove(HealthFacilities healthFacility)
41 {
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
49 }
50 }
51}
Note: See TracBrowser for help on using the repository browser.