public long InsertUserBooking(long customerId, long eventId, string confirmationNumber)
        {
            long newBookingId = 0;

            using (var context = new AnnoDBContext())
            {
                //Insert customer booking to database
                var newCustomerBooking = new CustomerBooking()
                {
                    customer_id         = customerId,
                    event_id            = eventId,
                    confirmation_number = confirmationNumber,
                    record_status       = RecordStatuses.Live,
                    created_date        = DateTime.UtcNow
                };
                context.CustomerBooking.Add(newCustomerBooking);
                context.SaveChanges();

                //Get the ID of the newly created record
                newBookingId = newCustomerBooking.booking_id;
            }

            return(newBookingId);
        }
Example #2
0
        public async Task <BookingResponse> GetBookingList(Booking booking, string cookieToken)
        {
            try
            {
                if (booking.content.Count == 1)
                {
                    BookingContent bookingContent = booking.content.ElementAt <BookingContent>(0);
                    _logger.LogInformation("Booking Found: " + bookingContent.id);
                    var url                = $"{Host}{GetCustomres}";
                    var uriBuilder         = new UriBuilder(url + bookingContent.id);
                    var client             = new HttpClient();
                    var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, uriBuilder.ToString());
                    httpRequestMessage.Headers.Add("Cookie", cookieToken);
                    _logger.LogInformation("Booking Requested: " + bookingContent.id);
                    var result = await GetURI(httpRequestMessage);

                    _logger.LogInformation("Booking Fetched: " + bookingContent.id);
                    Customer customer = Newtonsoft.Json.JsonConvert.DeserializeObject <Customer>(result);
                    if (customer.bookings.Count == 0)
                    {
                        _logger.LogError("Booking not found for Booking Reference ID : " + bookingContent.id);
                        throw new Exception("Booking not found for Booking Reference ID : " + bookingContent.id);
                    }
                    else
                    {
                        List <CustomerBooking> customerBooking = customer.bookings.Where(x => x.status == COMPLETED && CompareStartDate(x.startDate, x.endDate) == true && Enum.IsDefined(typeof(HelperUtils.BookingType), x.bookingType)).ToList <CustomerBooking>();
                        if (customerBooking.Count == 0)
                        {
                            _logger.LogError("No record found for Status COMPLETED booking Id: " + bookingContent.id);
                            throw new Exception("No record found for Status COMPLETED booking Id: " + bookingContent.id);
                        }
                        else if (customerBooking.Count > 1)
                        {
                            throw new Exception("More than one booking completed Records Exists: " + customerBooking.Count);
                        }
                        CustomerBooking _tempBooking = customerBooking.FirstOrDefault();
                        _logger.LogInformation("Succcess Booking");
                        double _tempAccountBalance;
                        bool   isNumerical = double.TryParse(customer.accountBalance, out _tempAccountBalance);
                        return(new BookingResponse()
                        {
                            id = _tempBooking.id,
                            customerId = customer.partyNumber,
                            firstName = customer.firstName,
                            lastName = customer.lastName,
                            accountBalance = isNumerical ? String.Format("{0:0.00}", _tempAccountBalance) : customer.accountBalance,
                            instanceId = _tempBooking.instanceId,
                            occupierId = _tempBooking.occupierId,
                            dateOfBirth = customer.dateOfBirth,
                            contractNumber = _tempBooking.contractNumber,
                            buildingName = _tempBooking.buildingName,
                            bookingType = _tempBooking.bookingType,
                            block = _tempBooking.block,
                            floor = _tempBooking.floor,
                            flatName = _tempBooking.flatName,
                            roomNumber = _tempBooking.roomNumber
                        });
                    }
                }
                else
                {
                    _logger.LogError("No Booking Record Found: " + booking.content.Count);
                    throw new Exception("No Booking Record Found: " + booking.content.Count);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("GetBookingList ===> " + ex.Message.ToString());
                throw new Exception(ex.Message.ToString(), ex);
            }
        }