Beispiel #1
0
        public IActionResult Index()
        {
            List <MindModel> mindModel = new List <MindModel>();

            var user = db.Users
                       .Where(c => c.UserId == Convert.ToInt32(User.Identity.Name))
                       .FirstOrDefault();

            ViewData["image"] = user.ProfilePic;
            ViewData["user"]  = user;

            foreach (var thisMind in db.Minds)
            {
                MindModel m = new MindModel();
                m.UserId     = thisMind.UserId;
                m.MindMess   = thisMind.MindMess;
                m.NumOfLikes = thisMind.NumOfLikes;
                m.DateOfMind = thisMind.DateOfMind;
                m.MindId     = thisMind.MindId;

                m.Comments2 = new Dictionary <Comment, String>();

                foreach (var comm in db.Comments)
                {
                    if (comm.MindId == m.MindId)
                    {
                        User commenter = db.Users
                                         .Where(c => c.UserId == comm.UserId)
                                         .FirstOrDefault();

                        m.Comments2.Add(comm, commenter.ProfilePic);
                    }
                }

                var like = db.Likes.Where(c => c.MindId == thisMind.MindId && user.UserId == c.UserId).FirstOrDefault();
                if (like != null)
                {
                    m.liked = true;
                }
                else
                {
                    m.liked = false;
                }

                var thisUser = db.Users
                               .Where(c => c.UserId == thisMind.UserId)
                               .FirstOrDefault();

                m.UserPic = thisUser.ProfilePic;

                mindModel.Add(m);
            }

            mindModel = mindModel.OrderByDescending(x => x.DateOfMind).ToList();

            return(View("Lenta", mindModel.ToList()));
            //return RedirectPermanent("~/Home/Lenta", mindModel.ToList());
        }
Beispiel #2
0
        public async Task <ActionResult> addLike(int MindId)
        {
            Like like = db.Likes
                        .Where(c => c.UserId == Convert.ToInt32(User.Identity.Name) && c.MindId == MindId)
                        .FirstOrDefault();



            if (like == null)
            {
                Like like2 = new Like {
                    UserId = Convert.ToInt32(User.Identity.Name), MindId = MindId
                };

                var thisMind = db.Minds
                               .Where(c => c.MindId == MindId)
                               .FirstOrDefault();

                thisMind.NumOfLikes += 1;

                db.Likes.Add(like2);
                await db.SaveChangesAsync();

                MindModel thisMindModel = new MindModel();
                thisMindModel.liked      = true;
                thisMindModel.MindId     = thisMind.MindId;
                thisMindModel.NumOfLikes = thisMind.NumOfLikes;

                //return PartialView(thisMind);
                return(PartialView(thisMindModel));
            }

            else
            {
                var thisMind = db.Minds
                               .Where(c => c.MindId == MindId)
                               .FirstOrDefault();

                thisMind.NumOfLikes -= 1;

                db.Likes.Remove(like);
                await db.SaveChangesAsync();

                MindModel thisMindModel = new MindModel();
                thisMindModel.liked      = false;
                thisMindModel.MindId     = thisMind.MindId;
                thisMindModel.NumOfLikes = thisMind.NumOfLikes;

                return(PartialView("addLike", thisMindModel));
            }
        }
Beispiel #3
0
        public async Task <ActionResult> addComment(String commentText, int MindId)
        {
            var user = db.Users
                       .Where(c => c.UserId == Convert.ToInt32(User.Identity.Name))
                       .FirstOrDefault();


            MindModel m = new MindModel();

            if (commentText != null || commentText != "")
            {
                Comment com = new Comment()
                {
                    CommentMess = commentText, MindId = MindId, UserId = Convert.ToInt32(User.Identity.Name), DateOfComment = DateTime.Now
                };
                db.Comments.Add(com);
                await db.SaveChangesAsync();


                m.Comments2 = new Dictionary <Comment, String>();
                m.UserPic   = user.ProfilePic;
                m.MindId    = MindId;
                foreach (var comm in db.Comments)
                {
                    if (comm.MindId == MindId)
                    {
                        User commenter = db.Users
                                         .Where(c => c.UserId == comm.UserId)
                                         .FirstOrDefault();

                        m.Comments2.Add(comm, commenter.ProfilePic);
                    }
                }
            }

            return(PartialView("_Comments", m));
        }
