public async Task UpdateAsync(Event evnt, DayBookingSource source) { SoloBookingSource.Validate(source); using (var db = DbUtil.Open()) { var booking = await FindByReferenceAsync(db, source.Reference); if (null == booking || booking.EventId != evnt.Id) { throw new BookingException($"Day booking with reference {source.Reference} not found or not in active event."); } await db.ExecuteAsync("update [DayBooking] set [FirstName] = @FirstName, [LastName] = @LastName, [Email] = @Email, [PhoneNo] = @PhoneNo, [Gender] = @Gender, [Dob] = @Dob, [Food] = @Food, [TypeId] = @TypeId, [PaymentConfirmed] = @PaymentConfirmed, [Updated] = sysdatetime() where [Id] = @Id", new { Id = booking.Id, FirstName = source.FirstName, LastName = source.LastName, Email = source.Email, PhoneNo = source.PhoneNo, Gender = source.Gender, Dob = source.Dob, Food = source.Food, TypeId = source.TypeId, PaymentConfirmed = source.PaymentConfirmed }); } }
public async Task <string> CreateAsync(Event evnt, DayBookingSource booking) { SoloBookingSource.Validate(booking); using (var db = DbUtil.Open()) { string reference = _credentialsGenerator.GenerateDayBookingReference(); await db.ExecuteScalarAsync <Guid>("insert into [DayBooking] ([EventId], [Reference], [FirstName], [LastName], [Email], [PhoneNo], [Gender], [Dob], [Food], [TypeId]) " + "values (@EventId, @Reference, @FirstName, @LastName, @Email, @PhoneNo, @Gender, @Dob, @Food, @TypeId)", new { EventId = evnt.Id, Reference = reference, FirstName = booking.FirstName, LastName = booking.LastName, Email = booking.Email, PhoneNo = booking.PhoneNo, Gender = booking.Gender, Dob = booking.Dob, Food = booking.Food, TypeId = booking.TypeId }); return(reference); } }
public async Task <IHttpActionResult> Solo(SoloBookingSource bookingSource) { try { Event evnt = await _eventRepository.GetActiveAsync(); if (null == evnt) { return(NotFound()); } if (!evnt.HasOpened) { _log.Warn("An attempt was made to create a solo booking before the event is open."); return(BadRequest()); } BookingResult result = await _bookingRepository.CreateSoloAsync(evnt, bookingSource); _log.Info("Created solo booking {0}.", result.Reference); await SendBookingCreatedMailAsync(evnt, bookingSource, result); return(Ok(result)); } catch (Exception ex) { _log.Error(ex, "An unexpected exception occurred while creating a solo booking."); throw; } }
async Task SendBookingCreatedMailAsync(Event evnt, SoloBookingSource source, BookingResult result) { try { using (var emailSender = new EmailSender()) await emailSender.SendBookingCreatedMailAsync(evnt.Name, source.Email, result.Reference, result.Password); } catch (Exception ex) { _log.Error(ex, "Failed to send e-mail on created booking."); } }
public async Task <BookingResult> CreateSoloAsync(Event evnt, SoloBookingSource source) { SoloBookingSource.Validate(source); var booking = new Booking { EventId = evnt.Id, Reference = _credentialsGenerator.GenerateBookingReference(), FirstName = source.FirstName, LastName = source.LastName, Email = source.Email, PhoneNo = source.PhoneNo, TeamName = String.Concat(source.FirstName, ' ', source.LastName), SpecialRequest = String.Empty, InternalNotes = String.Empty }; var pax = new BookingPax { FirstName = source.FirstName, LastName = source.LastName, Gender = Gender.FromString(source.Gender), Dob = new DateOfBirth(source.Dob), Food = source.Food, CabinClassMin = 0, CabinClassMax = 0, CabinClassPreferred = 0 }; using (var db = DbUtil.Open()) { await CreateBooking(db, Guid.Empty, booking); pax.BookingId = booking.Id; await CreatePax(db, pax, 0); } var password = _credentialsGenerator.GeneratePinCode(); await _userManager.CreateAsync(new AecUser { UserName = booking.Reference, IsBooking = true }, password); return(new BookingResult { Reference = booking.Reference, Password = password }); }