public ActionResult Edit(Post post) { data.Entry(post).State = EntityState.Modified; data.SaveChanges(); return RedirectToAction("Index", "Blog"); }
public ActionResult Create(Post post) { if (ModelState.IsValid) { db.Posts.Add(post); db.SaveChanges(); return RedirectToAction("Index"); } return View(post); }
public PostService(string parUserId) { _post = new Post(); _post.ApplicationUserId = parUserId; _post.Tittle = ""; _post.PostComments = new Collection<PostComment>(); _post.PostViews = new Collection<PostView>(); _post.PostTags = new Collection<PostTag>(); _post.PostContents = new Collection<PostContent>(); // _post.PostContents.Add(new PostContent() { ContentDataType = parContentDataType, ContentData = new byte[0] }); }
public ActionResult Create(Post post) { try { post.PostID = _blogDataContext.Posts.OrderByDescending(x => x.PostID).First().PostID + 1; _blogDataContext.Posts.InsertOnSubmit(post); _blogDataContext.SubmitChanges(); return RedirectToAction("Index"); } catch { return View(post); } }
public ActionResult Create(Post post) { if(!ModelState.IsValid) { return View(post); } var user = data.Users.FirstOrDefault(x => x.Username == User.Identity.Name); post.UserId = user.Id; post.CreatedOn = DateTime.Now; data.Posts.Add(post); data.SaveChanges(); return RedirectToAction("Index", "Blog"); }
public ActionResult Create(Post post) { db.Posts.Add(post); db.SaveChanges(); return RedirectToAction("Index"); }
public PostService(Post Post) { _post = Post; }
public ActionResult Edit(Post post) { if (ModelState.IsValid) { db.Entry(post).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(post); }
private void detach_Posts(Post entity) { this.SendPropertyChanging(); entity.Category = null; }
partial void DeletePost(Post instance);
private void attach_Posts(Post entity) { this.SendPropertyChanging(); entity.Category = this; }
partial void UpdatePost(Post instance);
partial void InsertPost(Post instance);
public ActionResult Edit(Post post) { //Custom form validation if (post.Title.Length == 1) ModelState.AddModelError("Title", "Your title has to be a little bit longer"); ViewData["Categories"] = _blogDataContext.Categories.ToSelectList("CategoryID", "CategoryName"); if (ModelState.IsValid) { var p = _blogDataContext.Posts.SingleOrDefault(x => x.PostID == post.PostID); UpdateModel(p); _blogDataContext.SubmitChanges(); } return View(post); }