public int AddPost(Post post) { using (var transactionScope = new TransactionScope()) { post.Category = context.Categories.Find(post.CategoryId); List <Tag> tags= context.Tags.Where(a => post.TagList.Contains(a.Id)).ToList(); post.Tags = tags; context.Posts.AddOrUpdate(a => a.Id, post); context.SaveChanges(); transactionScope.Complete(); return post.Id; } }
public static MvcHtmlString PostLink(this HtmlHelper helper, Post post) { return helper.ActionLink(post.Title, "Post", "Blog", new { year = post.PostedOn.Year, month = post.PostedOn.Month, title = post.UrlSlug }, new { title = post.Title }); }
public JsonResult AddEditPost(Post model) { try { model.PostedBy = _userStatistics.UserId; model.PostedOn = DateTime.Now; int id = _blogRepository.AddPost(model); return Json(id, JsonRequestBehavior.AllowGet); } catch (Exception ex) { //CatchException.CatchTheException(ex); throw; } finally { } }
/// <summary> /// /// </summary> /// <returns></returns> public ActionResult AddEditPost(int postId = -1) { try { Post model = null; if (postId == -1) { model = new Post(); ViewBag.Categoris = new SelectList(_blogRepository.Categories(), "Id", "Name"); ViewBag.Tags = new MultiSelectList(_blogRepository.Tags(), "Id", "Name"); } else { model = _blogRepository.GetPostbyId(postId, _userStatistics.UserId); ViewBag.Categoris = new SelectList(_blogRepository.Categories(), "Id", "Name", model.Category.Id); ViewBag.Tags = new MultiSelectList(_blogRepository.Tags(), "Id", "Name", model.Tags.Select(a => a.Id).ToList()); } return PartialView("../Blog/_AddEdit_Post", model); } catch (Exception ex) { //CatchException.CatchTheException(ex); throw; } finally { } }
public void EditPost(Post post) { using (var transactionScope = new TransactionScope()) { context.Posts.AddOrUpdate(p => p.Id, post); context.SaveChanges(); transactionScope.Complete(); } }