public async Task <Vacation> AddVacation(Vacation vacation) { try { if (await _сonnectedStateService.IsServiceAvailable()) { await Synchronization(); vacation.IsSynchroniz = true; vacation.SynchronizStatusId = Synchroniz; await _vacationWebService.CreateVacation(vacation); return(await _vacationRepository.Add(vacation)); } vacation.IsSynchroniz = false; vacation.SynchronizStatusId = Add; return(await _vacationRepository.Add(vacation)); } catch (VTSException e) { throw new BusinessException("Can't add vacation", e); } }
public void CreateVacation(VacationDTO vacation) { using (TransactionScope scope = new TransactionScope()) { _vacations.Add(Mapper.Map <VacationDTO, Vacation>(vacation)); var employee = _employees.GetById(vacation.EmployeeID); if (employee.EmployeesTeam.Count > 0) { var team = employee.EmployeesTeam.First(); var teamLead = _employees.GetById(team.TeamLeadID); _emailService.SendAsync(teamLead.WorkEmail, $"{teamLead.Name} {teamLead.Surname}", "Vacation request.", "Employee has requested a vacation.", $"{teamLead.Name} {teamLead.Surname}, your employee, {employee.Name} {teamLead.Surname}, has requested a vacation from {vacation.DateOfBegin.ToString("dd-MM-yyyy")} to {vacation.DateOfEnd.ToString("dd-MM-yyyy")}. Please, check it."); } scope.Complete(); } }
public void Create(VacationDTO vacation) { _vacationRepository.Add(Mapper.Map <VacationDTO, Vacation>(vacation)); }