source: FarmatikoData/FarmatikoRepo/PandemicRepository.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.3 KB
Line 
1using FarmatikoData.FarmatikoRepoInterfaces;
2using FarmatikoData.Models;
3using System.Linq;
4
5namespace FarmatikoData.FarmatikoRepo
6{
7 public class PandemicRepository : IPandemicRepository
8 {
9 private FarmatikoDataContext _context;
10
11 public PandemicRepository(FarmatikoDataContext context)
12 {
13 _context = context;
14 }
15
16 public void Add(Pandemic pandemic)
17 {
18 _context.Pandemics.Add(pandemic);
19 _context.SaveChangesAsync();
20 }
21
22 public IQueryable<Pandemic> GetAll()
23 {
24 return _context.Pandemics.Select(x => new Pandemic
25 {
26 Name = x.Name,
27 TotalMK = x.TotalMK,
28 ActiveMK = x.ActiveMK,
29 DeathsMK = x.DeathsMK,
30 NewMK = x.NewMK,
31 TotalGlobal = x.TotalGlobal,
32 DeathsGlobal = x.DeathsGlobal,
33 ActiveGlobal = x.ActiveGlobal
34 }).OrderBy(x => x.Name);
35 }
36
37 public void Remove(Pandemic pandemic)
38 {
39 var Pandem = _context.Pandemics.Where(x => x.Name.Equals(pandemic.Name)).FirstOrDefault();
40 if (Pandem != null)
41 {
42 _context.Pandemics.Remove(Pandem);
43 _context.SaveChangesAsync();
44 }
45 }
46 }
47}
Note: See TracBrowser for help on using the repository browser.