Example #1
0
 protected virtual void PrepareArticlePostModel(ArticlePostModels model, ArticlePost articlePost, bool prepareComments)
 {
     if (articlePost == null)
     {
         throw new ArgumentNullException("articlePost");
     }
     if (model == null)
     {
         throw new ArgumentNullException("model");
     }
     model.Id              = articlePost.Id;
     model.Title           = articlePost.Title;
     model.Body            = articlePost.Body;
     model.MetaDescription = articlePost.MetaDescription;
     model.CreatedOnUtc    = articlePost.CreatedOnUtc;
     model.MetaKeywords    = articlePost.MetaKeywords;
     model.MetaTitle       = articlePost.MetaTitle;
     model.Tags            = articlePost.Tags;
     if (prepareComments)
     {
         var articleComments = articlePost.ArticleComments.OrderBy(pr => pr.CreatedOnUtc);
         foreach (var ac in articleComments)
         {
             var commentModel = new ArticleCommentModels
             {
                 Id           = ac.Id,
                 MemberId     = ac.MemberId,
                 MemberName   = ac.Member.UName,
                 CommentText  = ac.CommentText,
                 CreatedOnUtc = ac.CreatedOnUtc
             };
             model.Comments.Add(commentModel);
         }
     }
 }
        public async Task <IActionResult> AddArticle([FromBody] ArticlePost a)
        {
            // TODO Use different class for input and convert to db class
            if (String.IsNullOrWhiteSpace(a.Text) || String.IsNullOrWhiteSpace(a.Title))
            {
                // Title and text cannot be empty
                // TODO Add Other checks
                return(NotFound());
            }

            // string imageId = null;
            // if (a.Image != null)
            // {
            //     imageId = _imageService
            //         .StoreImage(a.Image.OpenReadStream(),
            //                                     a.Image.FileName);
            // }
            //
            var article = new Article()
            {
                Date  = DateTime.Now,
                Title = a.Title,
                Text  = a.Text,
            };


            _unitOfWork.Articles.Add(article);
            _unitOfWork.Save();
            return(Json(article));
        }
Example #3
0
        public bool insertArticlePost(ArticlePost articlePost)
        {
            try
            {
                _postContext.ArticlePostRepository.Create(articlePost);
                _postContext.Commit();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Example #4
0
        public ActionResult Show(int id)
        {
            ArticlePost ap = _articlePostService.GetById(id);

            if (ap == null)
            {
                return(Redirect("Index"));
            }

            var model = new ArticlePostModels();

            PrepareArticlePostModel(model, ap, true);
            ViewBag.Title       = model.Title;
            ViewBag.Keywords    = model.MetaKeywords;
            ViewBag.Description = model.MetaDescription;
            return(View(model));
        }
        public async Task <IActionResult> UpdateArticle(string id, [FromBody] ArticlePost a)
        {
            if (String.IsNullOrWhiteSpace(a.Text) || String.IsNullOrWhiteSpace(a.Title))
            {
                // Title and text cannot be empty
                // TODO Add Other checks
                return(NotFound());
            }

            var article = new Article()
            {
                Id    = id,
                Date  = DateTime.Now,
                Title = a.Title,
                Text  = a.Text
            };

            _unitOfWork.Articles.Update(article);
            _unitOfWork.Save();
            return(Json(article));
        }
Example #6
0
        public ActionResult Add(ArticlePostModels model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var m = new ArticlePost()
                    {
                        Title           = model.Title,
                        Body            = model.Body,
                        AllowComments   = true,
                        CreatedOnUtc    = DateTime.Now,
                        MetaDescription = model.MetaDescription,
                        MetaKeywords    = model.MetaKeywords,
                        MetaTitle       = model.MetaTitle,
                        CommentCount    = 0,
                        Intro           = model.Intro,
                        Tags            = model.Tags
                    };
                    _articlePostService.Add(m);
                    if (m.Id > 0)
                    {
                        return(View("Add", model));
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex);
                }

                //return RedirectToAction("Index", "Home");
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }