Example #1
0
        static void Main(string[] args)
        {
            var objContext  = new SingleUsageObjectContextAdapter(new DbContextFactory <HotelAdminContext>());
            var hotelRep    = new HotelRepository(objContext);
            var factTypeRep = new FactTypeRepository(objContext);
            var historyRep  = new DummyHistoryItemRepository();

            FactTypeService factTypeService = new FactTypeService(objContext, factTypeRep);
            HotelService    hotelService    = new HotelService(objContext, hotelRep, historyRep);

            if (args != null && args.Length > 0 && args[0] == "world")
            {
                int numberOfHotels = 100;
                if (args.Length > 1)
                {
                    if (!int.TryParse(args[1], out numberOfHotels))
                    {
                        numberOfHotels = 100; // Default to 100
                    }
                }
                WorldLoader.LoadWorld(hotelService, factTypeService, numberOfHotels);
                return;
            }

            Console.WriteLine("Usage: HotelAdmin.Loader.exe {{world}} [maxItems] ");
        }
Example #2
0
        public static void LoadWorld(HotelService hotelService, FactTypeService factTypeService, int maxHotels)
        {
            var world = Download <World>("http://api.thomascook.se/v-1/geography/world");

            List <Hotel> hotels = new List <Hotel>();

            FindHotels(hotels, world, maxHotels);

            Console.WriteLine("\n\nAdding FactTypes");
            Dictionary <string, FactTypeModel> factTypeDictionary = new Dictionary <string, FactTypeModel>();

            foreach (var fact in hotels.SelectMany(h => h.Facts))
            {
                FactTypeModel model;
                if (!factTypeDictionary.TryGetValue(fact.Type, out model))
                {
                    model = factTypeService.GetFactType(fact.Type);
                    if (model == null)
                    {
                        model = new FactTypeModel()
                        {
                            Code = fact.Type, Name = fact.Title
                        };
                        var id = factTypeService.AddFactType(model);
                        model.Id = id;
                    }
                    factTypeDictionary[fact.Type] = model;
                }
            }
            Console.WriteLine("\n\nAdding hotels");
            foreach (var hotel in hotels)
            {
                Console.WriteLine("Adding hotel {0}", hotel.Name);
                var id = hotelService.AddHotel(hotel.Name, hotel.Description.Select(d => d.Text).FirstOrDefault(), hotel.ResortName,
                                               hotel.Images != null && hotel.Images.Main != null
                                                   ? hotel.Images.Main.Select(
                                                   i =>
                                                   i.OrderByDescending(ii => ii.Width).Select(ii => ii.Href).FirstOrDefault())
                                               .FirstOrDefault()
                                                   : null, hotel.Location != null ? hotel.Location.Latitude : 0,
                                               hotel.Location != null ? hotel.Location.Longitude : 0);

                Console.WriteLine("Setting facts for hotel {0}", hotel.Name);
                hotelService.SetHotelFacts(id, from f in hotel.Facts
                                           select
                                           new FactModel(factTypeDictionary[f.Type].Id, f.Type, f.Title,
                                                         f.Value.Trim() != "-" && f.Value.Trim().ToLower() != "false",
                                                         f.Value.ToLower() == "false" || f.Value.ToLower() == "true"
                                                                     ? string.Empty
                                                                     : f.Value));
            }
        }
Example #3
0
 public static int addFactType(FactType facttype)
 {
     return(FactTypeService.addFactType(facttype));
 }
Example #4
0
 public static int getFactTypeBytypename(string typename)
 {
     return(FactTypeService.getFactTypeBytypename(typename));
 }
Example #5
0
 public static IList <FactType> getFactTypeAll()
 {
     return(FactTypeService.getFactTypeAll());
 }
Example #6
0
 public static FactType getFactTypeById(int id)
 {
     return(FactTypeService.getFactTypeById(id));
 }
Example #7
0
 public static int deleteFactType(int id)
 {
     return(FactTypeService.deleteFactTypeById(id));
 }
Example #8
0
 public static int updateFactType(FactType facttype)
 {
     return(FactTypeService.updateFactTypeById(facttype));
 }