Beispiel #1
0
        public ActionResult CreateArticle(string editorContent, string tagSelect, string stringTitle)
        {
            var appliedTagList = JsonConvert.DeserializeObject<string[]>(tagSelect);
            int arId = 0;
            if (ModelState.IsValid)
            {
                Article article = new Article();

                article.Title = stringTitle;
                while (editorContent.EndsWith("<br>"))
                    editorContent = editorContent.Substring(0, editorContent.Length - 4);
                article.Content = editorContent.Trim('\r', '\n', ' ');
                article.UserId = User.Identity.GetUserId<int>();
                article.CreateDate = DateTime.Now;
                article.isActive = true;
                article.View = 0;

                db.Articles.Add(article);
                db.SaveChanges();
                arId = article.Id;
                if (appliedTagList != null)
                {
                    foreach (var item in appliedTagList)
                    {
                        AppliedTagArticle appliedTag = new AppliedTagArticle();
                        appliedTag.ArticleId = article.Id;
                        appliedTag.TagId = Int32.Parse(item);
                        //appliedTag.TaggingUser = WebSecurity.CurrentUserId;
                        appliedTag.AppliedDate = DateTime.Now;
                        db.AppliedTagArticles.Add(appliedTag);
                        db.SaveChanges();
                    }
                }
            }
            return Json(arId, JsonRequestBehavior.AllowGet);
        }
Beispiel #2
0
        public ActionResult EditArticle(string articleId, string editorContent, string tagSelect, string stringTitle)
        {
            int id = Int32.Parse(articleId);
            var appliedTagList = JsonConvert.DeserializeObject<string[]>(tagSelect);
            if (ModelState.IsValid)
            {
                Article article = (from qt in db.Articles
                                   where qt.Id == id && qt.isActive == true
                                   select qt).FirstOrDefault();

                article.Title = stringTitle;
                while (editorContent.EndsWith("<br>"))
                    editorContent = editorContent.Substring(0, editorContent.Length - 4);
                article.Content = editorContent.Trim('\r', '\n', ' ');
                article.CreateDate = DateTime.Now;
                article.isActive = true;
                //asking. = 0;

                db.Entry(article).State = EntityState.Modified;
                db.SaveChanges();

                // Delete applied tags in question
                var appliedTags = (from apTag in db.AppliedTagArticles
                                   where apTag.ArticleId == id
                                   select apTag).ToList();
                foreach (var item in appliedTags)
                {
                    var delTag = db.AppliedTagArticles.Where(a => a.ArticleId == id
                                                                        && a.TagId == item.TagId).Single();
                    db.AppliedTagArticles.Remove(delTag);
                }
                db.SaveChanges();
                //Save Applied tags
                if (appliedTagList != null)
                {
                    foreach (var item in appliedTagList)
                    {
                        AppliedTagArticle appliedTag = new AppliedTagArticle();
                        appliedTag.ArticleId = article.Id;
                        appliedTag.TagId = Int32.Parse(item);
                        //appliedTag.TaggingUser = WebSecurity.CurrentUserId;
                        appliedTag.AppliedDate = DateTime.Now;
                        db.AppliedTagArticles.Add(appliedTag);
                        db.SaveChanges();
                    }
                }
            }
            return Json(id, JsonRequestBehavior.AllowGet);
        }