64 lines
1.9 KiB
C#
64 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace EmployeeManagmentBusinessLogic.BusinessLogic
|
|
{
|
|
public class VacationLogic : IVacationLogic
|
|
{
|
|
private readonly IVacationStorage _vacationStorage;
|
|
|
|
public VacationLogic(IVacationStorage vacationStorage)
|
|
{
|
|
_vacationStorage = vacationStorage;
|
|
}
|
|
|
|
public List<VacationViewModel> GetVacations(VacationSearchModel model)
|
|
{
|
|
return _vacationStorage.GetFilteredList(model).Select(v => new VacationViewModel
|
|
{
|
|
Id = v.Id,
|
|
StartData = v.StartData,
|
|
EndData = v.EndData,
|
|
Passed = v.Passed,
|
|
EmployeeName = v.Employee.NameJob
|
|
}).ToList();
|
|
}
|
|
|
|
public void CreateOrUpdate(VacationBindingModel model)
|
|
{
|
|
if (model.Id.HasValue)
|
|
{
|
|
var existingVacation = _vacationStorage.GetElement(model.Id.Value);
|
|
if (existingVacation == null)
|
|
throw new Exception("Отпуск не найден");
|
|
|
|
existingVacation.StartData = model.StartData;
|
|
existingVacation.EndData = model.EndData;
|
|
existingVacation.Passed = model.Passed;
|
|
existingVacation.EmployeeId = model.EmployeeId;
|
|
|
|
_vacationStorage.Update(existingVacation);
|
|
}
|
|
else
|
|
{
|
|
var newVacation = new Vacation
|
|
{
|
|
StartData = model.StartData,
|
|
EndData = model.EndData,
|
|
Passed = model.Passed,
|
|
EmployeeId = model.EmployeeId
|
|
};
|
|
_vacationStorage.Insert(newVacation);
|
|
}
|
|
}
|
|
|
|
public void Delete(int id)
|
|
{
|
|
_vacationStorage.Delete(id);
|
|
}
|
|
}
|
|
}
|