public Validator(NodaTime.IClock clock) { RuleFor(x => x.StartDateTime.ToInstant()) .LessThanOrEqualTo(x => x.EndDateTime.ToInstant()) .WithMessage(ErrorMessages.StartDateCannotBeGreaterThanEndDate) .WithName(nameof(StartDateTime)); RuleFor(x => x.StartDateTime.ToInstant()) .GreaterThan(x => clock.GetCurrentInstant()) .WithMessage(ErrorMessages.StartDateMustBeInTheFuture) .WithName(nameof(StartDateTime)); }
public async Task <Result <Nothing, Error> > Handle(RecordRefusedTrainingInvitation.Command request, CancellationToken cancellationToken) { var user = await _userAccessor.GetUser(); var enrollment = await _aggregateStore.LoadAsync <EnrollmentAggregate, EnrollmentId>(EnrollmentId.With(request.EnrollmentId), cancellationToken); var preferredTrainings = await _trainingRepository.GetByIds(enrollment.PreferredTrainingIds); var result = await _aggregateStore.Update <EnrollmentAggregate, EnrollmentId, Result <Nothing, Error> >( EnrollmentId.With(request.EnrollmentId), CommandId.New, (aggregate) => aggregate.RecordCandidateRefusedTrainingInvitation(request, user, preferredTrainings, _clock.GetCurrentInstant()), cancellationToken); return(result.Unwrap()); }
public async Task <Result <Nothing, Error> > Handle(RecordAcceptedTrainingInvitation.Command request, CancellationToken cancellationToken) { var user = await _userAccessor.GetUser(); var enrollmentId = EnrollmentId.With(request.EnrollmentId); var enrollmentReadModel = _enrollmentRepo.Query() .SingleOrDefault(x => x.Id == enrollmentId); if (enrollmentReadModel == null) { return(Result.Failure <Nothing, Error>(new Error.ResourceNotFound())); } var preferredTrainings = await _trainingRepository.GetByIds(enrollmentReadModel.PreferredTrainings.Select(x => x.ID).ToArray()); var result = await _aggregateStore.Update <EnrollmentAggregate, EnrollmentId, Result <Nothing, Error> >( enrollmentId, CommandId.New, (aggregate) => aggregate.RecordCandidateAcceptedTrainingInvitation(request, user, preferredTrainings, _clock.GetCurrentInstant()), cancellationToken); if (result.Unwrap().IsSuccess) { var selectedTraining = preferredTrainings.Single(x => x.ID == request.SelectedTrainingID); _backgroundJobClient.Schedule(() => _engine.Execute( new SendTrainingReminder.Command() { EnrollmentId = request.EnrollmentId, TrainingId = request.SelectedTrainingID }), selectedTraining.StartDateTime.Minus(NodaTime.Duration.FromHours(24)).ToDateTimeOffset()); } return(result.Unwrap()); }
public async Task <ClaimsPrincipal> CreateAsync(ApplicationUser user) { var principal = await _baseImpl.CreateAsync(user); if (user.EmailConfirmed == false) { return(principal); } var email = EmailAddress.Parse(user.Email); var submissions = _enrollmentRepo.Query().Where(x => x.Email == email); var filteredSubmissions = submissions .Where(x => x.Email.ToString().ToLowerInvariant() == user.Email.ToLowerInvariant()) .ToArray(); if (filteredSubmissions.None()) { return(principal); } var latestSubmission = filteredSubmissions.OrderByDescending(x => x.Timestamp).First(); var campaign = await _campaignRepo.GetById(latestSubmission.Campaign.Id); var edition = await _editionProvider.GetEdition(campaign.EditionId); if (edition.HasNoValue) { throw new ApplicationException($"Niespójność danych: nie znaleziono edycji o ID={campaign.EditionId} dla kampanii o ID={campaign.Id}"); } if (new NodaTime.Interval(edition.Value.StartDateTime, edition.Value.EndDateTime).Contains(_clock.GetCurrentInstant()) == false) { return(principal); } principal.AddIdentity(new ClaimsIdentity(new[] { new Claim(SharedKernel.ClaimTypes.Candidate, latestSubmission.Id.GetGuid().ToString()) })); return(principal); }