public static bool UpdateArticle(DBO.Article article) { using (IziWatchEntities bdd = new IziWatchEntities()) { try { T_Article t_article = bdd.T_Article.Where(x => x.id == article.Id).FirstOrDefault(); if (t_article != null) { t_article.id = article.Id; t_article.title = article.Title; t_article.image = article.Image; t_article.category_id = article.CategoryId; t_article.text = article.Text; t_article.date = article.Date; t_article.views = article.Views; bdd.SaveChanges(); return(true); } else { return(false); } } catch (Exception e) { return(false); } } }
public ActionResult CreateArticleSocialNetwork(DBO.Article article) { DBO.Article newArticle = new DBO.Article() { Title = Request["title"], Image = Request["image"], CategoryId = int.Parse(Request["category"]), Text = Request["text"], Date = DateTime.Now }; String error = checkArticle(newArticle); if (error == null) { BusinessManagement.Article.CreateArticle(newArticle); BusinessManagement.SocialArticle.DeleteSocialArticle(int.Parse(Request["socialArticleId"])); } ViewBag.socialArticleId = int.Parse(Request["socialArticleId"]); ViewBag.error = error; ViewBag.categories = BusinessManagement.Category.GetListCategory(); ViewBag.partialArticle = newArticle; ViewBag.postData = true; return(View()); }
public static List <DBO.Article> GetListArticleByText(string word) { List <DBO.Article> result = new List <DBO.Article>(); try { using (MeditateBookEntities bdd = new MeditateBookEntities()) { List <T_Article> list = bdd.T_Article.Where(x => x.content.Contains(word) || x.title.Contains(word)).ToList(); foreach (T_Article article in list) { DBO.Article newArticle = new DBO.Article() { Id = article.id, Title = article.title, Content = article.content, CreatedDate = article.created_date, Validated = article.validated, IdCreator = article.id_creator }; result.Add(newArticle); } return(result); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); return(result); } }
public static bool UpdateArticle(DBO.Article article) { try { using (MeditateBookEntities bdd = new MeditateBookEntities()) { T_Article oldarticle = bdd.T_Article.Where(x => x.id == article.Id).FirstOrDefault(); if (oldarticle != null) { oldarticle.title = article.Title; oldarticle.content = article.Content; oldarticle.id_creator = article.IdCreator; oldarticle.validated = article.Validated; oldarticle.created_date = article.CreatedDate; bdd.SaveChanges(); return(true); } return(false); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); return(false); } }
public static bool CreateArticle(ref DBO.Article article) { try { using (MeditateBookEntities bdd = new MeditateBookEntities()) { T_Article newArticle = new T_Article() { title = article.Title, content = article.Content, id_creator = article.IdCreator, created_date = article.CreatedDate, validated = article.Validated }; bdd.T_Article.Add(newArticle); bdd.SaveChanges(); article.Id = newArticle.id; return(true); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.ToString()); return(false); } }
public static bool CreateArticle(DBO.Article article) { using (IziWatchEntities bdd = new IziWatchEntities()) { try { T_Article t_article = new T_Article() { id = article.Id, title = article.Title, image = article.Image, category_id = article.CategoryId, text = article.Text, date = article.Date, views = article.Views }; bdd.T_Article.Add(t_article); bdd.SaveChanges(); return(true); } catch (Exception e) { return(false); } } }
public static DBO.Article GetArticle(long id) { try { using (MeditateBookEntities bdd = new MeditateBookEntities()) { T_Article article = bdd.T_Article.Where(x => x.id == id).FirstOrDefault(); if (article != null) { DBO.Article result = new DBO.Article() { Id = article.id, Title = article.title, Content = article.content, CreatedDate = article.created_date, IdCreator = article.id_creator, Validated = article.validated }; return(result); } return(null); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); return(null); } }
public ActionResult Edit([Bind(Include = "Id,Title,Image,CategoryId,Text,Date,Views")] DBO.Article article) { if (ModelState.IsValid) { BusinessManagement.Article.UpdateArticle(article); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(article)); }
private static bool isInList(DBO.Article article, List <DBO.Article> list) { foreach (var articl in list) { if (articl.Id == article.Id) { return(true); } } return(false); }
public static bool LikeArticle(DBO.Article article, DBO.User user) { DBO.Popularity popularity = BusinessManagement.Popularity.GetPopularityByUserAndArticle(article, user); { if (popularity != null) { popularity.Liked = true; return(BusinessManagement.Popularity.UpdatePopularity(popularity)); } } return(false); }
// GET: Articles/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DBO.Article article = BusinessManagement.Article.GetArticle((int)id); if (article == null) { return(HttpNotFound()); } return(View(article)); }
public static DBO.Popularity GetPopularityByUserAndArticle(DBO.Article article, DBO.User user) { List <DBO.Popularity> popularities = BusinessManagement.Popularity.GetListPopularity(); foreach (DBO.Popularity popularity in popularities) { if (popularity.UserId == user.Id && popularity.ArticleId == article.Id) { return(popularity); } } return(null); }
public ActionResult EditTraduction(long id) { DBO.Article article = BusinessManagement.Article.GetArticle(id); TradArticleModel tradModel = new TradArticleModel(); tradModel.titleOriginal = article.Title; tradModel.contentOriginal = article.Content; tradModel.IdOriginal = article.Id; List <DBO.Language> listLanguages = BusinessManagement.Language.GetListLanguage(); tradModel.listLangues = listLanguages; return(View(tradModel)); }
public static int countCommentArticle(DBO.Article article) { List <DBO.Comment> comments = BusinessManagement.Comment.GetListComment(); int countComments = 0; foreach (DBO.Comment comment in comments) { if (comment.ArticleId == article.Id) { ++countComments; } } return(countComments); }
public static List <DBO.Comment> GetCommentsByArticle(DBO.Article article) { List <DBO.Comment> comments = DataAccess.Comment.GetListComment(); List <DBO.Comment> formatedComments = new List <DBO.Comment>(); foreach (DBO.Comment comment in comments) { if (comment.ArticleId == article.Id) { formatedComments.Add(comment); } } return(formatedComments); }
public static int countLikeArticle(DBO.Article article) { List <DBO.Popularity> popularities = BusinessManagement.Popularity.GetListPopularity(); int countLikes = 0; foreach (DBO.Popularity popularity in popularities) { if (popularity.ArticleId == article.Id && popularity.Liked) { ++countLikes; } } return(countLikes); }
public String checkArticle(DBO.Article article) { List <DBO.Category> categories = BusinessManagement.Category.GetListCategory(); String error = null; if (article.Text == "" || article.Title == "" || article.Image == "") { error = "Vous devez remplir tous les champs"; } if (error == null && BusinessManagement.Category.GetCategory(article.CategoryId) == null) { error = "La catégorie spécifiée est introuvable."; } return(error); }
public static List <Tuple <DBO.Article, List <DBO.Language> > > GetListArticleWithMissingTrans() { List <Tuple <DBO.Article, List <DBO.Language> > > result = new List <Tuple <DBO.Article, List <DBO.Language> > >(); try { using (MeditateBookEntities bdd = new MeditateBookEntities()) { var list = bdd.T_Article.GroupJoin(bdd.T_Translation, article => article.id, translation => translation.id_article, (article, translation) => new { article, translation }).ToList(); foreach (var elm in list) { List <DBO.Language> languages = Language.GetListLanguage(); if (elm.translation.Count() != languages.Count) { DBO.Article newArticle = new DBO.Article() { Id = elm.article.id, Title = elm.article.title, Content = elm.article.content, CreatedDate = elm.article.created_date, Validated = elm.article.validated, IdCreator = elm.article.id_creator }; foreach (var obj in elm.translation) { foreach (var language in languages) { if (obj.id_language == language.Id) { languages.Remove(language); } } } Tuple <DBO.Article, List <DBO.Language> > item = new Tuple <DBO.Article, List <DBO.Language> >(newArticle, languages); result.Add(item); } } return(result); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); return(result); } }
public static bool CreateArticle(DBO.Article article) { bool res = DataAccess.Article.CreateArticle(article); if (res) { DBO.Article newArticle = GetArticleByMaxId(); List <DBO.User> users = BusinessManagement.User.GetListUser(); DBO.Popularity popularity; foreach (DBO.User user in users) { popularity = new DBO.Popularity(); popularity.Liked = false; popularity.Viewed = false; popularity.ArticleId = newArticle.Id; popularity.UserId = user.Id; BusinessManagement.Popularity.CreatePopularity(popularity); } return(true); } return(false); }
public ActionResult EditArticle(EditArticleModel model, HttpPostedFileBase file) { if (!ModelState.IsValid) { return(View(model)); } var result = true; switch (result) { case true: DBO.Article article = new DBO.Article { Title = model.Title, Content = model.Content, Validated = false, CreatedDate = DateTime.Now }; var idCreator = HttpContext.Session["UserID"]; if (idCreator != null) { article.IdCreator = (long)idCreator; } BusinessManagement.Article.CreateArticle(ref article); if (file != null) { string pic = System.IO.Path.GetFileName(file.FileName); string dir = Server.MapPath("~/images/article"); string path = System.IO.Path.Combine(dir, pic); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } // file is uploaded file.SaveAs(path); DBO.ArticleImage image = new DBO.ArticleImage(); image.ImagePath = path; image.Name = pic; image.IdArticle = article.Id; BusinessManagement.ArticleImage.CreateArticleImage(image); } string dirAttach = Server.MapPath("~/images/attach"); int i = 0; if (HttpContext.Session["ListAttach" + i] != null) { while (HttpContext.Session["ListAttach" + i] != null) { DBO.ArticleAttach articleAttach = new DBO.ArticleAttach(); articleAttach.Name = (string)HttpContext.Session["ListAttach" + i]; articleAttach.FilePath = Path.Combine(dirAttach, articleAttach.Name); articleAttach.IdArticle = article.Id; BusinessManagement.ArticleAttach.CreateArticleAttach(articleAttach); i++; } } return(RedirectToAction("Submit", "Articles")); case false: ModelState.AddModelError("", "Insertion d'article invalide"); return(View(model)); default: ModelState.AddModelError("", "Insertion d'article invalide"); return(View(model)); } }
public static bool IncrementArticleViews(DBO.Article article) { article.Views = article.Views + 1; return(DataAccess.Article.UpdateArticle(article)); }
public static bool UpdateArticle(DBO.Article article) { return(DataAccess.Article.UpdateArticle(article)); }
public static bool CreateArticle(ref DBO.Article article) { return(DataAccess.Article.CreateArticle(ref article)); }
public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DBO.User user = BusinessManagement.User.GetUserByUserIdentity(User); DBO.Article article = BusinessManagement.Article.GetArticle((int)id); DBO.Popularity popularity = null; List <DBO.Comment> comments = new List <DBO.Comment>(); int countLikes = 0; bool commentError = false; if (article == null) { return(HttpNotFound()); } else { if (user != null) { if (Request["action"] == "like") { BusinessManagement.Article.LikeArticle(article, user); } else if (Request["action"] == "unlike") { BusinessManagement.Article.UnlikeArticle(article, user); } else if (Request["action"] == "Commenter") { DBO.Comment comment = new DBO.Comment(); comment.Title = Request["commentTitle"]; comment.Text = Request["commentText"]; comment.ArticleId = article.Id; comment.UserId = user.Id; if (comment.Title == "" || comment.Text == "") { commentError = true; } else { BusinessManagement.Comment.CreateComment(comment); } } BusinessManagement.Article.ViewArticle(article, user); popularity = BusinessManagement.Popularity.GetPopularityByUserAndArticle(article, user); } BusinessManagement.Article.IncrementArticleViews(article); comments = BusinessManagement.Comment.GetCommentsByArticle(article); countLikes = BusinessManagement.Popularity.countLikeArticle(article); } ViewBag.userConnected = user; ViewBag.article = article; ViewBag.comments = comments; ViewBag.popularity = popularity; ViewBag.countLikes = countLikes; ViewBag.pageUrl = Request.Url; ViewBag.commentError = commentError; ViewBag.tweet_text = "https://twitter.com/intent/tweet?text=" + article.Title.Substring(0, @article.Title.Length).Replace(" ", "%20"); return(View()); }