public IActionResult AddArticle(AddArticleForm article) { if (ModelState.IsValid) { if (_context.Blog.Any(m => m.Title.Equals(article.Title))) { ErrorMessage = "重复的标题"; return(RedirectToAction(nameof(Write))); } //TODO:作者与状态待完善 var newBlog = new Blog { Id = Guid.NewGuid(), Catalog = _context.Catalog.Find(article.CatalogId), CreatedTime = DateTime.Now, UpdateTime = DateTime.Now, Title = article.Title, Description = article.Description, Tags = article.Tags, Content = article.Content, Status = StatusType.New, AuthorName = User.Claims.Where(c => c.Type == ClaimTypes.Name).First().Value }; _context.Blog.Add(newBlog); if (_context.SaveChanges() > 0) { return(RedirectToAction(nameof(Index))); } } SetErrorMessage(); return(RedirectToAction(nameof(Write))); }
private void AddOrderArticleButton_Click(object sender, EventArgs e) { AddArticleForm addArticleForm = new AddArticleForm(orderList); addArticleForm.ShowDialog(); updateOrderListBox(); }