Exemplo n.º 1
0
        // GET: Profile
        public ActionResult Index(string username)
        {//Hej4
            if (username != null)
            {
                try {
                    var profileModel = _userRepository.GetUser(username).MapToModel();

                    //Räknar antal obesvarade friendrequests
                    profileModel.RequestCount = _friendshipRepository.RequestCount(profileModel.UserAccountID);

                    //Sätter friendRequest-knappen beroende på om det finns request, vänskap eller inget alls.
                    if (profileModel.Username != User.Identity.Name)
                    {
                        var userID   = _userRepository.GetUser(User.Identity.Name).UserAccountID;
                        var friendID = profileModel.UserAccountID;

                        //Redan requestad
                        if (_friendshipRepository.ExistingRequest(userID, friendID))
                        {
                            profileModel.PendingFriendRequest = true;
                        }
                        else
                        {
                            profileModel.PendingFriendRequest = false;
                        }

                        //Redan vänner
                        if (_friendshipRepository.ExistingFriendship(userID, friendID))
                        {
                            profileModel.IsFriend = true;
                        }
                        else
                        {
                            profileModel.IsFriend = false;
                        }
                    }
                    return(View(profileModel));
                }
                catch (Exception e)
                {
                    return(View("Error", new ErrorModel {
                        Exception = e
                    }));
                }
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }