public ServiceResultModel <List <HotelDefinitionVM> > GetHotels(HotelFilter filter)
        {
            List <HotelDefinitionVM> resultList = new List <HotelDefinitionVM>();

            using (EFBookingContext context = new EFBookingContext())
            {
                IQueryable <HotelDefinition> hotelDefinitionList = context.HotelDefinitions;

                if (filter.HotelName.IsNotNull())
                {
                    hotelDefinitionList = hotelDefinitionList.Where(p => p.Title.Contains(filter.HotelName));
                }

                if (filter.HotelTypeId > 0)
                {
                    hotelDefinitionList = hotelDefinitionList.Where(p => p.HotelTypeId == filter.HotelTypeId);
                }

                hotelDefinitionList.ToList().ForEach(p =>
                {
                    resultList.Add(p.MapProperties <HotelDefinitionVM>());
                });

                return(ServiceResultModel <List <HotelDefinitionVM> > .OK(resultList));
            }
        }
 private HotelFilter[] SetHotelFilters()
 {
     HotelFilter[] hotelFilters = new HotelFilter[]
     {
         new AvailabilityFilter()
         {
             ReturnOnlyAvailableItineraries = true
         }
     };
     return(hotelFilters);
 }
        private string GenerateSQL(HotelFilter filter)
        {
            StringBuilder sb = new StringBuilder("SELECT * FROM DemoHotel");

            if (filter.IsEmpty())
            {
                return(sb.ToString());
            }

            sb.Append(" WHERE ");

            bool haveAddress = false;

            if (!string.IsNullOrWhiteSpace(filter.AddressIs))
            {
                sb.Append($" Address = '{filter.AddressIs}'");
                haveAddress = true;
            }
            else if (!string.IsNullOrWhiteSpace(filter.AddressLike))
            {
                sb.Append($" Address LIKE '%{filter.AddressLike}%'");
                haveAddress = true;
            }



            if (!string.IsNullOrWhiteSpace(filter.NameIs))
            {
                if (haveAddress)
                {
                    sb.Append(" AND ");
                }
                sb.Append($" Name = '{filter.NameIs}'");
            }
            else if (!string.IsNullOrWhiteSpace(filter.NameLike))
            {
                if (haveAddress)
                {
                    sb.Append(" AND ");
                }
                sb.Append($" Name LIKE '%{filter.NameLike}%'");
            }

            return(sb.ToString());
        }
        public IEnumerable <Hotel> GetFilter(HotelFilter filter)
        {
            List <Hotel> liste = new List <Hotel>();

            String sql = GenerateSQL(filter);

            SqlCommand    cmd    = new SqlCommand(sql, SQLConnectionSingleton.Instance.DbConnection);
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                Hotel hotel = ReadHotel(reader);
                liste.Add(hotel);
            }
            reader.Close();

            foreach (Hotel h in liste)
            {
                h.AddRange(ReadHotelRooms(h.Id));
            }
            return(liste);
        }
Beispiel #5
0
        public ServiceResultModel <List <HotelVM> > GetAllHotels(HotelFilter filter)
        {
            List <HotelVM> resultList = new List <HotelVM>();

            using (EFBookingContext context = new EFBookingContext())
            {
                IQueryable <Hotel> HotelList = context.Hotels;

                if (filter.Name.IsNotNull())
                {
                    HotelList = HotelList.Where(p => p.Name.Contains(filter.Name));
                }

                //if (filter.HotelTypeId.HasValue)
                //    HotelList = HotelList.Where(p => p.HotelTypeId == filter.HotelTypeId);

                HotelList.ToList().ForEach(p =>
                {
                    resultList.Add(p.MapProperties <HotelVM>());
                });

                return(ServiceResultModel <List <HotelVM> > .OK(resultList));
            }
        }
Beispiel #6
0
 public IEnumerable <Hotel> GetFilter([FromUri] HotelFilter filter)
 {
     return(mgr.GetFilter(filter));
 }