public async Task <ActionResult> Edit(CategoryModel model) { var entity = await easonRepository.GetAsync(model.id); if (entity != null && entity.title != model.title) { entity.title = model.title; await easonRepository.UpdateAsync(entity); await easonRepository.UnitOfWork.CommitAsync(); } return(RedirectToAction("Index")); }
public async Task <ActionResult> Edit(long?id) { if (id == null) { return(RedirectToAction("Index")); } var entity = await repository.GetAsync((long)id); if (entity != null) { return(View(entity)); } return(RedirectToAction("Index")); }
public async Task <ActionResult> Create(PublishArticle model) { if (model == null) { ModelState.AddModelError("", "数据不允许为空!!"); } if (string.IsNullOrEmpty(model.title)) { ModelState.AddModelError("", "标题不允许为空!!"); } //if (string.IsNullOrEmpty(model.outLink)) //{ // model.outLink = "http://www.instwin.com/act/upa/content.html"; //} if (ModelState.IsValid) { var cate = new EasonRepository <ArticleCategory, long>(); var ct = await cate.GetAsync(model.categoryId); Article art = new Article() { title = model.title, contents = model.contents, creationTime = DateTime.Now, status = model.status, categoryId = model.categoryId, //channelId = model.channelId, //typeId = model.typeId, creatorName = User.Identity.Name, imageUrl = model.imageUrl, videoUrl = model.videoUrl, mTitle = model.mTitle, desc = model.desc, categoryName = ct.title, outLink = model.outLink, creatorId = long.Parse((User.Identity as ClaimsIdentity).Claims.FirstOrDefault(m => m.Type == ClaimTypes.Sid).Value) }; await repository.InsertAsync(art); await repository.UnitOfWork.CommitAsync(); return(Jsonp(new { success = true }, JsonRequestBehavior.AllowGet)); } return(View(model)); }
public async Task <ActionResult> Edit(PublishArticle model) { if (model == null) { ModelState.AddModelError("", "数据不允许为空!!"); } if (string.IsNullOrEmpty(model.title)) { ModelState.AddModelError("", "标题不允许为空!!"); } var art = await repository.GetAsync(model.id); var cate = new EasonRepository <ArticleCategory, long>(); var ct = await cate.GetAsync(model.categoryId); if (art == null) { ModelState.AddModelError("", "该文章可能已经被删除!"); } if (ModelState.IsValid) { art.title = model.title; art.contents = model.contents; art.creationTime = DateTime.Now; art.status = model.status; art.categoryId = model.categoryId; // art.typeId = model.typeId; art.creatorName = User.Identity.Name; art.imageUrl = model.imageUrl; art.videoUrl = model.videoUrl; art.mTitle = model.mTitle; art.desc = model.desc; art.outLink = model.outLink; art.categoryName = ct.title; art.creatorId = long.Parse((User.Identity as ClaimsIdentity).Claims.FirstOrDefault(m => m.Type == ClaimTypes.Sid).Value); await repository.UpdateAsync(art); await repository.UnitOfWork.CommitAsync(); return(Jsonp(new { success = true }, JsonRequestBehavior.AllowGet)); } return(View(model)); }