hanyadikhetvan-dotnethf/HanyadikHetVan/Services/PauseService.cs
Torma Kristóf 0bba2d2faf
Some checks failed
continuous-integration/drone/push Build is failing
refactor db access
2021-05-18 00:53:29 +02:00

66 lines
1.7 KiB
C#

using HanyadikHetVan.Data;
using HanyadikHetVan.Data.Entities;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace HanyadikHetVan.Services
{
public class PauseService
{
private readonly ApplicationDbContext _dbContext;
public PauseService(ApplicationDbContext dbContext)
{
_dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
}
public IEnumerable<Pause> GetAllPauses()
{
return _dbContext.Pauses.Include(x => x.WeeklyTimeSpan).ToList();
}
public async Task<Pause> AddPause(Pause pause)
{
var obj = await _dbContext.Pauses.AddAsync(pause);
_dbContext.SaveChanges();
return obj.Entity;
}
public bool DeletePause(int pauseId)
{
try
{
var item = _dbContext.Pauses.Where(x => x.Id == pauseId).FirstOrDefault();
_dbContext.Pauses.Remove(item);
_dbContext.SaveChanges();
return true;
}
catch (Exception)
{
return false;
}
}
public bool UpdatePause(Pause pause)
{
try
{
var DataList = _dbContext.Pauses.ToList();
foreach (var item in DataList)
{
_dbContext.Pauses.Update(item);
_dbContext.SaveChanges();
}
return true;
}
catch (Exception)
{
return true;
}
}
}
}