hanyadikhetvan-dotnethf/HanyadikHetVan/Repository/WeeklyTimeSpanRepository.cs
2021-05-03 16:48:32 +02:00

50 lines
1.4 KiB
C#

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<WeeklyTimeSpan>
{
private ApplicationDbContext _dbContext;
public WeeklyTimeSpanRepository(ApplicationDbContext applicationDbContext)
{
_dbContext = applicationDbContext ?? throw new ArgumentNullException(nameof(applicationDbContext));
}
public async Task<WeeklyTimeSpan> 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<WeeklyTimeSpan> 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();
}
}
}