Beispiel #1
0
        public static List <Advert> GetAdverts(string url)
        {
            HtmlNodeCollection content = RetrieveHtml(url);
            List <Advert>      adverts = new List <Advert>();
            Advert             advert;

            if (content != null)
            {
                foreach (HtmlNode node in content)
                {
                    try
                    {
                        advert = new Advert();

                        advert.Id         = ParseHtml.ParseId(node);
                        advert.Category   = ParseHtml.ParseCategory(node);
                        advert.Name       = ParseHtml.ParseName(node);
                        advert.Url        = ParseHtml.ParseUrl(node);
                        advert.Location   = ParseHtml.ParseLocation(node);
                        advert.Date       = ParseHtml.ParseDate(node);
                        advert.Price      = ParseHtml.ParsePrice(node);
                        advert.IsPromoted = ParseHtml.ParseIsPromoted(node);

                        adverts.Add(advert);
                    }
                    catch
                    { }
                }
            }


            return(adverts.OrderBy(x => x.Id).ToList());
        }
        public static bool IsAdvertExists(Advert advert)
        {
            string query = @"select iif(exists(select 1 from dbo.Advert where Adw_ForeignId = @Id),1,0) IsAdwExists";

            DynamicParameters param = new DynamicParameters();

            param.Add("Id", advert.Id);

            return(sqlConnection.ExecuteScalar <bool>(query, param));
        }
        public static string InsertAdvert(Advert advert, int searchid)
        {
            string query = @"insert into dbo.Advert(Adw_ForeignId, Adw_Name, Adw_Category, Adw_Location, Adw_Date, Adw_Price, Adw_Url, Adw_IsPromoted, Adw_SeLId)
values (@Id, @Name, @Category, @Location, @Date, @Price, @Url, @IsPromoted, @SearchId)
select top 1 'Poprawnie dodano ogłoszenie ' + Adw_ForeignId + ': ' + Adw_Name as Info from dbo.Advert where Adw_Id = SCOPE_IDENTITY()";

            DynamicParameters param = new DynamicParameters();

            param.Add("Id", advert.Id);
            param.Add("Name", advert.Name);
            param.Add("Category", advert.Category);
            param.Add("Location", advert.Location);
            param.Add("Date", advert.Date);
            param.Add("Price", advert.Price);
            param.Add("Url", advert.Url);
            param.Add("IsPromoted", advert.IsPromoted);
            param.Add("SearchId", searchid);

            return(sqlConnection.ExecuteScalar <string>(query, param));
        }