Ejemplo n.º 1
0
        public JsonResult InputNews(InputNewsRequestModel objReq)
        {
            try
            {
                var obj = new Movie();
                obj.Title     = objReq.Title;
                obj.Category  = objReq.Category;
                obj.Duration  = objReq.Duration;
                obj.Premiere  = objReq.Premiere;
                obj.Directors = objReq.Directors;
                obj.Cast      = objReq.Cast;
                obj.Language  = objReq.Language;
                obj.Rated     = objReq.Rated;
                obj.ImgUrl    = objReq.ImgUrl;

                _movie.Movies.Add(obj);

                _movie.SaveChanges();


                return(Json(new { success = true, responseText = "Đăng tin thành công" }));
            }
            catch (Exception e)
            {
                return(Json(new { success = false, responseText = "Errô" }));
            }
        }
Ejemplo n.º 2
0
        static void GetDataDistrict()
        {
            string          link        = "https://alonhadat.com.vn/handler/Handler.ashx?command=2&matinh=";
            List <District> lstDistrict = new List <District>();
            var             lstProvince = _context.Provinces.ToList();


            HtmlWeb htmlWeb = new HtmlWeb();

            {
            };

            foreach (var pro in lstProvince)
            {
                Console.WriteLine("Crawling: " + pro.Name);
                HtmlDocument document = htmlWeb.Load(link + pro.Id);

                foreach (var item in document.DocumentNode.ChildNodes)
                {
                    if (item.Name == "option" && item.Attributes["value"].Value != "0")
                    {
                        lstDistrict.Add(new District
                        {
                            Id         = int.Parse(item.Attributes["value"].Value),
                            Name       = HttpUtility.HtmlDecode(item.InnerText),
                            ProvinceId = pro.Id
                        });
                    }
                }
            }


            Console.WriteLine("Insert data to db");

            _context.Districts.AddRange(lstDistrict);
            _context.SaveChanges();

            GetMultiData();
            Console.ReadKey();
        }
Ejemplo n.º 3
0
        static void GetDataProvince()
        {
            string  link    = "https://alonhadat.com.vn/dang-tin-nha-dat.html";
            HtmlWeb htmlWeb = new HtmlWeb();

            {
            };

            HtmlDocument document          = htmlWeb.Load(link);
            var          selectboxProvince = document.GetElementbyId("ctl00_content_tinh").ChildNodes;

            List <Province> lstProvince = new List <Province>();

            foreach (var item in selectboxProvince)
            {
                if (item.Name == "option" && item.Attributes["value"].Value != "0")
                {
                    lstProvince.Add(new Province
                    {
                        Id   = int.Parse(item.Attributes["value"].Value),
                        Name = HttpUtility.HtmlDecode(item.InnerText)
                    });

                    Console.WriteLine(item.Attributes["value"].Value);
                    Console.WriteLine(HttpUtility.HtmlDecode(item.InnerText));
                }
            }


            var optionsBuilder = new DbContextOptionsBuilder <EstateWebDbContext>();

            optionsBuilder.UseSqlServer("Server=NGOCHAHA; Database= Movie; Integrated Security=true;");
            var _context = new EstateWebDbContext(optionsBuilder.Options);

            _context.Provinces.AddRange(lstProvince);
            _context.SaveChanges();
            GetDataDistrict();
            Console.ReadKey();
        }