public RedirectToRouteResult CreateParser(ParseCreator model)
 {
     var parser = new ParseAttribute
     {
         CodetypeID = model.CodetypeId.ToString(),
         ParseAttributelink = model.ParseAttributelink,
         NameXPath = model.ProductNameXpath,
         PagingXPath = model.PagingXpath,
         PointXPath = model.ProductPointXpath,
         IsActive = true
     };
     context.ParseAttributes.Add(parser);
     context.SaveChanges();
     TempData["create"] = "Success";
     return RedirectToAction("Index");
 }
        /// <summary>
        /// Get Data
        /// </summary>
        /// <param name="web"></param>
        /// <param name="parseAtt"></param>
        /// <returns></returns>
        public static List<KeyValuePair<string, string>> GetData(HtmlWeb web, ParseAttribute parseAtt)
        {
            var data = new List<KeyValuePair<string, string>>();
            var uri = new Uri(parseAtt.ParseAttributelink);
            string host = uri.GetLeftPart(UriPartial.Authority);
            //load website

            //1st page
            HtmlDocument doc = web.Load(parseAtt.ParseAttributelink);
            data = MatchingData(doc, parseAtt.NameXPath, parseAtt.PointXPath);
            //other page

            if (parseAtt.PagingXPath != null)
            {
                var pages = doc.DocumentNode.SelectNodes(parseAtt.PagingXPath);
                foreach (var page in pages)
                {
                    int pageNumber;
                    if (page == null || !Int32.TryParse(page.InnerText, out pageNumber))
                    {
                        break;
                    }
                    //get add
                    string url = host + page.Attributes["href"].Value;
                    //load page
                    doc = web.Load(url);
                    //get data
                    var tempdata = MatchingData(doc, parseAtt.NameXPath, parseAtt.PointXPath);
                    // add data to collection
                    data.AddRange(tempdata);
                }
            }

            return data;
        }
        public ActionResult SetActive(int id)
        {
            var parser = context.ParseAttributes.FirstOrDefault(x => x.ID == id);
            bool statusFlag = false;
            if (ModelState.IsValid)
            {
                if (parser.IsActive)
                {
                    parser.IsActive = false;
                    statusFlag = false;
                }
                else
                {
                    parser.IsActive = true;
                    statusFlag = true;
                }
                context.SaveChanges();
            }

            // Display the confirmation message
            var results = new ParseAttribute
            {
                IsActive = statusFlag
            };
            return Json(results);
        }
        public RedirectToRouteResult EditParser(ParseAttribute model)
        {
            var parser = context.ParseAttributes.FirstOrDefault(p => p.ID == model.ID);
            string message = "";
            if (parser != null)
            {
                parser.NameXPath = model.NameXPath;
                parser.PagingXPath = model.PagingXPath;
                parser.ParseAttributelink = model.ParseAttributelink;
                parser.PointXPath = model.PointXPath;
                parser.CodetypeID = model.CodetypeID;
                context.SaveChanges();
                message = "success";

            }
            else
            {
                message = "failed";
            }
            TempData["edit"] = message;
            return RedirectToAction("Index");
        }