예제 #1
0
        public async Task <ISingleResponse <Article> > CreateArticle(Article article)
        {
            ISingleResponse <Article> response = new SingleResponse <Article>()
            {
                IsSuccess = false
            };

            try
            {
                if (string.IsNullOrWhiteSpace(article.Title) || string.IsNullOrWhiteSpace(article.FirstParagraph))
                {
                    response.Message = "An article must has title and first paragraph filled in";
                    return(response);
                }

                article.Id = null;
                response   = await _articleRepository.CreateArticle(article);
            }
            catch (Exception e)
            {
                response.IsSuccess = false;
                response.Message   = e.Message;
            }

            return(response);
        }
예제 #2
0
 public ActionResult CreateArticle(ArticleModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             articleRepository.CreateArticle(model.Title, model.Preview, model.Content, model.URL, model.MetaKeywords,
                                             model.MetaDescription, model.PublicationDate, model.IsRemove);
             return(RedirectToAction("AllArticles"));
         }
         return(View(model));
     }
     catch
     {
         //throw new Exception("Невозможно добавить страницу");
         return(View());
     }
 }