public ActionResult Details(int IdPost) { int IdUser = 2; //int IdPost = 2; // Post post = db.Posts.Find(IdPost); ForPost forPost = new ForPost(); forPost.Userliked = false; foreach (Like l in db.Likes.Where(p => p.IdPost == IdPost & p.IdUser == IdUser)) { forPost.Userliked = l.liked; } List <Like> like = new List <Like>(); foreach (Like l in db.Likes.Where(p => p.IdPost == IdPost)) { like.Add(l); } forPost.Likes = like; if (forPost == null) { return(HttpNotFound()); } return(PartialView(forPost)); }
public ActionResult Post() { int IdUser = 1; int IdPost = 1; Post post = db.Posts.Find(IdPost); ForPost forPost = new ForPost(); foreach (Post l in db.Posts.Where(p => p.IdPost == post.IdPost & p.IdUser == IdUser)) { forPost.Userliked = true; } List <Like> like = new List <Like>(); foreach (Like l in db.Likes.Where(p => p.IdPost == post.IdPost)) { like.Add(l); } forPost.Likes = like; if (forPost != null) { return(HttpNotFound()); } return(PartialView(forPost)); }
public ActionResult LikePost(int?IdPost) { int IdUser = 1; // int IdPost = 2; // Post post = db.Posts.Find(IdPost); ForPost forPost = new ForPost(); forPost.Userliked = false; Like likeThis = new Like(); foreach (Like l in db.Likes.Where(p => p.IdPost == IdPost & p.IdUser == IdUser)) { if (l.liked == true) { l.liked = false; } else { l.liked = true; } likeThis = l; } if (likeThis.IdLike == 0) { likeThis.IdPost = IdPost; likeThis.IdUser = IdUser; likeThis.liked = true; Add(likeThis); } else { Saver(likeThis); } forPost.Userliked = likeThis.liked; List <Like> like = new List <Like>(); foreach (Like l in db.Likes.Where(p => p.IdPost == IdPost & p.liked == true)) { like.Add(l); } forPost.Likes = like; if (forPost == null) { return(HttpNotFound()); } return(PartialView(forPost)); }
public ActionResult DeleteComent(int IdComent) { int IdUser = 2; int IdPost = 1; Coment b = db.Coments.Find(IdComent); if (b == null) { return(HttpNotFound()); } db.Coments.Remove(b); db.SaveChanges(); ForPost forPost = new ForPost(); List <Coment> coment = new List <Coment>(); foreach (Coment l in db.Coments.Where(p => p.IdPost == IdPost)) { coment.Add(l); } List <User> userComents = new List <User>(); foreach (Coment l in coment) { foreach (User l2 in db.Users.Where(p => p.IdUser == l.IdUser)) { userComents.Add(l2); } } forPost.Coments = coment; forPost.UserComents = userComents; return(PartialView(forPost)); }
public ActionResult AddComent(String text) { int IdUser = 2; int IdPost = 1; Coment com = new Coment(); com.IdPost = 1; com.IdUser = 2; com.Text = text; com.user = db.Users.Find(2); db.Entry(com).State = EntityState.Added; db.SaveChanges(); ForPost forPost = new ForPost(); List <Coment> coment = new List <Coment>(); foreach (Coment l in db.Coments.Where(p => p.IdPost == IdPost)) { coment.Add(l); } List <User> userComents = new List <User>(); foreach (Coment l in coment) { foreach (User l2 in db.Users.Where(p => p.IdUser == l.IdUser)) { userComents.Add(l2); } } forPost.Coments = coment; forPost.UserComents = userComents; return(PartialView(forPost)); }
public ActionResult Post(int?id) { if (id == null) { return(HttpNotFound()); } Post post = db.Posts.Find(id); User user = db.Users.FirstOrDefault(p => p.IdUser == post.IdUser); List <Like> like = new List <Like>(); foreach (Like l in db.Likes.Where(p => p.IdPost == post.IdPost)) { like.Add(l); } List <Repost> repost = new List <Repost>(); foreach (Repost l in db.Reposts.Where(p => p.IdPost == post.IdPost)) { repost.Add(l); } List <Picture> picture = new List <Picture>(); foreach (Picture l in db.Pictures.Where(p => p.IdPost == post.IdPost)) { picture.Add(l); } int KolPostUsera = db.Posts.Count(p => p.IdUser == user.IdUser); int KolLikeUsera = db.Likes.Count(p => p.IdUser == user.IdUser); List <Coment> coment = new List <Coment>(); foreach (Coment l in db.Coments.Where(p => p.IdPost == post.IdPost)) { coment.Add(l); } List <User> userComents = new List <User>(); foreach (Coment l in coment) { foreach (User l2 in db.Users.Where(p => p.IdUser == l.IdUser)) { userComents.Add(l2); } } bool userliked = false; foreach (Like l in db.Likes.Where(p => p.IdPost == post.IdPost & p.IdUser == user.IdUser)) { userliked = l.liked; } ForPost forPost = new ForPost(); forPost.IdPost = post.IdPost; forPost.Post = post; forPost.KolLikeUsera = KolPostUsera; forPost.KolPostUsera = KolLikeUsera; forPost.IdUser = user.IdUser; forPost.User = user; forPost.Reposts = repost; forPost.Likes = like; forPost.Pictures = picture; forPost.Coments = coment; forPost.UserComents = userComents; forPost.Userliked = userliked; if (post != null) { return(View(forPost)); } return(HttpNotFound()); }