public bool CreateNewEvent(string name, string description, DateTime eventDate, int totalSeats, double ticketPrice, string userId) { var result = false; var newEvent = new Event() { Id = Guid.NewGuid(), Name = name, Description = description, TotalSeats = totalSeats, TicketPrice = ticketPrice, AvailableSeats = totalSeats, EventDate = eventDate, Status = EventStatus.Draft, Organizer = userId }; try { _ctx.Events.Add(newEvent); _ctx.SaveChanges(); result = true; _cloudContext.AddEvent(newEvent); } catch (Exception ex) { result = false; } return(result); }
public TicketSummary PlaceOrder(Guid eventId, string userId) { var parentEvent = _ctx.Events.Single(e => e.Id == eventId); var ticket = new Ticket() { AccessCode = Ticket.GenerateRandomAccessCode(), Attendee = userId, TotalPrice = parentEvent.TicketPrice, Status = TicketStatus.Pending, Id = Guid.NewGuid(), ParentEvent = parentEvent }; _ctx.Tickets.Add(ticket); _ctx.SaveChanges(); var ticketSummary = new TicketSummary() { TicketId = ticket.Id, TicketDescription = "Ticket for " + parentEvent.Name, TicketPrice = ticket.TotalPrice }; return(ticketSummary); }
public bool ConfirmTicket(Guid ticketId) { var result = false; bool hasBeenConfirmed = false; var ticket = _ctx.Tickets.Include("ParentEvent").Single(t => t.Id == ticketId); if (ticket.ParentEvent.AvailableSeats > 0) { result = true; ticket.Status = TicketStatus.Paid; ticket.ParentEvent.AvailableSeats--; hasBeenConfirmed = true; } else { _ctx.Tickets.Remove(ticket); } _ctx.SaveChanges(); if (hasBeenConfirmed) { _cloudContext.ConfirmTicket(ticket); _cloudContext.UpdateEventSeats(ticket.ParentEvent); } else { _cloudContext.DeleteTicket(ticket); } return(result); }
public void ProcessPlacedOrder(Guid eventId, string userId, string ticketId) { var ticketGuid = Guid.Parse(ticketId); var parentEvent = _ticketCtx.Events.SingleOrDefault(x => x.Id == eventId); var existingTicket = _ticketCtx.Tickets.SingleOrDefault(t => t.Id == ticketGuid); if (parentEvent != null && existingTicket == null) { Trace.TraceInformation("Adding the ticket to the database"); var ticket = new Ticket() { AccessCode = Ticket.GenerateRandomAccessCode(), Attendee = userId, TotalPrice = parentEvent.TicketPrice, Status = TicketStatus.Pending, Id = Guid.Parse(ticketId), ParentEvent = parentEvent }; _ticketCtx.Tickets.Add(ticket); _ticketCtx.SaveChanges(); // Update read model _azureCtx.AddTicket(ticket); } else { if (existingTicket != null) { Trace.TraceInformation("The ticket {0} already exists.", existingTicket.Id); } if (parentEvent == null) { Trace.TraceInformation("The event {0} for the ticket doesn't exist.", eventId); } } }