/// <summary>
        /// Creates the sessions.
        /// </summary>
        /// <param name="item">The item.</param>
        public void CreateSessions(MortgageUser item)
        {
            DateTime SessionExpiration = DateTime.UtcNow.AddMonths(SessionTimeOutValue);

            //Save user ID cookie
            HttpCookie authCookie = new HttpCookie(SessionKey, m_RavenSession.Advanced.GetDocumentId(item))
            {
                Expires = SessionExpiration
            };

            HttpContext.Current.Response.Cookies.Add(authCookie);
        }
        public ActionResult MortgageCalculator(string action, string userlogin, string[] compareIDs, MortgageCalculatorViewModel model)
        {
            MortgageCalculatorDataAccess dataAccess = new MortgageCalculatorDataAccess(RavenSession);
            MortgageUser mortgageUser = null;
            MortgagePageAction actionPage = MortgagePageAction.ShowLogIn;
            string value = string.Empty;

            if(!string.IsNullOrEmpty(action) && action.Contains('_'))
            {
                string[] actionValue = action.Split('_');

                action = actionValue[0];
                value = actionValue[1];
            }

            switch(action)
            {
                case "getuser":
                    if(!string.IsNullOrEmpty(userlogin))
                    {
                        mortgageUser = dataAccess.GetUser(userlogin);

                        if(mortgageUser == null || string.IsNullOrEmpty(mortgageUser.Id) || string.IsNullOrEmpty(mortgageUser.UserName))
                        {
                            actionPage = MortgagePageAction.ShowNoUserFound;
                        }
                        else
                        {
                            dataAccess.CreateSessions(mortgageUser);
                            actionPage = MortgagePageAction.ShowUserMortgages;
                        }
                    }
                    break;
                case "createuser":
                    actionPage = MortgagePageAction.CreateNewUser;
                    break;
                case "saveuser":
                    mortgageUser = new MortgageUser();
                    mortgageUser.InjectFrom(model);
                    dataAccess.SaveUser(mortgageUser);
                    actionPage = MortgagePageAction.CreateNewMortgage;
                    break;
                case "createmortgage":
                    mortgageUser = dataAccess.RetrieveFromSession();
                    actionPage = MortgagePageAction.CreateNewMortgage;
                    break;
                case "savemortgage":
                    mortgageUser = dataAccess.RetrieveFromSession();
                    MortgageInformation mortgageInfo = new MortgageInformation();
                    mortgageInfo.InjectFrom(model);
                    mortgageUser.Mortgages.Add(mortgageInfo);
                    dataAccess.SaveUser(mortgageUser);
                    actionPage = MortgagePageAction.ShowUserMortgages;
                    break;
                case "signout":
                    dataAccess.SignOutSession();
                    actionPage = MortgagePageAction.ShowLogIn;
                    mortgageUser = null;
                    Session.Abandon();
                    break;
                case "deleteuser":
                    dataAccess.DeleteCurrentUser();
                    actionPage = MortgagePageAction.ShowLogIn;
                    mortgageUser = null;
                    break;
                case "calculatemortgage":
                    mortgageUser = dataAccess.RetrieveFromSession();
                    if(!string.IsNullOrEmpty(value))
                    {
                        model.ShowMortgageID = value;
                        actionPage = MortgagePageAction.ShowMortgageCalculations;
                    }
                    break;
                case "deletemortgage":
                    mortgageUser = dataAccess.RetrieveFromSession();
                    if(!string.IsNullOrEmpty(value))
                    {
                        MortgageInformation deletedMortgage = mortgageUser.GetMortgageByName(value);
                        mortgageUser.Mortgages.Remove(deletedMortgage);
                        dataAccess.SaveChanges();
                        actionPage = MortgagePageAction.ShowUserMortgages;
                    }
                    break;
                case "amortizemortgage":
                    mortgageUser = dataAccess.RetrieveFromSession();
                    if(!string.IsNullOrEmpty(value))
                    {
                        model.ShowMortgageID = value;
                        actionPage = MortgagePageAction.ShowMortgageAmortization;
                    }
                    break;
                case "comparemortgage":
                    mortgageUser = dataAccess.RetrieveFromSession();
                    if(compareIDs != null && compareIDs.Length > 0)
                    {
                        model.CompareMortgageIDs = compareIDs;
                        actionPage = MortgagePageAction.ShowMortgageCompare;
                    }
                    break;
                default:
                    break;
            }

            model.Action = actionPage;
            model.User = mortgageUser;

            return View("MortgageCalculator", model);
        }
        /// <summary>
        /// Saves the user.
        /// </summary>
        /// <param name="user">The user.</param>
        public void SaveUser(MortgageUser user)
        {
            m_RavenSession.Store(user);
            m_RavenSession.SaveChanges();

            CreateSessions(user);
        }