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> /// Mortgages the calculator. /// </summary> /// <returns></returns> public ActionResult MortgageCalculator() { MortgageCalculatorDataAccess dataAccess = new MortgageCalculatorDataAccess(RavenSession); MortgageUser mortgageUser = dataAccess.RetrieveFromSession(); MortgageCalculatorViewModel model = new MortgageCalculatorViewModel(); model.User = mortgageUser; if(mortgageUser != null && !string.IsNullOrEmpty(mortgageUser.UserName) && mortgageUser.Mortgages.Count == 0) { model.Action = MortgagePageAction.CreateNewMortgage; } else if(mortgageUser != null && !string.IsNullOrEmpty(mortgageUser.UserName) && mortgageUser.Mortgages.Count > 0) { model.Action = MortgagePageAction.ShowUserMortgages; } return View("MortgageCalculator", model); }