hanyadikhetvan-dotnethf/HanyadikHetVan/Services/FunFactService.cs
Torma Kristóf beab15a7ef
All checks were successful
continuous-integration/drone/push Build is passing
everything works now
2021-05-19 23:14:57 +02:00

37 lines
1.2 KiB
C#

using AutoMapper;
using HanyadikHetVan.Data;
using HanyadikHetVan.Data.Entities;
using HanyadikHetVan.DTO;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
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<List<FunFactDTO>> GetFunFactOfWeeklyTimeSpan(int weeklytimespanId)
{
var funfact = await _dbContext.FunFacts.Where(x => x.WeeklyTimeSpanId == weeklytimespanId).ToListAsync();
return _mapper.Map<List<FunFact>, List<FunFactDTO>>(funfact);
}
public async Task<double> GetFunFactorOfFunFact(int funfactId)
{
var funfact = await _dbContext.FunFacts.Where(x => x.Id == funfactId).FirstOrDefaultAsync();
return funfact.FunFactor;
}
}
}