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 GetAllPauses() { return _dbContext.Pauses.Include(x => x.WeeklyTimeSpan).ToList(); } public async Task 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; } } } }