public ActionResult Create(PostModels p, HttpPostedFileBase Image) { if (!ModelState.IsValid || Image == null || Image.ContentLength == 0) { RedirectToAction("Create"); } p.Image = Image.FileName; try { Post post = new Post { PostId = p.Id, Title = p.Title, Description = p.Description, Privacy = p.Privacy, Image = p.Image, PostDateTime = DateTime.Now }; ps.Add(post); ps.Commit(); //ps.Dispose(); var path = Path.Combine(Server.MapPath("~/Content/images/"), Image.FileName); Image.SaveAs(path); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(int idTopic, post post) { post.user = CurrentUser.get(); post.topic = t.FindById(idTopic); post.postDate = DateTime.Now; p.Create(post); p.Commit(); return(RedirectToAction("Index", new { idTopic = post.idTopic })); }
public ActionResult AddComment(CommentsVM comment, int postId) { //bool result = false; Comment commentEntity = null; string currentUserId = User.Identity.GetUserId(); // int userId = 1; //int.Parse(currentUserId); //(int)Session["UserID"]; List <User> GetUsers = sp.GetUsers(); var user = GetUsers.FirstOrDefault(u => u.Id == currentUserId); var post = sp.GetPosts().FirstOrDefault(p => p.PostID == postId); if (comment != null) { commentEntity = new Comment { CommentMsg = comment.CommentMsg, CommentedDate = DateTime.Now //comment.CommentedDate, }; if (user != null && post != null) { post.Comments.Add(commentEntity); user.Comments.Add(commentEntity); //sq.SaveChanges( ); //dbContext.SaveChanges(); //result = true; sp.Commit(); su.Commit(); } } return(RedirectToAction("GetComments", "Comments", new { postId = postId })); }
public ActionResult Create(Post q) { try { // TODO: Add insert logic here string currentUserId = User.Identity.GetUserId(); List <User> GetUsers = ps.GetUsers(); var user = GetUsers.FirstOrDefault(u => u.Id == currentUserId); var cate = ps.GetCategoriePost().FirstOrDefault(u => u.Id == q.categoriePost.Id); //if (user != null) //{ Post pos = new Post { Message = q.Message, Titre = q.Titre, PostedDate = q.PostedDate, UserId = currentUserId, categoriePost = cate }; if (user != null) { user.Posts.Add(pos); ps.Commit(); su.Commit(); ps.Commit(); } return(RedirectToAction("Index", "Post")); } catch (Exception ex) { return(View()); } }
public ActionResult Create(PostViewModel pvm, CategoryPostViewModel id) { var c = Ps.GetAll(); foreach (var item in c) { CategoryPostViewModel Cvm = new CategoryPostViewModel(); Cvm.categorypostId = item.categorypostId; Cvm.nom = item.nom; /*Cvm.categoryId = item.categoryId; * Cvm.description = item.description; * Cvm.plan = item.plan; * Cvm.goals = item.goals; * Cvm.state = (WebApplication1.Models.stat)stat.To_Do;*/ } // ViewBag.cat = new SelectList(c, "projectId", "projectname"); Post p = new Post(); p.postId = pvm.postId; //p.categoriepostId=id.categorypostId; p.categorypostId = id.categorypostId; p.post_like = pvm.post_like; p.posttitre = pvm.posttitre; p.content = pvm.content; p.datepost = DateTime.Now; //// p.catgoriepostId = id.categorypostId; // p.content = pvm.content; // //p.userId = 1; //// p.user.Id = pvm.user.Id; Ts.Add(p); Ts.Commit(); try { // TODO: Add insert logic here return(RedirectToAction("listepost")); } catch { return(View()); } }