예제 #1
0
        public int Publish(ArticleNewModel articleNewModel)
        {
            if (GetCurrentUser() == null)
            {
                throw new ArgumentException(" 当前用户参数发生异常");
            }
            string[] container = articleNewModel.Keywords.Split(' ');
            Article  article   = mapper.Map <Article>(articleNewModel);

            article.Publish();
            article.Author   = GetCurrentUser();
            article.KeyWords = new List <Keyword>();
            for (int i = 0; i < container.Length; i++)
            {
                Keyword keyword = keywordRepository.GetByName(container[i]);
                if (keyword == null)
                {
                    keyword      = new Keyword();
                    keyword.Name = container[i];
                }//else nothing
                keyword.Used++;
                article.KeyWords.Add(keyword);
            }
            articleRepository.Save(article);
            return(article.Id);
        }
예제 #2
0
        public /*ArticleNewModel*/ int UIAddArticleNewModel(ArticleNewModel articleNewModel)
        {
            Article article = mapper.Map <Article>(articleNewModel);

            article.PublishTime = DateTime.Now;
            article.Author      = new User();
            article.Author      = CurrentUser;
            return(_articleRepository.AddArticle(article));
            //articleNewModel mapperNew = mapper.Map<ArticleNewModel>(article);
        }
예제 #3
0
        public ActionResult New(ArticleNewModel articleNewModel)//没有登录不应该访问,差needlogon
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", " 请输入正确的格式");
                return(View());
            }
            int articleId = articleService.Publish(articleNewModel);

            return(RedirectToAction(nameof(Single), new { id = articleId }));
        }
예제 #4
0
        public async Task <IActionResult> Create(ArticleNewModel item)
        {
            ViewBag.Domain = _configuration["Domain"];
            if (ModelState.IsValid)
            {
                Guid id = await _articleFacade.Create(item);

                return(RedirectToAction(nameof(Index), new { area = "Admin" }));
            }
            ViewBag.Category = new SelectList(await _categoryFacade.GetAll(), "Id", "Name");
            return(View(item));
        }
예제 #5
0
        public ActionResult New(ArticleNewModel model)
        {
            if (model.Title == null)
            {
                ModelState.AddModelError(nameof(model.Title), "* 文章标题不能为空");
                return(View(model));
            }
            if (model.Body == null)
            {
                ModelState.AddModelError(nameof(model.Body), "* 文章正文不能为空");
                return(View(model));
            }
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            model.PublishTime = DateTime.Now;
            int newId = _articleService.UIAddArticleNewModel(model);

            return(RedirectToAction("Single", new { id = newId }));
        }
예제 #6
0
 public int Publish(ArticleNewModel articleNewModel)
 {
     throw new NotImplementedException();
 }
예제 #7
0
 public int Publish(ArticleNewModel articleNewModel, int currentUserId)
 {
     throw new NotImplementedException();
 }