hanyadikhetvan-dotnethf/HanyadikHetVan/Services/FunFactService.cs
Torma Kristóf 634488c2d8
All checks were successful
continuous-integration/drone/push Build is passing
addfunfacts
2021-05-19 17:56:56 +02:00

36 lines
1.2 KiB
C#

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<FunFactDTO> GetFunFactOfWeeklyTimeSpan(int weeklytimespanId)
{
var funfact = await _dbContext.FunFacts.Where(x => x.WeeklyTimeSpanId == weeklytimespanId).FirstOrDefaultAsync();
return _mapper.Map<FunFact, FunFactDTO>(funfact);
}
public async Task<double> GetFunFactorOfFunFact(int funfactId)
{
var funfact = await _dbContext.FunFacts.Where(x => x.Id == funfactId).FirstOrDefaultAsync();
return funfact.FunFactor;
}
}
}