84 lines
2.6 KiB
C#
84 lines
2.6 KiB
C#
using AutoMapper;
|
|
using AutoMapper.QueryableExtensions;
|
|
using IRaCIS.Application.Interfaces;
|
|
using IRaCIS.Application.ViewModels;
|
|
using IRaCIS.Core.Application.Contracts.RequestAndResponse;
|
|
using System;
|
|
using System.Linq;
|
|
using IRaCIS.Core.Domain.Interfaces;
|
|
using IRaCIS.Core.Domain.Models;
|
|
|
|
namespace IRaCIS.Application.Services
|
|
{
|
|
|
|
public class VacationService : IVacationService
|
|
{
|
|
private readonly IVacationRepository _vacationRepository;
|
|
private readonly IMapper _mapper;
|
|
|
|
public VacationService(IVacationRepository vacationRepository,IMapper mapper)
|
|
{
|
|
_vacationRepository = vacationRepository;
|
|
_mapper = mapper;
|
|
}
|
|
public IResponseOutput AddOrUpdateVacation(VacationCommand param)
|
|
{
|
|
if (param.Id == Guid.Empty|| param.Id ==null)
|
|
{
|
|
var result = _vacationRepository.Add(_mapper.Map<Vacation>(param));
|
|
|
|
var success = _vacationRepository.SaveChanges();
|
|
|
|
return ResponseOutput.Result(success, result.Id);
|
|
|
|
}
|
|
else
|
|
{
|
|
var success = _vacationRepository.Update(u => u.Id == param.Id,
|
|
h => new Vacation
|
|
{
|
|
StartDate = param.StartDate,
|
|
EndDate = param.EndDate
|
|
});
|
|
|
|
return ResponseOutput.Result(success);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public IResponseOutput DeleteVacation(Guid holidayId)
|
|
{
|
|
var success = _vacationRepository.Delete(u => u.Id == holidayId);
|
|
|
|
return ResponseOutput.Result(success);
|
|
|
|
}
|
|
|
|
public PageOutput<VacationCommand> GetVacationList(Guid doctorId, int pageIndex, int pageSize)
|
|
{
|
|
var result = _vacationRepository.Find(u => u.DoctorId == doctorId).ProjectTo<VacationCommand>(_mapper.ConfigurationProvider)
|
|
.OrderBy(o => o.StartDate).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
|
|
|
|
var data = new PageOutput<VacationCommand>()
|
|
{
|
|
PageIndex = pageIndex,
|
|
PageSize = pageSize,
|
|
CurrentPageData = result,
|
|
TotalCount = _vacationRepository.GetCount(u => u.DoctorId == doctorId)
|
|
};
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
public IResponseOutput OnVacation(Guid doctorId)
|
|
{
|
|
var count = _vacationRepository.GetCount(u => u.DoctorId == doctorId && u.EndDate >= DateTime.Now && u.StartDate <= DateTime.Now);
|
|
|
|
return ResponseOutput.Result(count > 0);
|
|
}
|
|
|
|
}
|
|
}
|