public ActionResult Create(string channelTag, string columnTag, int tagtype, string title, string body, int isDraft) { var article = new Article(); article.Body = body.Replace(" ", " ").Replace("\r\n", "<br />"); article.Title = title; article.CreatedUtc = DateTime.Now; article.ChannelTags = channelTag; article.ColumnTags = columnTag; article.IsDraft = isDraft; article.IsRelease = article.IsDraft == 0 ? 1 : 0; article.ManagerName = _simpleAccount.GetUserElement().Name; HttpPostedFileBase hp = Request.Files["file1"]; if (Request.Files.Count > 0) { article.TitleImageUrl = _helperServices.UpLoadImg("file", ""); //获取上传图片 if (hp != null) { article.OtherImageUrl = _helperServices.UpLoadFile("file1", ""); //获取上传文件 } //if (string.IsNullOrEmpty(article.TitleImageUrl)) // return Content("<script>alert('图片不能为空');window.location.href='" + Url.Action("Create", new // { // ViewBag.channelTag, // ViewBag.columnTag, // @tagtype = 1 // }) + "';</script>"); } _articleService.Add(article); ViewBag.channelTag = channelTag; ViewBag.columnTag = columnTag; ViewBag.tagtype = tagtype; return Content("<script>alert('创建" + ViewBag.columnTag + "-" + ViewBag.columnTag + "内容成功');window.location.href='" + Url.Action("List", new { ViewBag.channelTag, ViewBag.columnTag, @tagtype = 1 }) + "';</script>"); }
public void Add(Article article) { _appDbContext.Articles.Add(article); _appDbContext.SaveChanges(); }
public void Update(Article article) { //_appDbContext.Articles.Attach(article); _appDbContext.Entry(article).State = EntityState.Modified; _appDbContext.SaveChanges(); }
public ActionResult Edit(Article article) { var old = _articleService.Get(article.ArticleId); old.Title = article.Title; old.Body = article.Body.Replace(" ", " ").Replace("\r\n", "<br />"); ; old.ManagerName = _simpleAccount.GetUserElement().Name; old.IsDraft = article.IsDraft; old.IsRelease = old.IsDraft == 0 ? 1 : 0; HttpPostedFileBase hp = Request.Files["file1"]; if (Request.Files.Count > 0) { article.TitleImageUrl = _helperServices.UpLoadImg("file", ""); //获取上传图片 if (!string.IsNullOrEmpty(article.TitleImageUrl)) old.TitleImageUrl = article.TitleImageUrl; if (hp != null) { article.OtherImageUrl = _helperServices.UpLoadFile("file1", ""); //获取上传文件 if (!string.IsNullOrEmpty(article.OtherImageUrl)) old.OtherImageUrl = article.OtherImageUrl; } } _articleService.Update(old); return Content("<script>alert('编辑" + ViewBag.columnTag + "-" + ViewBag.columnTag + "内容成功');window.location.href='" + Url.Action("List", new { channelTag = old.ChannelTags, columnTag = old.ColumnTags, @tagtype = 1 }) + "';</script>"); }