private void DeleteLoop(WA_Blogs blog) { var Blogs1 = blog.WA_Blogs1.ToList(); for (int i = 0; i < Blogs1.Count; i++) { DeleteLoop(Blogs1[i]); } var Posts = blog.WA_Posts.ToList(); for (int i = 0; i < Posts.Count; i++) { WA_Posts wa_posts = Posts[i]; if (wa_posts != null) { var comments = wa_posts.WA_Comments.ToList(); for (int j = 0; j < comments.Count; j++) { DeleteComments(comments[j]); } var likes = wa_posts.WA_Likes.ToList(); for (int j = 0; j < likes.Count; j++) { db.WA_Likes.Remove(likes[j]); db.SaveChanges(); } db.WA_Posts.Remove(wa_posts); db.SaveChanges(); } } db.WA_Blogs.Remove(blog); db.SaveChanges(); }
public ActionResult DeleteConfirmed(int id) { WA_Posts wa_posts = db.WA_Posts.Single(n => n.PostID == id); if (wa_posts != null) { var blogs = wa_posts.WA_Blogs.ToList(); for (int i = 0; i < blogs.Count; i++) { WA_Blogs blog = blogs[i]; blog.WA_Posts.Remove(wa_posts); db.Entry(blog).State = EntityState.Modified; db.SaveChanges(); } var comments = wa_posts.WA_Comments.ToList(); for (int i = 0; i < comments.Count; i++) { DeleteComments(comments[i]); } var likes = wa_posts.WA_Likes.ToList(); for (int i = 0; i < likes.Count; i++) { db.WA_Likes.Remove(likes[i]); db.SaveChanges(); } db.WA_Posts.Remove(wa_posts); db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "PostID,Title,Description,ContentPost,Picture,UseDescription,Active")] WA_Posts wa_posts, HttpPostedFileBase filebase) { if (ModelState.IsValid) { WA_Posts change = db.WA_Posts.Find(wa_posts.PostID); change.Title = wa_posts.Title; change.Description = wa_posts.Description; change.ContentPost = wa_posts.ContentPost; change.UseDescription = wa_posts.UseDescription; change.Active = wa_posts.Active; string path = "~/Content/images/thuvien"; if (!string.IsNullOrEmpty(Request.Files[0].FileName)) { string tg = DateTime.Now.ToString("ddMMyyyy_"); string pathToSave = Server.MapPath(path); string filename = tg + Path.GetFileName(Request.Files[0].FileName); wa_posts.Picture = Path.Combine(path, filename); change.Picture = wa_posts.Picture; Request.Files[0].SaveAs(Path.Combine(pathToSave, filename)); } db.Entry(change).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Author = new SelectList(db.WA_Users, "UserID", "UserName", wa_posts.Author); return(View(wa_posts)); }
public ActionResult Create([Bind(Include = "PostID,Title,Description,ContentPost,Author,Picture,UseDescription,Active")] WA_Posts wa_posts, int[] Blogs, HttpPostedFileBase filebase) { if (ModelState.IsValid) { if (Blogs == null || Blogs.Count() == 0) { return(View("Error")); } wa_posts.Created = DateTime.Now; wa_posts.Active = false; wa_posts.Seen = 0; for (int i = 0; i < Blogs.Count(); i++) { wa_posts.WA_Blogs.Add(db.WA_Blogs.Find(Blogs[i])); } string path = "~/Content/images/thuvien"; if (Request.Files[0] != null) { string tg = DateTime.Now.ToString("ddMMyyyy_"); string pathToSave = Server.MapPath(path); string filename = tg + Path.GetFileName(Request.Files[0].FileName); wa_posts.Picture = Path.Combine(path, filename); Request.Files[0].SaveAs(Path.Combine(pathToSave, filename)); } db.WA_Posts.Add(wa_posts); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Author = new SelectList(db.WA_Users, "UserID", "UserName", wa_posts.Author); return(View(wa_posts)); }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } WA_Posts wa_posts = db.WA_Posts.Find(id); if (wa_posts == null) { return(HttpNotFound()); } return(View(wa_posts)); }
// GET: /Posts/Edit/5 public ActionResult Edit(int?id, string title) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } WA_Posts wa_posts = db.WA_Posts.Find(id); if (wa_posts == null) { return(HttpNotFound()); } ViewBag.ListBlogs = db.WA_Blogs.Where(x => x.Parent == null && x.Active).ToList(); ViewBag.Author = new SelectList(db.WA_Users, "UserID", "UserName", wa_posts.Author); return(View(wa_posts)); }
public ActionResult ViewPost(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } WA_Posts wa_posts = db.WA_Posts.Find(id); if (wa_posts == null) { return(HttpNotFound()); } wa_posts.Seen++; db.Entry(wa_posts).State = EntityState.Modified; db.SaveChanges(); return(View(wa_posts)); }
public ActionResult QuickEdit([Bind(Include = "PostID,Title,Description,ContentPost,Active")] WA_Posts wa_posts, int[] Blogs, HttpPostedFileBase filebase) { if (ModelState.IsValid) { if (Blogs == null || Blogs.Count() == 0) { return(View("Edit", wa_posts)); } WA_Posts change = db.WA_Posts.Find(wa_posts.PostID); change.Title = wa_posts.Title; change.Description = wa_posts.Description; change.ContentPost = wa_posts.ContentPost; change.Active = wa_posts.Active; change.WA_Blogs = new List <WA_Blogs>(); //Save pic string path = "~/Content/images/thuvien"; if (Request.Files[0] != null) { string tg = DateTime.Now.ToString("ddMMyyyy_"); string pathToSave = Server.MapPath(path); string filename = tg + Path.GetFileName(Request.Files[0].FileName); change.Picture = Path.Combine(path, filename); Request.Files[0].SaveAs(Path.Combine(pathToSave, filename)); } foreach (var item in Blogs) { change.WA_Blogs.Add(db.WA_Blogs.Find(item)); } db.Entry(change).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Author = new SelectList(db.WA_Users, "UserID", "UserName", wa_posts.Author); return(View("Edit", wa_posts)); }