public bool AddOrUpdate(t_KinpanWard entity) { if (entity.id < 1) { return(dbContext.Add(entity)); } return(dbContext.Update(entity, c => c.id == entity.id)); }
/// <summary> /// 获取Kinpan菜单List /// </summary> /// <param name="strHtml"></param> /// <returns></returns> private static List <t_KinpanWard> GetKinpanMenusLists(string strHtml) { List <t_KinpanWard> lKinpanWard = new List <t_KinpanWard>(); try { HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(strHtml); doc.OptionOutputAsXml = true; HtmlNode node = doc.DocumentNode.SelectSingleNode(".//div[@class=\"all-sort-list\"]"); if (node == null) { return(null); } HtmlNodeCollection hrefList = node.SelectNodes(".//*[@class=\"subitem\"]/ul/li/a"); // HtmlNodeCollection hrefNodeList = node.SelectNodes(".//*[@class=\"subitem\"]/ul/li/a[@href]"); //if (hrefNodeList != null) //{ // foreach (var href in hrefNodeList) // { // string name = trNode.InnerText; // HtmlAttribute att = href.Attributes["href"]; // string Url = att.Value; // } //} int thisCount = hrefList.Count; int rid = 0; foreach (HtmlNode strHref in hrefList) { t_KinpanWard mKinpanWard = new t_KinpanWard(); string name = strHref.InnerText.Trim() ?? ""; HtmlAttribute att = strHref.Attributes["href"]; string url = att.Value.Trim() ?? ""; mKinpanWard.name = name; mKinpanWard.Url = url; if (Bllward.AddOrUpdate(mKinpanWard)) { MessageLog.AddLog("添加成功= 共(" + thisCount + ")第(" + rid + ")=>" + JsonConvert.SerializeObject(mKinpanWard)); } else { MessageLog.AddLog("失败--- 共(" + thisCount + ")第(" + rid + ")----" + JsonConvert.SerializeObject(mKinpanWard)); } lKinpanWard.Add(mKinpanWard); rid++; } } catch (Exception ex) { MessageLog.AddLog("GetKinpanMenusLists() ===>" + ex); } return(lKinpanWard); }