Beispiel #4
0
        public IActionResult Lenta()
        {
            List <int>       friendsIds = new List <int>();
            List <User>      friends    = new List <User>();
            List <Mind>      userMinds  = new List <Mind>();
            List <MindModel> mindModel  = new List <MindModel>();



            var user = db.Users
                       .Where(c => c.UserId == Convert.ToInt32(User.Identity.Name))
                       .FirstOrDefault();

            ViewData["image"] = user.ProfilePic;
            ViewData["user"]  = user;

            foreach (var fri in db.Friends)
            {
                if (User.Identity.Name == fri.USerOneId.ToString())
                {
                    friendsIds.Add(fri.USerTwoId);
                }
            }

            friendsIds.Add(Convert.ToInt32(User.Identity.Name));

            foreach (var id in friendsIds)
            {
                foreach (var userr in db.Users)
                {
                    if (id == userr.UserId)
                    {
                        friends.Add(userr);
                    }
                }
            }

            foreach (var frien in friends)
            {
                foreach (var myMind in db.Minds)
                {
                    if (frien.UserId == myMind.UserId)
                    {
                        MindModel m = new MindModel();
                        m.UserId     = myMind.UserId;
                        m.MindMess   = myMind.MindMess;
                        m.NumOfLikes = myMind.NumOfLikes;
                        m.DateOfMind = myMind.DateOfMind;
                        m.MindId     = myMind.MindId;
                        m.UserPic    = frien.ProfilePic;

                        m.Comments2 = new Dictionary <Comment, String>();

                        foreach (var comm in db.Comments)
                        {
                            if (comm.MindId == m.MindId)
                            {
                                User commenter = db.Users
                                                 .Where(c => c.UserId == comm.UserId)
                                                 .FirstOrDefault();

                                m.Comments2.Add(comm, commenter.ProfilePic);
                            }
                        }

                        var like = db.Likes.Where(c => c.MindId == myMind.MindId && user.UserId == c.UserId).FirstOrDefault();
                        if (like != null)
                        {
                            m.liked = true;
                        }
                        else
                        {
                            m.liked = false;
                        }

                        mindModel.Add(m);
                    }
                }
            }

            mindModel = mindModel.OrderByDescending(x => x.DateOfMind).ToList();


            return(View(mindModel.ToList()));
        }
        public IActionResult UserPage(int id)
        {
            UserPageModel userPageModel = new UserPageModel();

            bool myFriend = false;

            var friend = db.Friends.Where(c => c.USerOneId == Convert.ToInt32(User.Identity.Name) && c.USerTwoId == id).FirstOrDefault();

            if (friend != null)
            {
                userPageModel.myFriend = true;
            }
            else
            {
                userPageModel.myFriend = false;
            }

            User UserPage = db.Users.Where(c => c.UserId == id).FirstOrDefault();

            ViewData["user"] = UserPage;

            userPageModel.userPage = UserPage;

            List <MindModel> mindModel = new List <MindModel>();

            foreach (var myMind in db.Minds)
            {
                if (UserPage.UserId == myMind.UserId)
                {
                    MindModel m = new MindModel();
                    m.UserId     = myMind.UserId;
                    m.MindMess   = myMind.MindMess;
                    m.NumOfLikes = myMind.NumOfLikes;
                    m.DateOfMind = myMind.DateOfMind;
                    m.MindId     = myMind.MindId;
                    m.UserPic    = UserPage.ProfilePic;

                    m.Comments2 = new Dictionary <Comment, String>();

                    foreach (var comm in db.Comments)
                    {
                        if (comm.MindId == m.MindId)
                        {
                            User commenter = db.Users
                                             .Where(c => c.UserId == comm.UserId)
                                             .FirstOrDefault();

                            m.Comments2.Add(comm, commenter.ProfilePic);
                        }
                    }

                    var like = db.Likes.Where(c => c.MindId == myMind.MindId && /*UserPage.UserId*/ Convert.ToInt32(User.Identity.Name) == c.UserId).FirstOrDefault();
                    if (like != null)
                    {
                        m.liked = true;
                    }
                    else
                    {
                        m.liked = false;
                    }


                    mindModel.Add(m);
                }
            }

            userPageModel.userPageMinds = mindModel.ToList();

            return(View(userPageModel));
        }