public ActionResult Action(tblArticle objSubmit) { if (objSubmit.ID == 0) { objSubmit.DateCreated = DateTime.Now; objSubmit.DateUpdated = DateTime.Now; objSubmit.IsDeleted = false; objSubmit.IsShow = true; articleRepository.Add(objSubmit); } else { var obj = articleRepository.GetById <tblArticle>(objSubmit.ID); UpdateModel(obj); objSubmit.DateUpdated = DateTime.Now; articleRepository.Update(obj); } articleGroupMapRepository.ResetGroupOfNews(objSubmit.ID, Web365Utility.Web365Utility.StringToArrayInt(Request["groupID"])); return(Json(new { Error = false }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// method for adding the new article /// </summary> private void SaveExecute() { try { using (WarehouseEntities1 context = new WarehouseEntities1()) { tblArticle newArticle = new tblArticle(); if (article.Article.All(Char.IsLetter)) { newArticle.Article = article.Article; } else { MessageBox.Show("Wrong article name input, please edit."); } newArticle.Code = article.Code; newArticle.Amount = article.Amount; newArticle.Price = article.Price; newArticle.Stored = false; newArticle.ArticleID = article.ArticleID; context.tblArticles.Add(newArticle); context.SaveChanges(); IsUpdateArticle = true; } addArticle.Close(); } catch (Exception) { MessageBox.Show("Wrong inputs, please try again."); } }
protected string addProjectVersionArticle(projectVersionEditViewModel viewModel, SASDdbContext db) { string ret; tblArticle ta = new tblArticle(db); tblProject tp = new tblProject(); string projectName = tp.nameById(viewModel.editModel.projectId.ToString()); article prjArticle = ta.GetByProjectId(viewModel.editModel.projectId.ToString()); article pva = new article(); pva.articleId = (Guid)viewModel.editModel.versionArticleId; pva.createtime = DateTime.Now; pva.articleTitle = $"project {projectName} version " + $"{viewModel.editModel.version}"; pva.articleHtmlContent = string.Format(@" <h1>{0} version {1}</h1> <p>{2}</p> ", projectName, viewModel.editModel.version, viewModel.editModel.versionDescription); pva.articleContent = string.Format("{0} {1} {2}" , projectName, viewModel.editModel.version , viewModel.editModel.versionDescription); pva.isDir = true; pva.belongToArticleDirId = prjArticle.articleId; pva.articleType = ARTICLE_TYPE.Project.ToString(); pva.articleStatus = ARTICLE_STATUS.New.ToString(); pva.priority = 1; pva.projectId = viewModel.editModel.projectId; ret = ta.Add(pva); ret += ta.SaveChanges(); return(ret); }
protected string addProjectArticle(projectEditViewModel viewModel , SASDdbContext db) { string ret; tblArticle ta = new tblArticle(db); article pa = new article(); pa.articleId = (Guid)viewModel.editModel.projectArticleId;// Guid.NewGuid(); pa.createtime = DateTime.Now; pa.articleTitle = viewModel.editModel.projectName; pa.articleHtmlContent = string.Format(@" <h1>{0}</h1> <p>{1}</p> ", viewModel.editModel.projectName, viewModel.editModel.projectDescription); pa.articleContent = string.Format("{0} {1}" , viewModel.editModel.projectName , viewModel.editModel.projectDescription); pa.isDir = true; pa.articleType = ARTICLE_TYPE.Project.ToString(); pa.articleStatus = ARTICLE_STATUS.New.ToString(); pa.priority = 1; pa.projectId = viewModel.editModel.projectId; ret = ta.Add(pa); ret += ta.SaveChanges(); return(ret); }
private string loadArticle(string articleId, string parentDirId , ref articlesViewModel viewModel) { string ret = ""; // load directories tblArticle tbart = new tblArticle(); article parent = null; viewModel.subjects = new List <article>(); article art = null; if (!string.IsNullOrWhiteSpace(articleId)) { art = tbart.GetArticleById(articleId); if (art != null) { viewModel.articleTitle = art.articleTitle; viewModel.articleType = art.articleType; viewModel.articleHtmlContent = art.articleHtmlContent; if (string.IsNullOrWhiteSpace(parentDirId)) { parentDirId = art.belongToArticleDirId.ToString(); } } } if (art == null) { viewModel.articleTitle = ""; viewModel.articleType = ""; viewModel.articleHtmlContent = ""; } if (!string.IsNullOrWhiteSpace(parentDirId)) { parent = tbart.GetArticleById(parentDirId); } if (parent == null) { viewModel.parentDirId = ""; viewModel.parentDirTitle = ""; } else { viewModel.parentDirId = parent.articleId.ToString(); viewModel.parentDirTitle = parent.articleTitle; parent.belongToArticleDirId = parent.articleId; viewModel.subjects.Add(parent); } viewModel.directories = tbart.directoriesByParentArticleId(parentDirId); // load subjects viewModel.subjects.AddRange(tbart.subjectsByParentArticleId(parentDirId)); // the article of the current directory, should be listed at the top of the subject list // and view its content when click on it return(ret); }
public void Delete() { tblArticle model = new tblArticle(); using (DbModel db = new DbModel()) { model = db.Articles.Where(x => x.ArticleId == this.Id).FirstOrDefault(); db.Articles.Remove(model); db.SaveChanges(); } }
public ActionResult UpdateKeyAuto(tblArticle objSubmit) { //if (objSubmit.IsShow.HasValue) //{ // var webConfigApp = WebConfigurationManager.OpenWebConfiguration("~"); // //Modifying the AppKey from AppValue to IsCrawler // webConfigApp.AppSettings.Settings["IsCrawler"].Value = objSubmit.IsShow.Value.ToString(); // //Save the Modified settings of AppSettings. // webConfigApp.Save(); //} return(Json(new { Error = false }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Updates articles amount in DB with data from the list. /// </summary> /// <param name="articles"></param> public void UpdateAmount(List <vwArticle> articles) { using (BarStockEntities context = new BarStockEntities()) { for (int i = 0; i < articles.Count; i++) { if (articles[i].NewAmount != null) { int id = articles[i].ArticleID; tblArticle article = (from a in context.tblArticles where a.ArticleID == id select a).First(); article.Amount = (decimal)articles[i].NewAmount; } } context.SaveChanges(); } }
public void NewArticle() { tblArticle model = new tblArticle(); using (DbModel db = new DbModel()) { model.ArticleName = this.ArticleName; model.ArticleDescription = this.ArticleDescription; model.Price = this.Price; model.ArticleCategory = this.ArticleCategory; AddNewCategory(); db.Articles.Add(model); db.SaveChanges(); } }
private void AllStockDataGridView_MouseDoubleClick(object sender, MouseEventArgs e) { addStock.Visible = !addStock.Visible; int id = Convert.ToInt32(this.AllStockDataGridView.CurrentRow.Cells[0].Value); using (DbModel db = new DbModel()) { tblArticle model = new tblArticle(); model = db.Articles.Where(x => x.ArticleId == id).FirstOrDefault(); addStock.txtAddProductName.Text = model.ArticleName; addStock.txtAddProductDescription.Text = model.ArticleDescription; addStock.txtAddProductPrice.Text = model.Price.ToString(); addStock.cbAddProductCategory.Text = model.ArticleCategory; } }
public void Save(ArticleItem item) { var errors = item.GetValidationErrors(); errors.ThrowIfHasErrors(); var article = new tblArticle { Id = item.Id, Date = DateTime.Now, Text = item.Text, Title = item.Title }; Db.Save(article); item.Id = article.Id; }
/// <summary> /// method for checking and storing the articles /// </summary> private void StoreArticleExecute() { try { Delegate d = new Delegate(); using (WarehouseEntities1 context = new WarehouseEntities1()) { int id = 0; for (int i = 0; i < ListOfArticles.Count; i++) { // checking if the article is already stored if (ListOfArticles[i].Stored == true) { continue; } else { // checking the amount of the article and displaying messages with delegate and event if (ListOfArticles[i].Amount > 100) { d.WarehouseFull(ListOfArticles[i].Article); } else { id = ListOfArticles[i].ArticleID; tblArticle article = (from x in context.tblArticles where x.ArticleID == id select x).First(); article.Stored = true; MessageBox.Show("Article '" + article.Article + "' is stored."); } } } context.SaveChanges(); ListOfArticles = GetAllArticles().ToList(); } } catch (Exception) { MessageBox.Show("Something went wrong, please try again"); } }
public ActionResult Action(tblArticle objSubmit) { if (objSubmit.ID == 0) { objSubmit.DateCreated = DateTime.Now; objSubmit.DateUpdated = DateTime.Now; objSubmit.IsDeleted = false; objSubmit.IsShow = true; } else { objSubmit.DateUpdated = DateTime.Now; } return(Json(new { Error = false }, JsonRequestBehavior.AllowGet)); }
public void EditArticle() { tblArticle model = new tblArticle(); using (DbModel db = new DbModel()) { model.ArticleId = db.Articles.Where(x => x.ArticleName == this.ArticleName).Select(x => x.ArticleId).FirstOrDefault(); model.ArticleName = this.ArticleName; model.ArticleDescription = this.ArticleDescription; model.Price = this.Price; model.ArticleCategory = this.ArticleCategory; if (!db.Categories.Any(x => x.CategoryName == this.ArticleCategory)) { AddNewCategory(); } db.Entry(model).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } }
/// <summary> /// method for editing the article /// </summary> private void SaveExecute() { try { using (WarehouseEntities1 context = new WarehouseEntities1()) { int id = article.ArticleID; // finding the article with the ID tblArticle newArticle = (from x in context.tblArticles where x.ArticleID == id select x).First(); if (article.Article.All(Char.IsLetter)) { newArticle.Article = article.Article; } else { MessageBox.Show("Wrong article name input, please try again."); } newArticle.Code = article.Code; newArticle.Amount = article.Amount; newArticle.Price = article.Price; newArticle.Stored = false; newArticle.ArticleID = article.ArticleID; context.SaveChanges(); IsUpdateArticle = true; } editArticle.Close(); } catch (Exception) { MessageBox.Show("Wrong inputs, please try again."); } }
private string loadArticle(string articleId, string parentDirId , ref articlesViewModel viewModel) { string ret = ""; // load directories tblArticle tbart = new tblArticle(); Article parent = null; if (!string.IsNullOrWhiteSpace(articleId)) { Article art = tbart.GetArticleById(articleId); viewModel.articleTitle = art.ArticleTitle; viewModel.articleHtmlContent = art.ArticleHtmlContent; parentDirId = art.BelongToArticleDirId.ToString(); } else { viewModel.articleTitle = ""; } if (!string.IsNullOrWhiteSpace(parentDirId)) { parent = tbart.GetArticleById(parentDirId); } if (parent == null) { viewModel.parentDirId = ""; viewModel.parentDirTitle = ""; } else { viewModel.parentDirId = parent.ArticleId.ToString(); viewModel.parentDirTitle = parent.ArticleTitle; } viewModel.directories = tbart.directoriesByParentArticleId(parentDirId); // load subjects viewModel.subjects = tbart.subjectsByParentArticleId(parentDirId); return(ret); }
/// <summary> /// method for deleting the article /// </summary> private void DeleteArticleExecute() { try { using (WarehouseEntities1 context = new WarehouseEntities1()) { // geting the article id int id = article.ArticleID; // checking if the article can be deleted if (article.Stored == true) { MessageBox.Show("Article can not be deleted, because it is stored."); } else { // confirmation for the action and deleting the article MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure you want to delete the article?", "Delete Confirmation", MessageBoxButton.YesNo); if (messageBoxResult == MessageBoxResult.Yes) { tblArticle articleToDelete = (from x in context.tblArticles where x.ArticleID == id select x).First(); context.tblArticles.Remove(articleToDelete); context.SaveChanges(); ListOfArticles = GetAllArticles().ToList(); } } } } catch (Exception) { MessageBox.Show("The user can not be deleted, please try again."); } }
public ActionResult Articles(articlesViewModel viewModel) { ActionResult ar; var selectedDirectory = Request.Form["selectedDirectory"]; var selectedArticle = Request.Form["selectedArticle"]; if (!string.IsNullOrWhiteSpace(selectedDirectory)) { string[] dirs = selectedDirectory.Split(','); viewModel.selectedDirId = new List <string>(dirs); } if (!string.IsNullOrWhiteSpace(selectedArticle)) { string[] arts = selectedArticle.Split(','); viewModel.selectedArticleId = new List <string>(arts); } var confirmDelete = TempData["confirmDelete"]; var tmpVM = TempData["articlesViewModel"]; articlesViewModel tmpViewModel = null; if (tmpVM != null) { tmpViewModel = (articlesViewModel)tmpVM; if (confirmDelete != null && (int)confirmDelete == 1) { viewModel.selectedDirId = tmpViewModel.selectedDirId; viewModel.selectedArticleId = tmpViewModel.selectedArticleId; } } string err = loadArticle(viewModel.articleId, viewModel.parentDirId, ref viewModel); viewModel.errorMsg = err; articleEditViewModel aevm; tblArticle ta; article art; switch (viewModel.cmd) { case "create": aevm = new articleEditViewModel(); if (!string.IsNullOrWhiteSpace(viewModel.parentDirId)) { aevm.editModel.belongToArticleDirId = Guid.Parse(viewModel.parentDirId); ta = new tblArticle(); art = ta.GetArticleById(viewModel.parentDirId); aevm.parentDirTitle = art.articleTitle; } aevm.changeMode = ARTICLE_CHANGE_MODE.CREATE; aevm.pageStatus = (int)modelsfwk.PAGE_STATUS.ADD; TempData["articleEditViewModel"] = aevm; ar = RedirectToAction("EditArticle"); return(ar); case "edit": ta = new tblArticle(); art = ta.GetArticleById(viewModel.articleId); //aevm = jsonUtl.decodeJson<articleEditViewModel>(jsonUtl.encodeJson(art)); aevm = new articleEditViewModel(); aevm.editModel = art; if (art == null || art.belongToArticleDirId == null) { aevm.parentDirTitle = EMPTY_PARENT_TITLE; } else { article artParent = ta.GetArticleById(art.belongToArticleDirId.ToString()); aevm.parentDirTitle = artParent.articleTitle; } aevm.changeMode = ARTICLE_CHANGE_MODE.EDIT; aevm.pageStatus = (int)modelsfwk.PAGE_STATUS.EDIT; TempData["articleEditViewModel"] = aevm; ar = RedirectToAction("EditArticle"); return(ar); case "replyTo": aevm = new articleEditViewModel(); aevm.editModel.belongToArticleDirId = new Guid(viewModel.articleId); aevm.parentDirTitle = viewModel.articleTitle; aevm.changeMode = ARTICLE_CHANGE_MODE.REPLY_TO; aevm.pageStatus = (int)modelsfwk.PAGE_STATUS.ADD; TempData["articleEditViewModel"] = aevm; ar = RedirectToAction("EditArticle"); return(ar); case "parentDir": ar = RedirectToAction("Articles", new { articleId = viewModel.parentDirId }); return(ar); case "delete": // delete confirm if (viewModel.selectedDirId.Count > 0 || viewModel.selectedArticleId.Count > 0) { ViewBag.confirmDelete = "1"; TempData["confirmDelete"] = 1; } ar = View(viewModel); break; case "realDelete": // to real delete //SASDdbBase db = new SASDdbBase(); string err1 = ""; tblArticle tart = new tblArticle(); DbContextTransaction transaction = tart.BeginTransaction(); try { foreach (string articleId in viewModel.selectedDirId) { err1 = tart.DeleteArticleOrDir(articleId); if (err1.Length > 0) { throw new Exception(err1); } } foreach (string articleId in viewModel.selectedArticleId) { err1 = tart.DeleteArticleOrDir(articleId); if (err1.Length > 0) { throw new Exception(err1); } } tart.SaveChanges(); transaction.Commit(); viewModel.successMsg = "selected directory(s) or article(s) successfully deleted"; } catch (Exception ex) { transaction.Rollback(); viewModel.errorMsg += ex.Message; viewModel.successMsg = ""; } err = loadArticle(viewModel.articleId, viewModel.parentDirId, ref viewModel); viewModel.errorMsg += err; // at last no matter what result, clear selection viewModel.selectedDirId.Clear(); viewModel.selectedArticleId.Clear(); ar = View(viewModel); break; default: ar = View(viewModel); break; } TempData["articlesViewModel"] = viewModel; return(ar); }
// constructor public EditArticleViewModel(EditArticleView editArticleOpen, tblArticle tblArticle) { article = tblArticle; editArticle = editArticleOpen; }
public ActionResult EditArticle(articleEditViewModel viewModel) { ActionResult ret; ViewBag.articleTypeOption = SAdropdownOptions.articleTypeOption(); ViewBag.articleStatusOption = SAdropdownOptions.articleStatusOption(); ViewBag.articlePriorityOption = SAdropdownOptions.articlePriorityOption(); ViewBag.userList = PMdropdownOption.userList(); string err; // articles, ckeditor, paste base64 image switch (viewModel.cmd) { case "save": err = checkForm(viewModel); if (err.Length > 0) { viewModel.errorMsg = err; ret = View(viewModel); break; } //article article2add = new article(); //article2add.ArticleId = Guid.NewGuid(); //article2add.ArticleTitle = // viewModel.ArticleTitle; //article2add.ArticleHtmlContent = // viewModel.ArticleHtmlContent; string pureText; err = htmlHelper.removeHtmlTags( viewModel.editModel.articleHtmlContent, out pureText); if (err.Length > 0) { viewModel.errorMsg = err; ret = View(viewModel); break; } viewModel.editModel.articleContent = pureText; //article2add.IsDir = viewModel.IsDir ; tblArticle tArticle = new tblArticle(); if (viewModel.changeMode == ARTICLE_CHANGE_MODE.CREATE) { viewModel.editModel.articleId = Guid.NewGuid(); viewModel.editModel.createtime = DateTime.Now; //article art = new article(); //art.articleId = viewModel.articleId; //art.createtime = DateTime.Now; //art.articleTitle = viewModel.articleTitle; //art.articleHtmlContent = viewModel.articleHtmlContent; //art.articleContent = viewModel.articleContent; //art.isDir = viewModel.isDir; //art.belongToArticleDirId = viewModel.belongToArticleDirId; err = tArticle.Add(viewModel.editModel); // as article); err += tArticle.SaveChanges(); if (err.Length > 0) { viewModel.errorMsg = "error: " + err; } else { viewModel.successMsg = "new article successfully added"; viewModel.pageStatus = (int)modelsfwk.PAGE_STATUS.ADDSAVED; } } else if (viewModel.changeMode == ARTICLE_CHANGE_MODE.EDIT) { err = tArticle.Update(viewModel.editModel); err += tArticle.SaveChanges(); if (err.Length > 0) { viewModel.errorMsg = "error: " + err; } else { viewModel.successMsg = "article successfully updated"; viewModel.pageStatus = (int)modelsfwk.PAGE_STATUS.SAVED; } } else if (viewModel.changeMode == ARTICLE_CHANGE_MODE.REPLY_TO) { // transaction, 1. create replied article 2. change original article to be directory type string err1 = ""; SASDdbBase db = new SASDdbBase(); using (var transaction = db.BeginTransaction()) { viewModel.editModel.articleId = Guid.NewGuid(); viewModel.editModel.createtime = DateTime.Now; err1 = tArticle.Add(viewModel.editModel); // as article); err1 += tArticle.SaveChanges(); tblArticle tart = new tblArticle(); article replied = tart.GetArticleById(viewModel.editModel.belongToArticleDirId.ToString()); replied.isDir = true; err1 += tart.Update(replied); err1 += tart.SaveChanges(); if (err1.Length == 0) { transaction.Commit(); } else { err += err1; } } if (err.Length > 0) { viewModel.errorMsg = "error: " + err; } else { viewModel.successMsg = "new article successfully added"; viewModel.pageStatus = (int)modelsfwk.PAGE_STATUS.ADDSAVED; } } // notification failed, so, should use pure hidden field rather than html helped //ViewBag.Message = "article/directory saved"; ret = View(viewModel); break; default: ret = View(viewModel); break; } TempData["articleEditViewModel"] = viewModel; return(ret); }
public IActionResult EditArticle(articleEditViewModel viewModel) { IActionResult ret; string err; //todo !!... edit article // articles, ckeditor, paste base64 image object obj = Request.Form; switch (viewModel.cmd) { case "save": err = checkForm(viewModel); if (err.Length > 0) { viewModel.errorMsg = err; ret = View(viewModel); break; } //Article article2add = new Article(); //article2add.ArticleId = Guid.NewGuid(); //article2add.ArticleTitle = // viewModel.ArticleTitle; //article2add.ArticleHtmlContent = // viewModel.ArticleHtmlContent; string pureText; err = htmlHelper.removeHtmlTags( viewModel.ArticleHtmlContent, out pureText); if (err.Length > 0) { viewModel.errorMsg = err; ret = View(viewModel); break; } viewModel.ArticleContent = pureText; //article2add.IsDir = viewModel.IsDir ; tblArticle tArticle = new tblArticle(); if (viewModel.changeMode == ARTICLE_CHANGE_MODE.CREATE) { viewModel.ArticleId = Guid.NewGuid(); err = tArticle.Add(viewModel); err += tArticle.SaveChanges(); } else if (viewModel.changeMode == ARTICLE_CHANGE_MODE.EDIT) { err = tArticle.Update(viewModel); err += tArticle.SaveChanges(); } else if (viewModel.changeMode == ARTICLE_CHANGE_MODE.REPLY_TO) { // transaction, 1. create replied article 2. change original article to be directory type SASDdbBase db = new SASDdbBase(); using (var transaction = db.BeginTransaction()) { viewModel.ArticleId = Guid.NewGuid(); err = tArticle.Add(viewModel); err += tArticle.SaveChanges(); tblArticle tart = new tblArticle(); Article replied = tart.GetArticleById(viewModel.BelongToArticleDirId.ToString()); replied.IsDir = true; tart.Update(replied); tart.SaveChanges(); transaction.Commit(); } } if (err.Length > 0) { viewModel.errorMsg = err; } else { viewModel.successMsg = "new article successfully added"; } //undone !!... notification failed //todo !!...proceed to save article/directory //ViewBag.Message = "article/directory saved"; ret = View(viewModel); break; default: ret = View(viewModel); break; } TempData["articleEditViewModel"] = jsonUtl.encodeJson(viewModel); return(ret); }
public bool ReadLink(ArticleAutoItem objTypeAuto, string linkRead, int TypeID, string groupID, int page = 1) { try { var linkImage = string.Empty; var url = new Uri(objTypeAuto.Link); var web = new HtmlWeb(); // load link var doc = web.Load(linkRead); var aTags = doc.DocumentNode.SelectSingleNode(page > 1 ? objTypeAuto.XpathPaging : objTypeAuto.Xpath); if (aTags != null) { var htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(aTags.InnerHtml); // get tags a of xpath var listA = htmlDoc.DocumentNode.SelectNodes(".//a"); if (listA != null) { // check link content foreach (var item in listA.Where(t => t.Attributes["href"] != null)) { try { var link = item.Attributes["href"].Value; if (!item.Attributes["href"].Value.Contains(url.Host)) { link = url.Scheme + "://" + url.Host + link; } var docDetail = web.Load(link); var htmlDocDetail = new HtmlDocument(); htmlDocDetail.LoadHtml(item.InnerHtml); // get image default news if image exits var img = htmlDocDetail.DocumentNode.SelectNodes(".//img"); if (img != null) { // image src var imgDetail = img.FirstOrDefault().Attributes["src"].Value; if (!imgDetail.Contains(url.Scheme + "//") && !imgDetail.Contains("https://") && !imgDetail.Contains("http://")) { imgDetail = url.Scheme + "://" + url.Host + imgDetail; } linkImage = imgDetail; } var linkRefer = link; if (docDetail.DocumentNode.SelectNodes(objTypeAuto.XpathTitle) == null) { continue; } var title = docDetail.DocumentNode.SelectNodes(objTypeAuto.XpathTitle)[0].InnerHtml.Trim(); var titleAscii = Web365Utility.Web365Utility.ConvertToAscii(title); var objExits = articleRepository.GetItemByTitleAscii(titleAscii); if (objExits != null) { if (string.IsNullOrEmpty(objExits.LinkReferenPicture) && !string.IsNullOrEmpty(linkImage)) { objExits.LinkReferenPicture = linkImage; articleRepository.Update(objExits); } continue; } string summary; try { if (string.IsNullOrEmpty(objTypeAuto.XpathSummary)) { summary = string.Empty; } else { summary = Web365Utility.Web365Utility.RemoveStyleInHtmlTag(docDetail.DocumentNode.SelectNodes(objTypeAuto.XpathSummary)[0].InnerHtml); } } catch (Exception e) { summary = string.Empty; WriteLogs("Error read Sumary " + item.Attributes["href"].Value + "AutoID : " + objTypeAuto.ID); } string detail; try { if (string.IsNullOrEmpty(objTypeAuto.XpathDetail)) { detail = string.Empty; } else { detail = Web365Utility.Web365Utility.RemoveStyleInHtmlTag(docDetail.DocumentNode.SelectNodes(objTypeAuto.XpathDetail)[0].InnerHtml); if (string.IsNullOrEmpty(linkImage)) { try { htmlDocDetail.LoadHtml(detail); } catch (Exception ex) { WriteLogs("Error read Detail" + item.Attributes["href"].Value + "AutoID : " + objTypeAuto.ID); } // get image default news if image exits var imgDetailContent = htmlDocDetail.DocumentNode.SelectNodes(".//img"); if (imgDetailContent != null) { try { // image src details var imgDetailSrc = imgDetailContent.FirstOrDefault().Attributes["src"].Value; if (!imgDetailSrc.Contains(url.Scheme + "//") && !imgDetailSrc.Contains("https://") && !imgDetailSrc.Contains("http://")) { imgDetailSrc = url.Scheme + "://" + url.Host + imgDetailSrc; } linkImage = imgDetailSrc; } catch (Exception ex) { WriteLogs("Error read images Detail" + item.Attributes["href"].Value + "AutoID : " + objTypeAuto.ID); } } } } } catch (Exception ex) { WriteLogs("Error " + item.Attributes["href"].Value + "AutoID : " + objTypeAuto.ID); detail = string.Empty; } var objNews = new tblArticle { DateCreated = DateTime.Now, DateUpdated = DateTime.Now, SEOTitle = title, SEOKeyword = title, SEODescription = title, Number = 0, TypeID = TypeID, IsDeleted = false, IsShow = true, Title = title, TitleAscii = titleAscii, Summary = summary, Detail = detail, LinkReferenPicture = linkImage, LinkReference = linkRefer }; autoArticleRepository.Add(objNews); articleGroupMapRepository.ResetGroupOfNews(objNews.ID, Web365Utility.Web365Utility.StringToArrayInt(groupID)); } catch (Exception ex) { WriteLogs("Error " + item.Attributes["href"].Value + "AutoID : " + objTypeAuto.ID); Elmah.ErrorLog.GetDefault(System.Web.HttpContext.Current).Log(new Elmah.Error(ex)); } } } } else { WriteLogs("Can't read tags <a> with link " + linkRead + "AutoID : " + objTypeAuto.ID); return(false); } } catch (Exception) { WriteLogs("Error " + linkRead + "AutoID : " + objTypeAuto.ID); return(false); } return(true); }
public IActionResult Articles(articlesViewModel viewModel) { IActionResult ret; var selectedArticle = Request.Form["selectedArticle"]; string err = loadArticle(viewModel.articleId, viewModel.parentDirId, ref viewModel); viewModel.errorMsg = err; articleEditViewModel aevm; tblArticle ta; Article art = null; switch (viewModel.cmd) { case "create": //if (viewModel.editingArticle==null || // viewModel.editingArticle.BelongToArticleDirId==null) //{ // //todo !!... show error message // ret = View(viewModel); // break; //} //string BelongToArticleDirId = viewModel.parentDirId; aevm = new articleEditViewModel(); if (!string.IsNullOrWhiteSpace(viewModel.parentDirId)) { aevm.BelongToArticleDirId = Guid.Parse(viewModel.parentDirId); ta = new tblArticle(); art = ta.GetArticleById(viewModel.parentDirId); aevm.parentDirTitle = art.ArticleTitle; } aevm.changeMode = ARTICLE_CHANGE_MODE.CREATE; TempData["articleEditViewModel"] = jsonUtl.encodeJson(aevm); //viewModel.editingArticle = new Article(); //if (!string.IsNullOrWhiteSpace(BelongToArticleDirId)) // viewModel.editingArticle.BelongToArticleDirId = Guid.Parse(BelongToArticleDirId); ret = RedirectToAction("EditArticle"); break; case "edit": //if (viewModel.editingArticle == null || // viewModel.editingArticle.BelongToArticleDirId == null) //{ // //todo !!... show error message // ret = View(viewModel); // break; //} ta = new tblArticle(); art = ta.GetArticleById(viewModel.articleId); aevm = jsonUtl.decodeJson <articleEditViewModel>(jsonUtl.encodeJson(art)); //aevm = new articleEditViewModel(); if (art == null || art.BelongToArticleDirId == null) { aevm.parentDirTitle = EMPTY_PARENT_TITLE; } else { Article artParent = ta.GetArticleById(art.BelongToArticleDirId.ToString()); aevm.parentDirTitle = artParent.ArticleTitle; } // undone !!... there is a huge big issue here, if there is image base64, then edit will crash, then crash the whole web project //aevm.ArticleContent = null; //aevm.ArticleHtmlContent = null; aevm.changeMode = ARTICLE_CHANGE_MODE.EDIT; string json = jsonUtl.encodeJson(aevm); TempData["articleEditViewModel"] = json; ret = RedirectToAction("EditArticle"); break; case "replyTo": aevm = new articleEditViewModel(); aevm.BelongToArticleDirId = new Guid(viewModel.articleId); aevm.parentDirTitle = viewModel.articleTitle; aevm.changeMode = ARTICLE_CHANGE_MODE.REPLY_TO; TempData["articleEditViewModel"] = jsonUtl.encodeJson(aevm); ret = RedirectToAction("EditArticle"); break; case "delete": //todo !!.. delete confirm ViewBag.confirmDelete = "1"; ret = View(viewModel); break; case "realDelete": //todo !!.. to real delete ret = View(viewModel); break; default: ret = View(viewModel); break; } TempData["articlesViewModel"] = jsonUtl.encodeJson(viewModel); return(ret); }
public EditArticleView(tblArticle article) { InitializeComponent(); this.DataContext = new EditArticleViewModel(this, article); }
// constructor public AddArticleViewModel(AddArticleView articleOpen) { article = new tblArticle(); addArticle = articleOpen; }