public Surveys GetById(long id)
        {
            var survey = GetAll().FirstOrDefault(h => h.Id == id);

            if (survey != null)
            {
                var customerId = BookingList.First(x => x.BookingId == survey.BookingId).CustomerId;
                var hotels     = (from h in HotelList
                                  join p in ProductList on h.HotelId equals p.HotelId
                                  join b in BookingList on p.ProductId equals b.ProductId
                                  where b.BookingId == survey.BookingId
                                  select h).FirstOrDefault();
                var products = (from p in ProductList
                                join b in BookingList on p.ProductId equals b.ProductId
                                where b.BookingId == survey.BookingId
                                select p).FirstOrDefault();
                var bookings = BookingList.FirstOrDefault(b => b.BookingId == survey.BookingId);

                survey.TicketPurchased = BookingList.Where(b => b.CustomerId == customerId).Sum(b => b.Quantity);
                survey.HotelName       = hotels != null ? hotels.HotelName : string.Empty;
                survey.City            = hotels != null ? hotels.City : string.Empty;
                survey.ProductName     = products != null ? products.ProductName : string.Empty;
                survey.CheckInDate     = bookings != null ? bookings.CheckinDate : null;
                survey.PerTicketPrice  = bookings != null ? bookings.HotelPrice : 0;
                survey.TotalPrice      = bookings != null ? bookings.TotalPrice : 0;
            }

            return(survey);
        }
        public Surveys GetSurveysByCode(string code)
        {
            var surveys = GetAll().FirstOrDefault(x => x.Code == code);

            if (surveys != null)
            {
                var booking = BookingList.FirstOrDefault(b => b.BookingId == surveys.BookingId);
                if (booking != null)
                {
                    var product = ProductList.FirstOrDefault(p => p.ProductId == booking.ProductId);
                    surveys.RedeemedDate = booking.RedeemedDate;
                    surveys.HotelPrice   = booking.HotelPrice;
                    if (product != null)
                    {
                        var    hotel    = HotelList.FirstOrDefault(h => h.HotelId == product.HotelId);
                        string imageUrl = Constant.ImageDefault;
                        var    image    = ProductImageList.FirstOrDefault(x => x.ProductId == product.ProductId && x.IsCover && x.IsActive);
                        if (image != null)
                        {
                            imageUrl = image.Url;
                        }
                        surveys.ImageUrl = imageUrl;
                        if (hotel != null)
                        {
                            surveys.HotelInfo = string.Format("{0} at {1}<br/> {2}, {3}",
                                                              product.ProductName,
                                                              hotel.HotelName,
                                                              hotel.Neighborhood,
                                                              hotel.City);
                        }
                    }
                }
            }
            return(surveys);
        }
        public ListResult <Surveys> SearchSurveys(int hotelId, DateTime?startDate, DateTime?endDate, int pageNumber = 1)
        {
            var result  = new ListResult <Surveys>();
            var surveys = (from p in SurveyList
                           join p1 in BookingList on p.BookingId equals p1.BookingId
                           join p2 in ProductList on p1.ProductId equals p2.ProductId
                           join p3 in HotelList on p2.HotelId equals p3.HotelId
                           where p3.HotelId == hotelId && p.IsFinish && !p.IsDelete
                           orderby p1.RedeemedDate descending
                           select p).ToList();

            // Assign CheckInDate
            if (surveys.Any())
            {
                surveys.ForEach(item =>
                {
                    var bookings = BookingList.FirstOrDefault(b => b.BookingId == item.BookingId);
                    if (bookings != null)
                    {
                        item.CheckInDate = bookings.CheckinDate;
                    }
                });
            }

            if (startDate.HasValue)
            {
                surveys =
                    surveys.Where(x => x.CheckInDate.HasValue && x.CheckInDate.Value.Date >= startDate.Value.Date).ToList();
            }

            if (endDate.HasValue)
            {
                surveys =
                    surveys.Where(x => x.CheckInDate.HasValue && x.CheckInDate.Value.Date <= endDate.Value.Date).ToList();
            }

            result.TotalRecords = surveys.Count();

            surveys = pageNumber <= 1 ? surveys.Take(Constant.ItemPerPage).ToList() : surveys.Skip((pageNumber - 1) * Constant.ItemPerPage).Take(Constant.ItemPerPage).ToList();

            if (surveys.Any())
            {
                surveys.ForEach(item =>
                {
                    double spend = 0;
                    if (item.IsBuyFoodAndDrink && item.FoodAndDrinkPrice.HasValue)
                    {
                        spend += item.FoodAndDrinkPrice.Value;
                    }

                    if (item.IsPayForParking)
                    {
                        spend += Constant.ParkingPrice;
                    }

                    if (item.IsBuySpaService && item.SpaServicePrice.HasValue)
                    {
                        spend += item.SpaServicePrice.Value;
                    }

                    if (item.IsBuyAdditionalService && item.AdditionalServicePrice.HasValue)
                    {
                        spend += item.AdditionalServicePrice.Value;
                    }

                    item.EstSpend     = spend;
                    item.RedeemedDate = item.Bookings.RedeemedDate;
                });
            }

            result.Items = surveys.ToList();

            return(result);
        }