Esempio n. 1
0
        public void UpdateAutoSearchItem(AutoSearchItem item, SearchArgumentModel searchArgument)
        {
            item.SearchType = searchArgument.SearchType;
            item.MaxArea    = searchArgument.MaxArea;
            item.MinArea    = searchArgument.MinArea;

            item.MaxPrice = searchArgument.MaxPrice;
            item.MinPrice = searchArgument.MinPrice;

            item.MaxFloor = searchArgument.MaxFloor;
            item.MinFloor = searchArgument.MinFloor;

            item.MaxStoreys = searchArgument.MaxStoreys;
            item.MinStoreys = searchArgument.MinStoreys;

            item.District  = searchArgument.District;
            item.RoomCount = searchArgument.RoomCount;

            item.Description = searchArgument.Description;
            item.FoundApart  = 0;
            item.Num         = item.Num;

            AutoSearchViewModel.Instance.Items[int.Parse(item.Num) - 1] = item;

            DataBase.Update(item, DBTable.AutoSearchApartment);

            DataBase.Delete <FoundApartment>(apart => item.Id == apart.AutoSearchId, DBTable.FoundApartment);
        }
Esempio n. 2
0
        public static SearchArgumentModel Convert(AutoSearchItem item)
        {
            var sam = new SearchArgumentModel();

            sam.Id = item.Id;

            sam.SearchType = item.SearchType;
            sam.MinPrice   = item.MinPrice;
            sam.MaxPrice   = item.MaxPrice;
            sam.MinArea    = item.MinArea;
            sam.MaxArea    = item.MaxArea;
            sam.MinFloor   = item.MinFloor;
            sam.MaxFloor   = item.MaxFloor;

            sam.MinStoreys = item.MinStoreys;
            sam.MaxStoreys = item.MaxStoreys;
            sam.District   = item.District;

            return(sam);
        }
Esempio n. 3
0
        public void AddNewAutoSearchItem(SearchArgumentModel searchArgument)
        {
            var item = new AutoSearchItem();

            item.MaxArea = searchArgument.MaxArea;
            item.MinArea = searchArgument.MinArea;

            item.MaxPrice = searchArgument.MaxPrice;
            item.MinPrice = searchArgument.MinPrice;

            item.MaxFloor = searchArgument.MaxFloor;
            item.MinFloor = searchArgument.MinFloor;

            item.MaxStoreys = searchArgument.MaxStoreys;
            item.MinStoreys = searchArgument.MinStoreys;

            item.District  = searchArgument.District;
            item.RoomCount = searchArgument.RoomCount;

            item.Description = searchArgument.Description;
            item.Num         = (AutoSearchViewModel.Instance.Items.Count + 1).ToString();
            DataBase.Insert(item, DBTable.AutoSearchApartment);
            AutoSearchViewModel.Instance.Items.Add(item);
        }
Esempio n. 4
0
        private static async void Tick(object o, EventArgs e)
        {
            Console.WriteLine("Start search");
            var searchArgument = DataBase.GetCollectionList <AutoSearchItem>(DBTable.AutoSearchApartment);

            if (searchArgument.Count == 0)
            {
                return;
            }

            var buyArg    = searchArgument.Where(s => s.SearchType == SearchType.Buy).Select(s => SearchArgumentModel.Convert(s)).ToList();
            var arendaArg = searchArgument.Where(s => s.SearchType == SearchType.Arenda).Select(s => SearchArgumentModel.Convert(s)).ToList();

            var tasksBuy    = _scrapers.ToList().Select(async s => await s.GetApartments(buyArg, SearchType.Buy));
            var tasksArenda = _scrapers.ToList().Select(async s => await s.GetApartments(arendaArg, SearchType.Arenda));

            var tasks = new List <Task <List <FoundApartment> > >();

            tasks.AddRange(tasksBuy);
            tasks.AddRange(tasksArenda);

            var tasks_result = await Task.WhenAll(tasks);

            var aparts = new List <FoundApartment>();

            tasks_result.ToList().ForEach((t) => aparts.AddRange(t));

            var col = DataBase.GetCollectionList <FoundApartment>(DBTable.FoundApartment);

            aparts.ForEach(res =>
            {
                if (DataBase.Query <FoundApartment>(DBTable.FoundApartment).Where(apart =>
                                                                                  apart.apartment.Address == res.apartment.Address &&
                                                                                  apart.apartment.Area == res.apartment.Area &&
                                                                                  apart.apartment.Price == res.apartment.Price &&
                                                                                  apart.apartment.Floor == res.apartment.Floor &&
                                                                                  apart.apartment.Storeys == res.apartment.Storeys).Limit(1).ToList().Count == 0)
                {
                    DataBase.Insert(res, DBTable.FoundApartment);
                    if (AutoSearchViewModel.Instance.Items != null)
                    {
                        var asItem = AutoSearchViewModel.Instance.Items.FirstOrDefault(a => a.Id == res.AutoSearchId);
                        if (asItem != null)
                        {
                            asItem.FoundApart++;
                            asItem.Num = asItem.Num;
                            DataBase.Update(asItem, DBTable.AutoSearchApartment);
                        }
                    }
                }
            });
        }