public ActionResult ArticleSubmit(AddArticleViewModel addarticleViewModel, HttpPostedFileBase banner, int UserID) { var MaxId = articleManage.ArticleId(p => p.ID); var articleID = MaxId + 1; if (banner != null) { var bannerName = Path.Combine(Request.MapPath("/ArticleImg"), articleID + ".jpg"); if (System.IO.File.Exists(bannerName)) { System.IO.File.Delete(bannerName); } banner.SaveAs(bannerName); } if (ModelState.IsValid) { Article article = new Article(); article.MovieID = addarticleViewModel.MovieID; article.Title = addarticleViewModel.Title; article.UserID = UserID; article.Content = addarticleViewModel.Content; article.Releasetime = DateTime.Now; article.Auditstatus = Article.Status.待审核; var _resp = articleManage.Add(article); return(RedirectToAction("Index", "User")); } else { return(View(addarticleViewModel)); } }
public ActionResult Add(AddArticelViewModel articleViewModel, HttpPostedFileBase banner) { var MaxId = articleManage.ArticleId(p => p.ID); var articleID = MaxId + 1; if (banner != null) { var bannerName = Path.Combine(Request.MapPath("/ArticleImg"), articleID + ".jpg"); if (System.IO.File.Exists(bannerName)) { System.IO.File.Delete(bannerName); } banner.SaveAs(bannerName); } if (ModelState.IsValid) { Article _article = new Article(); _article.UserID = articleViewModel.UserID; _article.MovieID = articleViewModel.MovieID; _article.Releasetime = articleViewModel.Releasetime; _article.Title = articleViewModel.Title; _article.Content = articleViewModel.Content; _article.Auditstatus = Article.Status.待审核; var _resp = articleManage.Add(_article); if (_resp.Code == 1) { return(View("Prompt", new Prompt() { Title = "添加文章成功", Message = "您成功的添加了当前文章", Buttons = new List <string>() { "<a href=\"" + Url.Action("Index", "Article") + "\" class=\"btn btn-default\">文章管理</a>", "<a href=\"" + Url.Action("Add", "Article") + "\" class=\"btn btn-default\">继续添加</a>" } } )); } else { ModelState.AddModelError("", _resp.Message); } } else { return(View(articleViewModel)); } var _users = new UserManage().FindList(); List <SelectListItem> _userlistItems = new List <SelectListItem>(_users.Count()); foreach (var _user in _users) { _userlistItems.Add(new SelectListItem() { Text = _user.Username, Value = _user.ID.ToString() }); } ViewBag.Users = _userlistItems; var _movies = new MovieManage().FindList(); List <SelectListItem> _movielistItems = new List <SelectListItem>(_movies.Count()); foreach (var _movie in _movies) { _movielistItems.Add(new SelectListItem() { Text = _movie.MovieName, Value = _movie.ID.ToString() }); } ViewBag.Movies = _movielistItems; return(View(articleViewModel)); }