Esempio n. 1
0
 public ActionResult Index(LstMyNewsModel post)
 {
     if (ModelState.IsValid)
     {
         db.Posts.Add(new Post()
         {
             ContentPost = post.ContentPost,
             DatePublication = DateTime.Today,
             Author = db.Users.Find(WebSecurity.CurrentUserId),
             Likes = new List<Like>(),
             Comments = new List<Comment>()
         });
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(post);
 }
Esempio n. 2
0
        public ActionResult Index()
        {
            LstMyNewsModel viewLstMyNew = new LstMyNewsModel();
            viewLstMyNew.MyNews = new List<Post>();
            List<Follow> MyFollow = new List<Follow>();
            List<Post> PostsUserFollowed = new List<Post>();

            //on récupère la liste de likes mis par l'utilisateur connecté
            viewLstMyNew.Likes = db.Likes.Where(i => i.LikeFromUser.UserId == WebSecurity.CurrentUserId).ToList();

            // on récupère la liste des utilisateur suivi de l'utilisateur connecté
            MyFollow = db.Follows
                       .Where(i => i.userfollower.UserId == WebSecurity.CurrentUserId)
                       .ToList();
            foreach (Follow unUserFollowed in MyFollow)
            {
                PostsUserFollowed = db.Posts
                                        .Where(i => i.Author.UserId == unUserFollowed.userfollowed.UserId)
                                        .ToList();
                foreach (Post unPost in PostsUserFollowed)
                {
                    if (unPost != null)
                    {
                        viewLstMyNew.MyNews.Add(unPost);
                    }
                    else
                    {
                        break;
                    }

                }
                PostsUserFollowed.Clear();
            }

            // on liste nos news personnel
            List<Post> PersonalPost = new List<Post>();
            PersonalPost = db.Posts
                            .Where(i => i.Author.UserId == WebSecurity.CurrentUserId)
                            .ToList();
            foreach(Post unPostPerso in PersonalPost)
            {
                if (unPostPerso != null)
                {
                    viewLstMyNew.MyNews.Add(unPostPerso);
                }
                else
                {
                    break;
                }

            }
            PersonalPost.Clear();
            viewLstMyNew.MyNews.OrderByDescending(i => i.DatePublication);
            return View(viewLstMyNew);
        }