From 8930d4e20d28c7326f7af211b2336c681550a65d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Mon, 3 May 2021 16:48:32 +0200 Subject: [PATCH] add crud --- HanyadikHetVan/Interface/IRepository.cs | 21 ++++++++ HanyadikHetVan/Repository/PauseRepository.cs | 49 +++++++++++++++++++ .../Repository/WeeklyTimeSpanRepository.cs | 49 +++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 HanyadikHetVan/Interface/IRepository.cs create mode 100644 HanyadikHetVan/Repository/PauseRepository.cs create mode 100644 HanyadikHetVan/Repository/WeeklyTimeSpanRepository.cs diff --git a/HanyadikHetVan/Interface/IRepository.cs b/HanyadikHetVan/Interface/IRepository.cs new file mode 100644 index 0000000..fc45c14 --- /dev/null +++ b/HanyadikHetVan/Interface/IRepository.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HanyadikHetVan.Interface +{ + public interface IRepository + { + public Task Create(T _object); + + public void Update(T _object); + + public IEnumerable GetAll(); + + public T GetById(int Id); + + public void Delete(T _object); + + } +} diff --git a/HanyadikHetVan/Repository/PauseRepository.cs b/HanyadikHetVan/Repository/PauseRepository.cs new file mode 100644 index 0000000..53f6ca4 --- /dev/null +++ b/HanyadikHetVan/Repository/PauseRepository.cs @@ -0,0 +1,49 @@ +using HanyadikHetVan.Data; +using HanyadikHetVan.Data.Entities; +using HanyadikHetVan.Interface; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HanyadikHetVan.Repository +{ + public class PauseRepository : IRepository + { + private ApplicationDbContext _dbContext; + + public PauseRepository(ApplicationDbContext applicationDbContext) + { + _dbContext = applicationDbContext ?? throw new ArgumentNullException(nameof(applicationDbContext)); + } + + public async Task Create(Pause _object) + { + var obj = await _dbContext.Pauses.AddAsync(_object); + _dbContext.SaveChanges(); + return obj.Entity; + } + + public void Delete(Pause _object) + { + _dbContext.Remove(_object); + _dbContext.SaveChanges(); + } + + public IEnumerable GetAll() + { + return _dbContext.Pauses.ToList(); + } + + public Pause GetById(int Id) + { + return _dbContext.Pauses.Where(x => x.Id == Id).FirstOrDefault(); + } + + public void Update(Pause _object) + { + _dbContext.Pauses.Update(_object); + _dbContext.SaveChanges(); + } + } +} diff --git a/HanyadikHetVan/Repository/WeeklyTimeSpanRepository.cs b/HanyadikHetVan/Repository/WeeklyTimeSpanRepository.cs new file mode 100644 index 0000000..dcabab9 --- /dev/null +++ b/HanyadikHetVan/Repository/WeeklyTimeSpanRepository.cs @@ -0,0 +1,49 @@ +using HanyadikHetVan.Data; +using HanyadikHetVan.Data.Entities; +using HanyadikHetVan.Interface; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HanyadikHetVan.Repository +{ + public class WeeklyTimeSpanRepository : IRepository + { + private ApplicationDbContext _dbContext; + + public WeeklyTimeSpanRepository(ApplicationDbContext applicationDbContext) + { + _dbContext = applicationDbContext ?? throw new ArgumentNullException(nameof(applicationDbContext)); + } + + public async Task Create(WeeklyTimeSpan _object) + { + var obj = await _dbContext.WeeklyTimeSpans.AddAsync(_object); + _dbContext.SaveChanges(); + return obj.Entity; + } + + public void Delete(WeeklyTimeSpan _object) + { + _dbContext.Remove(_object); + _dbContext.SaveChanges(); + } + + public IEnumerable GetAll() + { + return _dbContext.WeeklyTimeSpans.ToList(); + } + + public WeeklyTimeSpan GetById(int Id) + { + return _dbContext.WeeklyTimeSpans.Where(x => x.Id == Id).FirstOrDefault(); + } + + public void Update(WeeklyTimeSpan _object) + { + _dbContext.WeeklyTimeSpans.Update(_object); + _dbContext.SaveChanges(); + } + } +}