using AutoMapper; using HanyadikHetVan.Data; using HanyadikHetVan.Data.Entities; using HanyadikHetVan.DTO; using Microsoft.EntityFrameworkCore; using System; using System.Linq; using System.Threading.Tasks; namespace HanyadikHetVan.Services { public class FunFactService { private readonly ApplicationDbContext _dbContext; private readonly IMapper _mapper; public FunFactService(ApplicationDbContext dbContext, IMapper mapper) { _dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext)); _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); } public async Task GetFunFactOfWeeklyTimeSpan(int weeklytimespanId) { var funfact = await _dbContext.FunFacts.Where(x => x.WeeklyTimeSpanId == weeklytimespanId).FirstOrDefaultAsync(); return _mapper.Map(funfact); } public async Task GetFunFactorOfFunFact(int funfactId) { var funfact = await _dbContext.FunFacts.Where(x => x.Id == funfactId).FirstOrDefaultAsync(); return funfact.FunFactor; } } }