public async Task <Unit> Handle(DeleteVacationTypeCommand request, CancellationToken cancellationToken) { var vacationtype = await VacationTypeRepository.Get(request.Id); if (vacationtype == null) { throw new ArgumentOutOfRangeException("Vacation Type does not exist."); } var employees = await EmployeeRepository.Select(); if (employees.Any(e => e.GetVacations(DateTimeOffset.Now.Year).Any(v => v.VacationType.Equals(vacationtype)))) { throw new ArgumentOutOfRangeException("Some employees has active vacations of this type."); } var vacationtypes = await VacationTypeRepository.Select(); foreach (var type in vacationtypes.Where(e => e.Pool != null && e.Pool.Equals(vacationtype))) { type.UpdatePool(vacationtype.Pool, type.RowVersion); await VacationTypeRepository.Update(type); } await VacationTypeRepository.Delete(vacationtype); await Mediator.Publish(new VacationTypeDeletedEvent { Id = vacationtype.Id }); return(await Unit.Task); }
public async Task <Unit> Handle(UpdateVacationTypeCommand request, CancellationToken cancellationToken) { var vacationtype = await VacationTypeRepository.Get(request.Id); if (vacationtype == null) { throw new ArgumentOutOfRangeException("Vacation Type does not exist."); } var pool = await VacationTypeRepository.Get(request.PoolId.GetValueOrDefault(0)); vacationtype.Update(request.Name, request.DefaultLeaveDays, request.IsPassing, pool, Convert.FromBase64String(request.Version)); await VacationTypeRepository.Update(vacationtype); await Mediator.Publish(new VacationTypeUpdatedEvent { Id = vacationtype.Id }); return(await Unit.Task); }
public SelectListItem[] SelectVacationTypes() { var vacationTypes = _vacationTypes.Get().Select(type => new SelectListItem { Text = type.VacationTypeName, Value = type.VacationTypeID }).ToArray(); return(vacationTypes); }
public async Task <int> Handle(InsertVacationTypeCommand request, CancellationToken cancellationToken) { var pool = await VacationTypeRepository.Get(request.PoolId.GetValueOrDefault(0)); var vacationtype = new DonVo.CQRS.Standard21.Domain.Model.Company.VacationType(request.Name, request.DefaultLeaveDays, request.IsPassing, pool); var id = await VacationTypeRepository.Insert(vacationtype); await Mediator.Publish(new VacationTypeInsertedEvent { Id = vacationtype.Id }); return(id); }
public ProfileVacationDTO[] GetUserVacationsData(string id) { var employee = _employees.GetById(id); var vacationStatuses = _vacationStatusTypes.Get(); var vacationTypes = _vacationTypes.Get(); var vacations = _vacations.Get(x => x.EmployeeID.Equals(employee.EmployeeID)).Select(x => new ProfileVacationDTO { VacationType = vacationTypes.FirstOrDefault(y => y.VacationTypeID.Equals(x.VacationTypeID)).VacationTypeName, Comment = x.Comment, DateOfBegin = x.DateOfBegin, DateOfEnd = x.DateOfEnd, Duration = x.Duration, Status = vacationStatuses.FirstOrDefault(y => y.VacationStatusTypeID.Equals(x.VacationStatusTypeID)).VacationStatusName, Created = x.Created }).OrderBy(x => FunctionHelper.VacationSortFunc(x.Status)).ThenBy(x => x.Created).ToArray(); return(vacations); }
public async Task <Unit> Handle(RequestVacationCommand request, CancellationToken cancellationToken) { var employee = await EmployeeRepository.Get(request.EmployeeId); if (employee == null) { throw new ArgumentOutOfRangeException("Employee does not exist."); } var holidays = await HolidayRepository.Select(); var vacationtype = await VacationTypeRepository.Get(request.VacationTypeId); var vacation = employee.InsertVacation(request.Start, request.End, vacationtype, DonVo.CQRS.Standard21.Domain.Model.Company.VacationState.Requested, holidays); await VacationRepository.Insert(vacation); await Mediator.Publish(new VacationRequestedEvent { Id = vacation.Id }); return(await Unit.Task); }