public async Task ValidateNewHolidayConfirmationReadiness(NewHolidayDto holidayDto) { if (holidayDto == null) { throw new ArgumentNullException(nameof(holidayDto)); } var holiday = _mapper.Map <Holiday>(holidayDto); await ValidateHoliday(holiday); }
public async void When_CreatingHoliday_Expect_ReturnsCreatedHoliday(int employeeId) { var newHoliday = new NewHolidayDto() { EmployeeId = employeeId, Type = HolidayType.DayForChildren, FromInclusive = new DateTime(2019, 10, 24), ToInclusive = new DateTime(2019, 10, 27), }; var createdHolidayId = await _holidaysService.Create(newHoliday); var createdHoliday = _context.Holidays.Find(createdHolidayId); Assert.True(createdHolidayId > -1 && createdHoliday != null); }
public async Task <IActionResult> RequestConfirmationFromClient(NewHolidayDto newHolidayDto) { try { await _holidayValidationService.ValidateNewHolidayConfirmationReadiness(newHolidayDto); var holidayId = await _holidaysService.Create(newHolidayDto); await _confirmationService.RequestClientApproval(holidayId); } catch (InvalidOperationException exception) { return(BadRequest(exception.Message)); } return(Ok()); }
public async Task <int> Create(NewHolidayDto newHolidayDto) { if (newHolidayDto == null) { throw new ArgumentNullException(); } var newHoliday = _mapper.Map <Holiday>(newHolidayDto); newHoliday.RequestCreatedDate = _timeService.GetCurrentTime(); newHoliday.Status = HolidayStatus.Pending; var holidayId = await _holidaysRepository.Create(newHoliday); var employee = await _employeeRepository.GetById(newHoliday.EmployeeId); if (employee.ClientId > 0) { var newHolidayGuid = new HolidayGuid() { IsAdmin = false, ConfirmerId = employee.ClientId, HolidayId = holidayId, Guid = Guid.NewGuid().ToString() }; await _holidayGuidsRepository.Create(newHolidayGuid); } var allAdmins = await _employeeRepository.GetAllAdmins(); foreach (var admin in allAdmins) { var newHolidayGuid = new HolidayGuid() { IsAdmin = true, ConfirmerId = admin.Id, HolidayId = holidayId, Guid = Guid.NewGuid().ToString() }; await _holidayGuidsRepository.Create(newHolidayGuid); } return(holidayId); }