2021-05-19 04:33:53 +02:00
|
|
|
|
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 HanyadikHetVanEntityService
|
|
|
|
|
{
|
|
|
|
|
private readonly ApplicationDbContext _dbContext;
|
|
|
|
|
private readonly IMapper _mapper;
|
|
|
|
|
|
|
|
|
|
public HanyadikHetVanEntityService(ApplicationDbContext dbContext, IMapper mapper)
|
|
|
|
|
{
|
|
|
|
|
_dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
|
|
|
|
|
_mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<int> GetDefaultWeek()
|
|
|
|
|
{
|
2021-05-19 19:39:46 +02:00
|
|
|
|
var latest = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).OrderBy(x => x.Id).LastAsync();
|
2021-05-19 04:33:53 +02:00
|
|
|
|
var latestDto = _mapper.Map<WeeklyTimeSpan, WeeklyTimeSpanDTO>(latest);
|
|
|
|
|
return latestDto.CurrentWeek;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-19 17:56:56 +02:00
|
|
|
|
public async Task<int> GetUserDefaultWeek(string userId)
|
|
|
|
|
{
|
2021-05-19 19:39:46 +02:00
|
|
|
|
var latest = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Where(x => x.UserId == userId).OrderBy(x => x.Id).LastAsync();
|
2021-05-19 17:56:56 +02:00
|
|
|
|
var latestDto = _mapper.Map<WeeklyTimeSpan, WeeklyTimeSpanDTO>(latest);
|
|
|
|
|
return latestDto.CurrentWeek;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-19 04:33:53 +02:00
|
|
|
|
public async Task<int> GetWeekById(int weeklytimespanId)
|
|
|
|
|
{
|
|
|
|
|
var wts = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Where(x => x.Id == weeklytimespanId).FirstOrDefaultAsync();
|
|
|
|
|
var wtsDto = _mapper.Map<WeeklyTimeSpan, WeeklyTimeSpanDTO>(wts);
|
|
|
|
|
return wtsDto.CurrentWeek;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|