예제 #1
0
        public ActionResult Login(string username, string password)
        {
            try
            {
                if (_userRepository.UserExists(username, password))
                {
                    FormsAuthentication.SetAuthCookie(username, false);

                    //Hämtar ett UserAccount, mappar till UserAccountModel och räknar vänförfrågningar
                    var user = _userRepository.GetUser(username).MapToModel();
                    user.RequestCount = _friendshipRepository.RequestCount(user.UserAccountID);

                    Session["User"] = user;

                    return(RedirectToAction("Index", "Profile", new RouteValueDictionary(new { username = user.Username })));
                }
                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception e)
            {
                return(View("Error", new ErrorModel {
                    Exception = e
                }));
            }
        }
예제 #2
0
        public ActionResult AcceptRequest(int senderID)
        {
            try
            {
                var user = Session["User"] as ProfileModel;

                var _userID = _userRepository.GetUser(User.Identity.Name).UserAccountID;
                //Repositoryt tar bort requesten och skapar en friendship.
                _friendshipRepository.AcceptRequest(senderID, _userID);

                //Uppdaterar antalet obesvarade requests
                user.RequestCount = _friendshipRepository.RequestCount(user.UserAccountID);
                Session["User"]   = user;

                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                return(View("Error", new ErrorModel {
                    Exception = e
                }));
            }
        }
예제 #3
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"));
            }
        }