public IHttpActionResult CancelVacation(GeneralIdModel model) { var vacation = VacationRepository.First(x => x.Id == model.Id); var employee = EmployeeRepository.First(x => x.Id == CurrentUser.Id); employee.VacationDays += vacation.Days; vacation.Status = VacationStatus.Declined; EmployeeRepository.SaveOrUpdate(employee); VacationRepository.SaveOrUpdate(vacation); EmployeeRepository.Commit(); VacationRepository.Commit(); return(Ok()); }
public IHttpActionResult DeleteVacation(GeneralIdModel model) { var vacation = VacationRepository.First(x => x.Id == model.Id); var employee = EmployeeRepository.First(x => x.Id == vacation.Employee.Id); employee.VacationDays += vacation.Days; vacation.Status = VacationStatus.Declined; EmployeeRepository.SaveOrUpdate(employee); VacationRepository.SaveOrUpdate(vacation); var emails = EmployeeRepository.Where(x => x.VacationMessages == true && x.Id == vacation.EmployeeId).Select(x => x.Email).ToList(); EmailService.VacationDenied(vacation, emails); ContextManager.Commit(); return(Ok()); }
public IHttpActionResult ModifyVacation(VacationModel model) { if (model.End < model.Start) { return(BadRequest()); } var vacation = VacationRepository.First(x => x.Id == model.Id); var employee = vacation.Employee; var tempDays = vacation.Days; vacation.StartDate = model.Start; vacation.EndDate = model.End; vacation.Days = (int)model.End.Subtract(model.Start).TotalDays + 1; tempDays -= vacation.Days; if (employee.VacationDays - tempDays < 0) { return(BadRequest()); } employee.VacationDays += tempDays; EmployeeRepository.SaveOrUpdate(employee); EmployeeRepository.Commit(); VacationRepository.SaveOrUpdate(vacation); VacationRepository.Commit(); var emails = EmployeeRepository.Where(x => x.VacationMessages == true && x.Id == vacation.EmployeeId).Select(x => x.Email).ToList(); EmailService.VacationModified(vacation, emails); return(Ok()); }