public async Task UpdateAsync(RsvpRepository repository) { var existingInvitation = await repository.GetInvitationByIdAsync(EventId, Id); // Iterate over the existing guests so that we only change the acceptance. // Don't allow new guests to be added or old guests to be removed. existingInvitation.Guests.ForEach(guest => { var matchingGuest = Guests.FirstOrDefault(x => x.Id == guest.Id); guest.Accepted = matchingGuest.Accepted; }); await repository.UpdateInvitationAsync(existingInvitation); }
public InvitationValidator(RsvpRepository repository) { _repository = repository; RuleFor(x => x.EventId).NotEmpty().WithMessage("Event ID is required.").DependentRules(() => { RuleFor(x => x.EventId).MustAsync(async(id, cancellation) => { return(await _repository.GetEventAsync(id) != null); }).WithMessage("Event doesn't exist."); }); RuleFor(x => x.Guests).NotEmpty().WithMessage("Guests are required."); RuleFor(x => x.Email).NotEmpty().When(x => x.Mobile == null).WithMessage("Email or Mobile is required."); RuleFor(x => x.Mobile).NotEmpty().When(x => x.Email == null).WithMessage("Email or Mobile is required."); }
public async Task SaveAsync(RsvpRepository repository) { await repository.CreateEventAsync(this); }
public async Task SaveAsync(RsvpRepository repository) { await repository.CreateInvitationAsync(this); }