//Chat Page
        #region "Chat Page"

        public IActionResult Chat(UserDetailsModel model)
        {
            string mUserID   = TempData["UserID"] as string;
            string mUsername = TempData["Username"] as string;

            if (mUserID != null)
            {
                model.UserID = Convert.ToInt32(mUserID);
                if (model.FriendList == null || model.FriendList.Count == 0)
                {
                    UserDetails_adapter UserRequest = new UserDetails_adapter();
                    model.FriendList = UserRequest.GetFriendList();
                }

                if (model.NewMessage == null)
                {
                    model.NewMessage = new MessageModel();
                }

                Messages_adapter MessageAdp = new Messages_adapter(model.UserID, mUsername);
                model.Conversation = MessageAdp.GetConversationBetweenUsers(0);

                TempData.Keep();
                return(View("Chat", model));
            }
            else
            {
                TempData["Username"] = null;
                return(RedirectToAction("Login"));
            }
        }
        public IActionResult Login(LoginViewModel model)
        {
            UserDetails_adapter UserRequest  = new UserDetails_adapter();
            UserDetails         RecievedUser = UserRequest.LoginUser(model.Username, model.Password);

            if (RecievedUser != null)
            {
                TempData["UserID"]   = RecievedUser.UserID.ToString();
                TempData["Username"] = RecievedUser.UserName.ToString();
                return(RedirectToAction("Chat"));
            }
            else
            {
                ViewData["LoginError"] = "Incorrect Username or Password";
                return(View());
            }
        }
        public IActionResult Register(LoginViewModel model)
        {
            if (model.Password == model.RetypePassword)
            {
                UserDetails_adapter UserRequest = new UserDetails_adapter();
                string result = UserRequest.CreateUser(model.Username, model.Email, model.Password);

                if (result != null)
                {
                    ViewData["LoginError"] = result;
                    return(View());
                }
                else
                {
                    TempData["Username"] = model.Username;
                    return(RedirectToAction("Chat"));
                }
            }
            else
            {
                ViewData["LoginError"] = "Passwords do not match.";
                return(View());
            }
        }