Esempio n. 1
0
        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
                });
            }
        }
Esempio n. 2
0
        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> Update(DayBookingSource booking)
        {
            try
            {
                Event evnt = await _eventRepository.GetActiveAsync();

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

                await _dayBookingRepository.UpdateAsync(evnt, booking);

                return(Ok());
            }
            catch (BookingException ex)
            {
                _log.Warn(ex, "A validation error occurred while updating the day booking.");
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                _log.Error(ex, "An unexpected exception occurred while updating the day booking.");
                throw;
            }
        }
        public async Task <IHttpActionResult> Create(DayBookingSource booking)
        {
            try
            {
                Event evnt = await _eventRepository.GetActiveAsync();

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

                string reference = await _dayBookingRepository.CreateAsync(evnt, booking);

                _log.Info("Created day booking {0}.", reference);

                return(Ok());
            }
            catch (Exception ex)
            {
                _log.Error(ex, "An unexpected exception occurred while creating a day booking.");
                throw;
            }
        }