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); }
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); }
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 })); }
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)); }
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 })); }
public int Publish(ArticleNewModel articleNewModel) { throw new NotImplementedException(); }
public int Publish(ArticleNewModel articleNewModel, int currentUserId) { throw new NotImplementedException(); }