public void CreateArticle(Articles article)
 {
     article.dateCreated = DateTime.Now;
     Users user = _userService.CheckSession();
     if (user != null)
     {
         article.userid = user.userId;
         _dataModel.AddToArticles1(article);
         _dataModel.SaveChanges();
     }
 }
        public void EditArticle(Articles article)
        {
            var originalArticle = (from a in _dataModel.Articles1 where a.articleId == article.articleId select a).First();
            if (originalArticle.datePublished.HasValue)
            {
                article.datePublished = originalArticle.datePublished;
            }
            article.dateCreated = originalArticle.dateCreated;

            _dataModel.ApplyCurrentValues(originalArticle.EntityKey.EntitySetName, article);
            _dataModel.SaveChanges();
        }
        public ActionResult Create(FormCollection form, string submitButton)
        {
            ViewData["articleTypeId_0"] = new SelectList(CreateArticleTypeList(0), "Value", "Text");
            try
            {
                var article = new Articles()
                {

                    articleTypeId = Convert.ToInt32(form["articleTypeId_0"]),
                    body = form["Body"],
                    dateCreated = DateTime.Now,
                    headline = form["headline"],
                    strapline = form["strapline"]
                };

                _articleService.CreateArticle(article);
                Publish(form, submitButton, article);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        /**** Published Articles ****/
        public void PublishArticle(Articles article)
        {
            PublishedArticles articleToPublish = new PublishedArticles()
            {
                articleId = article.articleId,
                articleTypeId = article.articleTypeId,
                body = article.body,
                headline = article.headline,
                strapline = article.strapline,
                userid = article.userid,
                datePublished = article.datePublished,
                isPublished = true
            };
            var originalPublishedArticle = (from pa in _dataModel.PublishedArticles where pa.articleId == article.articleId select pa);
            if (originalPublishedArticle.Count() > 0)
            {
                _dataModel.ApplyCurrentValues(originalPublishedArticle.First().EntityKey.EntitySetName, articleToPublish);
            }
            else
            {
                _dataModel.AddToPublishedArticles(articleToPublish);

            }
            _dataModel.SaveChanges();
        }
 public Articles ExtendArticle(Articles article)
 {
     article.user = (from u in _userService.GetList() where u.userId == article.userid select u).First();
     article.articleType = (from at in new ArticleTypeService().GetArticleTypesList() where at.articleTypeId == article.articleTypeId select at).First();
     return article;
 }
 /// <summary>
 /// Create a new Articles object.
 /// </summary>
 /// <param name="articleId">Initial value of the articleId property.</param>
 /// <param name="dateCreated">Initial value of the dateCreated property.</param>
 /// <param name="isPublished">Initial value of the isPublished property.</param>
 public static Articles CreateArticles(global::System.Int32 articleId, global::System.DateTime dateCreated, global::System.Boolean isPublished)
 {
     Articles articles = new Articles();
     articles.articleId = articleId;
     articles.dateCreated = dateCreated;
     articles.isPublished = isPublished;
     return articles;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Articles1 EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToArticles1(Articles articles)
 {
     base.AddObject("Articles1", articles);
 }
Beispiel #8
0
 public Articles ExtendArticle(Articles article)
 {
     article.user        = (from u in _userService.GetList() where u.userId == article.userid select u).First();
     article.articleType = (from at in new ArticleTypeService().GetArticleTypesList() where at.articleTypeId == article.articleTypeId select at).First();
     return(article);
 }
        public ActionResult Edit(FormCollection form, string submitButton)
        {
            var article = new Articles()
            {
                articleTypeId = Convert.ToInt32(form["articleTypeId_0"]),
                articleId = Convert.ToInt32(form["articleId"]),
                body = form["Body"],
                dateCreated = DateTime.Now,
                headline = form["headline"],
                strapline = form["strapline"],
                userid = new Guid(form["userid"])
            };
            Publish(form, submitButton, article);

            return RedirectToAction("Index");
        }
 private void Publish(FormCollection form, string submitButton, Articles article)
 {
     if (submitButton.Contains("Publish"))
     {
         article.datePublished = GetDatePublished(form);
         article.isPublished = true;
         _articleService.PublishArticle(article);
     }
     _articleService.EditArticle(article);
 }