using EmployeeManagmentContracts.BindingModels; using EmployeeManagmentContracts.BusinessLogicContracts; using EmployeeManagmentContracts.SearchModels; using EmployeeManagmentContracts.StoragesContracts; using EmployeeManagmentContracts.ViewModels; namespace EmployeeManagmentBusinessLogic.BusinessLogic { public class VacationLogic : IVacationLogic { private readonly IVacationStorage _vacationStorage; public VacationLogic(IVacationStorage vacationStorage) { _vacationStorage = vacationStorage; } public List 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); } } }