Esempio n. 1
0
        public async Task <IHttpActionResult> Create(BookingCandidate candidate)
        {
            try
            {
                Event evnt = await _eventRepository.GetActiveAsync();

                if (null == evnt)
                {
                    return(NotFound());
                }

                Guid id = await _candidateRepository.CreateAsync(candidate);

                int queueSize = await _candidateRepository.GetNumberOfActiveAsync();

                return(Ok(new BookingCandidateResponse(id, queueSize, evnt)));
            }
            catch (BookingException ex)
            {
                _log.Warn(ex, "A validation error occurred while creating the booking candidate.");
                return(BadRequest());
            }
            catch (Exception ex)
            {
                _log.Error(ex, "An unexpected exception occurred while creating the booking candidate.");
                throw;
            }
        }
Esempio n. 2
0
        public async Task <Guid> CreateAsync(BookingCandidate candidate)
        {
            BookingCandidate.Validate(candidate);

            using (var db = DbUtil.Open())
            {
                Guid id = await db.ExecuteScalarAsync <Guid>("insert into [BookingCandidate] ([FirstName], [LastName], [Email], [PhoneNo], [TeamName], [TeamSize]) output inserted.[Id] values (@FirstName, @LastName, @Email, @PhoneNo, @TeamName, @TeamSize)",
                                                             new { FirstName = candidate.FirstName, LastName = candidate.LastName, Email = candidate.Email, PhoneNo = candidate.PhoneNo, TeamName = candidate.TeamName, TeamSize = candidate.TeamSize });

                return(id);
            }
        }
Esempio n. 3
0
 async Task SendBookingCreatedMailAsync(Event evnt, BookingCandidate candidate, BookingResult result)
 {
     try
     {
         using (var emailSender = new EmailSender())
             await emailSender.SendBookingCreatedMailAsync(evnt.Name, candidate.Email, result.Reference, result.Password);
     }
     catch (Exception ex)
     {
         _log.Error(ex, "Failed to send e-mail on created booking.");
     }
 }
Esempio n. 4
0
        public async Task <BookingResult> CreateFromCandidateAsync(Event evnt, BookingCandidate candidate, int placeInQueue)
        {
            Booking booking;

            /*
             * We need a transaction around this to prevent multiple bookings being created from the same candidate.
             * Unlike Sjöslaget there is no risk of overcommitting passengers since allocation of cabins happens
             * separate from booking.
             */
            var tranOptions = new TransactionOptions {
                IsolationLevel = IsolationLevel.ReadUncommitted
            };

            using (var tran = new TransactionScope(TransactionScopeOption.Required, tranOptions, TransactionScopeAsyncFlowOption.Enabled))
                using (var db = DbUtil.Open())
                {
                    await db.GetAppLockAsync(LockResource, LockTimeout);

                    if (0 != await db.ExecuteScalarAsync <int>("select count(*) from [Booking] where [CandidateId] = @Id", new { Id = candidate.Id }))
                    {
                        _log.Warn($"An attempt was made to create a second booking from the same candidate = {candidate.Id}");
                        throw new BookingException("A booking has already been created from this candidate.");
                    }

                    booking = Booking.FromCandidate(candidate, placeInQueue, evnt.Id, _credentialsGenerator.GenerateBookingReference());
                    await CreateBooking(db, candidate.Id, booking);

                    tran.Complete();
                }

            var password = _credentialsGenerator.GeneratePinCode();
            await _userManager.CreateAsync(new AecUser { UserName = booking.Reference, IsBooking = true }, password);

            return(new BookingResult {
                Reference = booking.Reference, Password = password
            });
        }