public async Task <Event> SignUpForFreeEvent(Guid eventId, [CurrentUserGlobalState] CurrentUser currentUser) { var price = await _service.CalculateEventPriceForUserAsync(eventId, currentUser); if (price == null || price > 1) { throw new QueryException(ErrorBuilder.New() .SetMessage("Event is not free") .SetCode("ID_UNKNOWN") .Build()); } else { var e = new SignUpEventSuccessEvent() { UserId = currentUser.UserId, EventId = eventId }; await _eventService.SaveEventAndDbContextChangesAsync(e); await _eventService.PublishEventAsync(e); } return(await _context.Events.FindAsync(eventId)); }
public async Task Consume_MultipleSignUpEventSuccessEvent_CreatesOneCodeForUsers() { var @event = new SignUpEventSuccessEvent() { EventId = Guid.NewGuid(), UserId = Guid.NewGuid() }; var @event2 = new SignUpEventSuccessEvent() { EventId = Guid.NewGuid(), UserId = Guid.NewGuid() }; await SendEvent(@event); await SendEvent(@event2); using (var context = _factory.CreateContext()) { Assert.That(context.EventVerifications.Count(), Is.EqualTo(2)); var memberDb = context.EventVerifications.Single(ev => ev.EventId == @event.EventId && ev.UserId == @event.UserId); Assert.That(memberDb, Is.Not.Null); Assert.That(memberDb.EventVerificationId, Is.EqualTo(1)); var memberDb2 = context.EventVerifications.Single(ev => ev.EventId == @event2.EventId && ev.UserId == @event2.UserId); Assert.That(memberDb2, Is.Not.Null); Assert.That(memberDb2.EventVerificationId, Is.EqualTo(2)); } }
public async Task <EventParticipant> SignUpFreeEventAsync(Guid eventId, [CurrentUserGlobalState] CurrentUser currentUser) { var e = await _context.Events .Include(e => e.EventPrices) .SingleOrThrowAsync(e => e.EventId == eventId); var userSub = currentUser.GetSubscriptionIn(e.ClubId); if (!userSub.HasValue && e.PublicPrice != null) { throw new QueryException( ErrorBuilder.New() .SetMessage("The event is private") .SetCode("USER_NOT_MEMBER") .Build()); } if (userSub == null) { userSub = Guid.Empty; } var userPrice = e.EventPrices.Find(ep => ep.ClubSubscriptionId == userSub.Value); if (userPrice == null) { throw new QueryException( ErrorBuilder.New() .SetMessage("Price is not configured so you cannot join") .SetCode("USER_CANNOT_JOIN") .Build()); } if (Math.Abs(userPrice.Price) < 1) { var ep = new EventParticipant() { EventId = eventId, UserId = currentUser.UserId }; _context.EventParticipants.Add(ep); var @event = new SignUpEventSuccessEvent() { UserId = currentUser.UserId, EventId = eventId }; await _eventService.SaveEventAndDbContextChangesAsync(@event); await _eventService.PublishEventAsync(@event); return(ep); } else { throw new QueryException( ErrorBuilder.New() .SetMessage("Event is not free for your membership type.") .SetCode("EVENT_IS_NOT_FREE") .Build()); } }
public async Task Consume_UserAlreadySignedUp_Ignores() { var @event = new SignUpEventSuccessEvent() { UserId = Guid.NewGuid(), EventId = Guid.NewGuid(), }; using (var context = _factory.CreateContext()) { context.Events.Add(new Event() { EventId = @event.EventId, ClubId = Guid.NewGuid(), PublicPrice = 10 }); context.EventParticipants.Add(new EventParticipant() { EventId = @event.EventId, UserId = @event.UserId, }); context.SaveChanges(); } await SendEvent(@event); using (var context = _factory.CreateContext()) { Assert.That(context.EventParticipants.Count(), Is.EqualTo(1)); } }
public async Task <IActionResult> Index() { var json = await new StreamReader(HttpContext.Request.Body).ReadToEndAsync(); Log.Information(json); try { var stripeEvent = EventUtility.ParseEvent(json); if (stripeEvent.Type == Stripe.Events.PaymentIntentSucceeded) { var paymentIntent = stripeEvent.Data.Object as PaymentIntent; if (paymentIntent.Metadata.Count == 2) { var e = new SignUpEventSuccessEvent() { UserId = new Guid(paymentIntent.Metadata["UserId"]), EventId = new Guid(paymentIntent.Metadata["EventId"]) }; Log.Information("User: "******" signed up to eventId: " + e.EventId); await _eventService.SaveEventAndDbContextChangesAsync(e); await _eventService.PublishEventAsync(e); } } else if (stripeEvent.Type == Stripe.Events.CustomerSubscriptionCreated) { var sub = stripeEvent.Data.Object as Subscription; if (sub.Metadata.Count == 2) { var e = new SignUpSubscriptionSuccessEvent() { UserId = new Guid(sub.Metadata["UserId"]), ClubSubscriptionId = new Guid(sub.Metadata["ClubSubscriptionId"]) }; Log.Information("User: "******" signed up to subscription: " + e.ClubSubscriptionId); await _eventService.SaveEventAndDbContextChangesAsync(e); await _eventService.PublishEventAsync(e); } } else { Console.WriteLine("Unhandled event type: {0}", stripeEvent.Type); } return(Ok()); } catch { } return(BadRequest()); }
public async Task <IActionResult> eventCheat(EventCheatRequest request) { var e = new SignUpEventSuccessEvent() { UserId = request.UserId, EventId = request.EventId }; Log.Information("User: "******" signed up to eventId: " + e.EventId); await _eventService.SaveEventAndDbContextChangesAsync(e); await _eventService.PublishEventAsync(e); return(Ok()); }
public async Task Consume_EventDoesNotExist_DoesNotCreateUserSignUp() { var @event = new SignUpEventSuccessEvent() { UserId = Guid.NewGuid(), EventId = Guid.NewGuid(), }; await SendEvent(@event); using (var context = _factory.CreateContext()) { Assert.That(context.EventParticipants.Count(), Is.EqualTo(0)); } }