public const double PriceOfSingleSolution = 0.60; //Single #endregion Fields #region Methods public bool AddSolution(User theUser, SelectModel model, AnswerAppDataContext db) { String[] UserAnswers; if(theUser.Answers != null) { UserAnswers = theUser.Answers.Split(new char[1] { ';' }); foreach (String Answer in UserAnswers) { String thisAnswer = Answer.Replace(".pdf", ""); if (model.Contains(thisAnswer)) { theUser.Answers = theUser.Answers.Replace(thisAnswer + ".pdf;", ""); } } } theUser.Answers += model.ToString() + ".pdf;"; bool done = false; if (!model.Question.Equals("All") && !done) { //Find all questions from the selected section IQueryable<AnswerApp.Models.Question> retrieved = from theAnswers in db.Questions where theAnswers.Page_Number.Equals(model.Page) select theAnswers; Question[] results = retrieved.ToArray<Question>(); bool UserHasAll = true; foreach (Question theQuestion in results) { if (!UserHasAccess(theUser, theQuestion.Textbook_Title + "_" + theQuestion.Unit_Title + "_" + theQuestion.Chapter_Title + "_" + theQuestion.Section_Title + "_" + theQuestion.Page_Number + "_" + theQuestion.Question_Number + ".pdf", db)) { UserHasAll = false; break; } } if (UserHasAll) { model.Question = "All"; UserAnswers = theUser.Answers.Split(new char[1] { ';' }); foreach (String Answer in UserAnswers) { String thisAnswer = Answer.Replace(".pdf", ""); if (model.Contains(thisAnswer)) { theUser.Answers = theUser.Answers.Replace(thisAnswer + ".pdf;", ""); } } theUser.Answers += model.ToString() + ".pdf;"; } else { done = true; } } if (!model.Page.Equals("All") && !done) { //Find all questions from the selected section IQueryable<AnswerApp.Models.Page> retrieved = from thePages in db.Pages where thePages.Section_Title.Equals(model.Section) select thePages; AnswerApp.Models.Page[] results = retrieved.ToArray<AnswerApp.Models.Page>(); bool UserHasAll = true; foreach (AnswerApp.Models.Page thePage in results) { if (!UserHasAccess(theUser, thePage.Textbook_Title + "_" + thePage.Unit_Title + "_" + thePage.Chapter_Title + "_" + thePage.Section_Title + "_" + thePage.Page_Number + "_All", db)) { UserHasAll = false; break; } } if (UserHasAll) { model.Page = "All"; UserAnswers = theUser.Answers.Split(new char[1] { ';' }); foreach (String Answer in UserAnswers) { String thisAnswer = Answer.Replace(".pdf", ""); if (model.Contains(thisAnswer)) { theUser.Answers = theUser.Answers.Replace(thisAnswer + ".pdf;", ""); } } theUser.Answers += model.ToString() + ".pdf;"; } else { done = true; } } if (!model.Section.Equals("All") && !done) { //Find all Secrtions from the selected Chapter IQueryable<AnswerApp.Models.Section> retrieved = from theSections in db.Sections where theSections.Chapter_Title.Equals(model.Chapter) select theSections; AnswerApp.Models.Section[] results = retrieved.ToArray<AnswerApp.Models.Section>(); bool UserHasAll = true; foreach (AnswerApp.Models.Section theSection in results) { if (!UserHasAccess(theUser, theSection.Textbook_Title + "_" + theSection.Unit_Title + "_" + theSection.Chapter_Title + "_" + theSection.Section_Title + "_All_All", db)) { UserHasAll = false; break; } } if (UserHasAll) { model.Section = "All"; UserAnswers = theUser.Answers.Split(new char[1] { ';' }); foreach (String Answer in UserAnswers) { String thisAnswer = Answer.Replace(".pdf", ""); if (model.Contains(thisAnswer)) { theUser.Answers = theUser.Answers.Replace(thisAnswer + ".pdf;", ""); } } theUser.Answers += model.ToString() + ".pdf;"; } else { done = true; } } if (!model.Chapter.Equals("All") && !done) { //Find all Chapters from the selected Unit IQueryable<AnswerApp.Models.Chapter> retrieved = from theChapters in db.Chapters where theChapters.Unit_Title.Equals(model.Unit) select theChapters; AnswerApp.Models.Chapter[] results = retrieved.ToArray<AnswerApp.Models.Chapter>(); bool UserHasAll = true; foreach (AnswerApp.Models.Chapter theChapter in results) { if (!UserHasAccess(theUser, theChapter.Textbook_Title + "_" + theChapter.Unit_Title + "_" + theChapter.Chapter_Title + "_All_All_All", db)) { UserHasAll = false; break; } } if (UserHasAll) { model.Chapter = "All"; UserAnswers = theUser.Answers.Split(new char[1] { ';' }); foreach (String Answer in UserAnswers) { String thisAnswer = Answer.Replace(".pdf", ""); if (model.Contains(thisAnswer)) { theUser.Answers = theUser.Answers.Replace(thisAnswer + ".pdf;", ""); } } theUser.Answers += model.ToString() + ".pdf;"; } else { done = true; } } if (!model.Unit.Equals("All") && !done) { //Find all Units from the selected Textbook IQueryable<AnswerApp.Models.Unit> retrieved = from theUnits in db.Units where theUnits.Textbook_Title.Equals(model.Textbook) select theUnits; AnswerApp.Models.Unit[] results = retrieved.ToArray<AnswerApp.Models.Unit>(); bool UserHasAll = true; foreach (AnswerApp.Models.Unit theUnit in results) { if (!UserHasAccess(theUser, theUnit.Textbook_Title + "_" + theUnit.Unit_Title + "_All_All_All_All", db)) { UserHasAll = false; break; } } if (UserHasAll) { model.Unit = "All"; UserAnswers = theUser.Answers.Split(new char[1] { ';' }); foreach (String Answer in UserAnswers) { String thisAnswer = Answer.Replace(".pdf", ""); if (model.Contains(thisAnswer)) { theUser.Answers = theUser.Answers.Replace(thisAnswer + ".pdf;", ""); } } theUser.Answers += model.ToString() + ".pdf;"; } else { done = true; } } db.SubmitChanges(); return true; }
public PriceBreakdown(SelectModel model, User thisUser, AnswerAppDataContext db) { this.Credit = thisUser.Credit; AnswerApp.Controllers.AnswersController theAnswerController = new AnswerApp.Controllers.AnswersController(); this.NumberOfSolutionsToPurchase = theAnswerController.NumberOfQuestions(model, db); //ViewData["NumberOfSolutionsToPurchase"] = this.NumberOfSolutionsToPurchase; //ViewData["TotalValue"] = (this.NumberOfSolutionsToPurchase * PriceOfSingleSolution).ToString("C"); //this.NumberOfSolutionsForThisUser = 0; //this.NumberSelectedUserAlreadyHas = 0; String[] UserAnswers; if (thisUser.Answers != null) { UserAnswers = thisUser.Answers.Split(new char[1] { ';' }); foreach (String theAnswer in UserAnswers) { SelectModel theModel = new SelectModel(theAnswer); int NumberOfSolutions = theAnswerController.NumberOfQuestions(theModel, db); this.NumberOfSolutionsForThisUser += NumberOfSolutions; if (model.Contains(theModel)) { this.NumberSelectedUserAlreadyHas += NumberOfSolutions; } } } //ViewData["NumberOfSolutionsForThisUser"] = this.NumberOfSolutionsForThisUser; //ViewData["NumberSelectedUserAlreadyHas"] = this.NumberSelectedUserAlreadyHas; this.SolutionsRemainingToBePurchased = (this.NumberOfSolutionsToPurchase - this.NumberSelectedUserAlreadyHas); //ViewData["SolutionsRemainingToBePurchased"] = this.SolutionsRemainingToBePurchased; this.RemainingCost = (this.NumberOfSolutionsToPurchase - this.NumberSelectedUserAlreadyHas) * PriceOfSingleSolution; //ViewData["RemainingCost"] = this.RemainingCost.ToString("C"); //ViewData["UserCredit"] = thisUser.Credit; this.TotalRemainingSolutions = this.SolutionsRemainingToBePurchased - thisUser.Credit; //ViewData["TotalRemainingSolutions"] = this.TotalRemainingSolutions; this.TotalRemainingPrice = this.TotalRemainingSolutions * PriceOfSingleSolution; //ViewData["TotalRemainingCost"] = this.TotalRemainingPrice.ToString("C"); this.UserLevel = this.NumberOfSolutionsForThisUser + thisUser.Credit; //ViewData["UserLevel"] = this.UserLevel; //int AdditionalCredits = 0;//To be determined below this.UpgradePrice = this.TotalRemainingPrice;//To be determined below this.UpgradePriceDifference = this.TotalRemainingPrice;//To be determined below //if the cost of an upgrade is less than the cost of all the solutions then the user gets the upgrade this.TargetNumberOfSolutionsAfterPurchase = this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased; if (this.TargetNumberOfSolutionsAfterPurchase > 1000)//they want 1000+ pack { } else if ((this.TargetNumberOfSolutionsAfterPurchase > 250))//want 1000 pack { if (this.UserLevel >= 250)//250 < UserLevel < 1000 { this.UpgradePriceDifference = PriceOf1000Pack - PriceOf250Pack; if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade { this.UpgradePrice = this.UpgradePriceDifference; } else { this.UpgradePrice = (1000 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; } this.AdditionalCredits = 1000 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased); } else if (this.UserLevel >= 100)//100 < UserLevel < 250 { this.UpgradePriceDifference = PriceOf1000Pack - PriceOf100Pack; if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade { this.UpgradePrice = this.UpgradePriceDifference; } else { this.UpgradePrice = (1000 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; } this.AdditionalCredits = 1000 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased); } else if (this.UserLevel >= 50)//50 < UserLevel < 100 { this.UpgradePriceDifference = PriceOf1000Pack - PriceOf50Pack; if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade { this.UpgradePrice = this.UpgradePriceDifference; } else { this.UpgradePrice = (1000 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; } this.AdditionalCredits = 1000 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased); } else if (this.UserLevel >= 10)//10 < UserLevel < 20 { this.UpgradePriceDifference = PriceOf1000Pack - PriceOf10Pack; if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade { this.UpgradePrice = this.UpgradePriceDifference; } else { this.UpgradePrice = (1000 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; } this.AdditionalCredits = 1000 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased); } else//if (UserLevel < 10)//0 < UserLevel < 10 { this.UpgradePriceDifference = PriceOf1000Pack - ((this.NumberOfSolutionsForThisUser + thisUser.Credit) * PriceOfSingleSolution); if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade { this.UpgradePrice = this.UpgradePriceDifference; } else { this.UpgradePrice = (1000 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; } this.AdditionalCredits = 1000 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased); } } else if ((this.TargetNumberOfSolutionsAfterPurchase > 100))//want 250 pack { if (this.UserLevel >= 100)//100 < UserLevel < 250 { this.UpgradePriceDifference = PriceOf250Pack - PriceOf100Pack; if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade { this.UpgradePrice = this.UpgradePriceDifference; } else { this.UpgradePrice = (250 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; } this.AdditionalCredits = 250 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased); } else if (this.UserLevel >= 50)//50 < UserLevel < 100 { this.UpgradePriceDifference = PriceOf250Pack - PriceOf50Pack; if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade { this.UpgradePrice = this.UpgradePriceDifference; } else { this.UpgradePrice = (250 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; } this.AdditionalCredits = 250 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased); } else if (this.UserLevel >= 10)//10 < UserLevel < 20 { this.UpgradePriceDifference = PriceOf50Pack - PriceOf10Pack; if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade { this.UpgradePrice = this.UpgradePriceDifference; } else { this.UpgradePrice = (250 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; } this.AdditionalCredits = 250 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased); } else//if (UserLevel < 10)//0 < UserLevel < 10 { this.UpgradePriceDifference = PriceOf250Pack - ((this.NumberOfSolutionsForThisUser + thisUser.Credit) * PriceOfSingleSolution); if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade { this.UpgradePrice = this.UpgradePriceDifference; } else { this.UpgradePrice = (250 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; } this.AdditionalCredits = 250 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased); } } else if ((this.TargetNumberOfSolutionsAfterPurchase > 50))//want 100 pack { if (this.UserLevel >= 50)//50 < UserLevel < 100 { this.UpgradePriceDifference = PriceOf100Pack - PriceOf50Pack; if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade { this.UpgradePrice = this.UpgradePriceDifference; } else { this.UpgradePrice = (100 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; } this.AdditionalCredits = 100 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased); } else if (this.UserLevel >= 10)//10 < UserLevel < 20 { this.UpgradePriceDifference = PriceOf100Pack - PriceOf10Pack; if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade { this.UpgradePrice = this.UpgradePriceDifference; } else { this.UpgradePrice = (100 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; } this.AdditionalCredits = 100 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased); } else//if (UserLevel < 10)//0 < UserLevel < 10 { this.UpgradePriceDifference = PriceOf100Pack - ((this.NumberOfSolutionsForThisUser + thisUser.Credit) * PriceOfSingleSolution); if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade { this.UpgradePrice = this.UpgradePriceDifference; } else { this.UpgradePrice = (100 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; } this.AdditionalCredits = 100 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased); } } else if ((this.TargetNumberOfSolutionsAfterPurchase > 10))//want 50 pack { if (this.UserLevel >= 10)//10 < UserLevel < 50 { this.UpgradePriceDifference = PriceOf50Pack - PriceOf10Pack; if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade { this.UpgradePrice = this.UpgradePriceDifference; } else { this.UpgradePrice = (50 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; } this.AdditionalCredits = 50 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased); } else//if (UserLevel <= 10)//0 < UserLevel < 10 { this.UpgradePriceDifference = PriceOf50Pack - ((this.NumberOfSolutionsForThisUser + thisUser.Credit) * PriceOfSingleSolution); if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade { this.UpgradePrice = this.UpgradePriceDifference; } else { this.UpgradePrice = (50 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; } this.AdditionalCredits = 50 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased); } } else//if ((TargetNumberOfSolutionsAfterPurchase <= 10)) { this.UpgradePriceDifference = PriceOf10Pack - ((this.NumberOfSolutionsForThisUser + thisUser.Credit) * PriceOfSingleSolution); if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade { this.UpgradePrice = this.UpgradePriceDifference; } else { this.UpgradePrice = (10 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; } this.AdditionalCredits = 10 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased); } if (this.UpgradePrice > this.UpgradePriceDifference) { this.UpgradePrice = this.UpgradePriceDifference; } this.UserLevelAfterPurchase = this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased + this.AdditionalCredits; this.UpgradeSavings = this.TotalRemainingPrice - this.UpgradePrice; if (this.UpgradeSavings > 0) { this.ShowUpgradeSavings = "true"; } else { this.ShowUpgradeSavings = "false"; } //if(this.UpgradePrice < UpgradePriceDifference) if (this.UpgradePrice < this.TotalRemainingPrice) { this.DisplayIndividualPurchasePrice = "false"; } else { this.DisplayIndividualPurchasePrice = "true"; } if(UserLevel < 10) {CurrentLevel = "Novice";} else if(UserLevel < 50) {CurrentLevel = "Apprentice";} else if(UserLevel < 100) {CurrentLevel = "Journeyman";} else if(UserLevel < 250) {CurrentLevel = "Adept";} else if(UserLevel < 1000) {CurrentLevel = "Expert";} else//if(UserLevel > 1000) {CurrentLevel = "Master";} if (UserLevelAfterPurchase <= 10) { UpgradeLevel = "Apprentice"; } else if (UserLevelAfterPurchase <= 50) { UpgradeLevel = "Journeyman"; } else if (UserLevelAfterPurchase <= 100) { UpgradeLevel = "Adept"; } else if (UserLevelAfterPurchase <= 250) { UpgradeLevel = "Expert"; } else if (UserLevelAfterPurchase <= 1000) { UpgradeLevel = "Master"; } else//if(UserLevel > 1000) {UpgradeLevel = "Doctor of Philosophy"; } }
public string DynamicPopulateMethod() { String message = ""; AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); AnswerApp.Models.User thisUser = db.Users.Single(d => d.UserName.Equals(User.Identity.Name)); System.Threading.SpinWait sw = new System.Threading.SpinWait(); //string knownCategoryValues; //System.Threading.SpinWait.SpinUntil(thisUser.MetaData.EndsWith("ready"), 1000); //while (!thisUser.MetaData.EndsWith("ready")) { sw.SpinOnce(); } //if (!thisUser.MetaData.EndsWith("ready")) { sw.SpinOnce(); }//return null; } //thisUser.MetaData = thisUser.MetaData.Replace("ready", ""); string knownCategoryValues = thisUser.MetaData; db.SubmitChanges(); StringDictionary incomingKnownCatagories = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); SelectModel theUsersSelection = new SelectModel(incomingKnownCatagories["textbook"] + "_" + incomingKnownCatagories["unit"] + "_" + incomingKnownCatagories["chapter"] + "_" + incomingKnownCatagories["section"] + "_" + incomingKnownCatagories["page"] + "_" + incomingKnownCatagories["question"]); String Textbook_Title = theUsersSelection.Textbook; String Unit_Title = theUsersSelection.Unit; String Chapter_Title = theUsersSelection.Chapter; String Section_Title = theUsersSelection.Section; String Page_Number = theUsersSelection.Page; String Question_Number = theUsersSelection.Question; //Populate parent groupings based on child groupings if (!Question_Number.Equals("All") && Page_Number.Equals("All")) { IQueryable<AnswerApp.Models.Question> retrieved; Question[] results; //Find all questions from the selected section retrieved = from theAnswers in db.Questions where theAnswers.Textbook_Title.Equals(Textbook_Title) && theAnswers.Section_Title.Equals(Section_Title) && theAnswers.Question_Number.Equals(Question_Number) select theAnswers; results = retrieved.ToArray<Question>(); //If there are no questions of this number from the selected section if (results.Length < 1) { //Find all questions from the selected chapter retrieved = from theAnswers in db.Questions where theAnswers.Textbook_Title.Equals(Textbook_Title) && theAnswers.Chapter_Title.Equals(Chapter_Title) && theAnswers.Question_Number.Equals(Question_Number) select theAnswers; results = retrieved.ToArray<Question>(); //If there are no questions of this number from the selected chapter if (results.Length < 1) { //Find all questions from the selected unit retrieved = from theAnswers in db.Questions where theAnswers.Textbook_Title.Equals(Textbook_Title) && theAnswers.Unit_Title.Equals(Unit_Title) && theAnswers.Question_Number.Equals(Question_Number) select theAnswers; results = retrieved.ToArray<Question>(); //If there are no questions of this number from the selected unit if (results.Length < 1) { //Find all questions from the selected textbook retrieved = from theAnswers in db.Questions where theAnswers.Textbook_Title.Equals(Textbook_Title) && theAnswers.Textbook_Title.Equals(Textbook_Title) && theAnswers.Question_Number.Equals(Question_Number) select theAnswers; results = retrieved.ToArray<Question>(); } } } if (results.Length > 1) { return "<span style=\"color:red;\">There are multiple Questions with that number. Please make a more specific selection.</span>"; } else if (results.Length == 1) { Page_Number = results.First().Page_Number; Section_Title = results.First().Section_Title; Chapter_Title = results.First().Chapter_Title; Unit_Title = results.First().Unit_Title; } else if (results.Length == 0) { return "<span style=\"color:red;\">Error: The selected Question could not be found. Please contact the Solvation.ca developement team. " + knownCategoryValues + "</span>"; } } if (!Page_Number.Equals("All") && Section_Title.Equals("All")) { //Section_Title = db.Pages.Single<Page>(p => p.Page_Number.Equals(Page_Number)).Section_Title; IQueryable<AnswerApp.Models.Page> retrieved = null; retrieved = from theAnswers in db.Pages where theAnswers.Textbook_Title.Equals(Textbook_Title) && theAnswers.Page_Number.Equals(Page_Number) select theAnswers; Section_Title = retrieved.First().Section_Title;// db.Pages.Single<Page>(s => s.Page_Title.Equals(Page_Title)).Section_Title; } if (!Section_Title.Equals("All") && Chapter_Title.Equals("All")) { IQueryable<AnswerApp.Models.Section> retrieved = null; retrieved = from theAnswers in db.Sections where theAnswers.Textbook_Title.Equals(Textbook_Title) && theAnswers.Section_Title.Equals(Section_Title) select theAnswers; Chapter_Title = retrieved.First().Chapter_Title;// db.Sections.Single<Section>(s => s.Section_Title.Equals(Section_Title)).Chapter_Title; } if (!Chapter_Title.Equals("All") && Unit_Title.Equals("All")) { //Unit_Title = db.Chapters.Single<Chapter>(c => c.Chapter_Title.Equals(Chapter_Title)).Unit_Title; IQueryable<AnswerApp.Models.Chapter> retrieved = null; retrieved = from theAnswers in db.Chapters where theAnswers.Textbook_Title.Equals(Textbook_Title) && theAnswers.Chapter_Title.Equals(Chapter_Title) select theAnswers; Unit_Title = retrieved.First().Unit_Title;// db.Chapters.Single<Chapter>(s => s.Chapter_Title.Equals(Chapter_Title)).Unit_Title; } if (Textbook_Title.Equals("Select a Textbook")) { return "Please make a selection"; } if (Textbook_Title.Equals("")) { return "Please Select a textbook"; } theUsersSelection.Textbook = Textbook_Title; theUsersSelection.Unit = Unit_Title; theUsersSelection.Chapter = Chapter_Title; theUsersSelection.Section = Section_Title; theUsersSelection.Page = Page_Number; theUsersSelection.Question = Question_Number; AnswerApp.Controllers.AnswersController theAnswerController = new AnswerApp.Controllers.AnswersController(); int NumberOfSolutionsToPurchase = theAnswerController.NumberOfQuestions(theUsersSelection, db); double TotalValue = (NumberOfSolutionsToPurchase * AnswerApp.Controllers.AnswersController.PriceOfSingleSolution); int NumberOfSolutionsForThisUser = 0; int NumberSelectedUserAlreadyHas = 0; String[] UserAnswers; if (thisUser.Answers != null) { UserAnswers = thisUser.Answers.Split(new char[1] { ';' }); foreach (String theAnswer in UserAnswers) { SelectModel currentAnswer = new SelectModel(theAnswer); int NumberOfSolutionsInCurrentAnswer = theAnswerController.NumberOfQuestions(currentAnswer, db); NumberOfSolutionsForThisUser += NumberOfSolutionsInCurrentAnswer; if (theUsersSelection.Contains(currentAnswer)) { NumberSelectedUserAlreadyHas += NumberOfSolutionsInCurrentAnswer; } } } int SolutionsRemainingToBePurchased = (NumberOfSolutionsToPurchase - NumberSelectedUserAlreadyHas); int TotalRemainingSolutions = SolutionsRemainingToBePurchased - thisUser.Credit; if(SolutionsRemainingToBePurchased > 1) { if (NumberOfSolutionsForThisUser > 1) { message += "You have seleted " + NumberOfSolutionsToPurchase + " solutions. "; } else { message += "You have seleted " + NumberOfSolutionsToPurchase + " solution. "; } message += SolutionsRemainingToBePurchased + " are new. "; if (TotalRemainingSolutions >= 1) { if (thisUser.Credit > 1) { message += "You have " + thisUser.Credit + " credits, the remaining " + TotalRemainingSolutions + " will need to be purchased."; } else { message += "You have " + thisUser.Credit + " credit, the remaining " + TotalRemainingSolutions + " will need to be purchased."; } } else { if (thisUser.Credit > 1) { message += "You have " + thisUser.Credit + " credits. "; } else { message += "You have " + thisUser.Credit + " credit. "; } } } else if(SolutionsRemainingToBePurchased == 1) { if (NumberOfSolutionsForThisUser > 1) { message += "You have seleted " + NumberOfSolutionsToPurchase + " solutions. "; } else { message += "You have seleted " + NumberOfSolutionsToPurchase + " solution. "; } message += SolutionsRemainingToBePurchased + " is new. "; if (TotalRemainingSolutions >= 1) { if (thisUser.Credit > 1) { message += "You have " + thisUser.Credit + " credits, the remaining " + TotalRemainingSolutions + " will need to be purchased."; } else { message += "You have " + thisUser.Credit + " credit, the remaining " + TotalRemainingSolutions + " will need to be purchased."; } } else { if (thisUser.Credit > 1) { message += "You have " + thisUser.Credit + " credits. "; } else { message += "You have " + thisUser.Credit + " credit. "; } } } else//if(SolutionsRemainingToBePurchased <= 1) { return "You presently have access to all of the selected solutions"; } return message; return theUsersSelection.Textbook + "_" + theUsersSelection.Unit + "_" + theUsersSelection.Chapter + "_" + theUsersSelection.Section + "_" + theUsersSelection.Page + "_" + theUsersSelection.Question; //return theModel.Textbook + "_" + theModel.Unit + "_" + theModel.Chapter + "_" + theModel.Section + "_" + theModel.Page + "_" + theModel.Question; }
public String GenerateSelectionList(SelectModel model, int Index) { String SelectionList = ""; AnswerApp.Models.SelectModel newModel = new AnswerApp.Models.SelectModel(); newModel.Textbook = model.Textbook; newModel.Unit = model.Unit; newModel.Chapter = model.Chapter; newModel.Section = model.Section; newModel.Page = model.Page; newModel.Question = model.Question; AnswerApp.Controllers.AnswersController thisAnswerController = new AnswerApp.Controllers.AnswersController(); AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); AnswerApp.Models.User thisUser = db.Users.Single<User>(u => u.UserName.Equals(User.Identity.Name)); if (thisUser.Answers == null) { return null; } String[] ThisUsersAnswers = thisUser.Answers.Split(new char[1] { ';' }); if (model.Textbook.Equals("All"))//All Textbooks have been specified { IQueryable<AnswerApp.Models.Textbook> retrieved = from theAnswers in db.Textbooks select theAnswers; AnswerApp.Models.Textbook[] preresults = retrieved.ToArray<AnswerApp.Models.Textbook>(); System.Linq.IOrderedEnumerable<AnswerApp.Models.Textbook> results = preresults.OrderBy(Textbook => Textbook.Title); foreach (Textbook theTextbook in results) { model.Textbook = theTextbook.Title; if (UserHasAccess(User.Identity.Name, model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf") && (NumberOfQuestions(model, db) > 0)) { SelectionList += Collapsable("<a href=\"/Answers/ViewAnswer/" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\"><img src=\"/Answers/GetImage/" + theTextbook.Title + "\" height=\"120px\" alt=\"" + theTextbook.Title + "\"/></a><br />", GenerateSelectionList(model, Index)); } else { foreach (String thisAnswer in ThisUsersAnswers) { String[] theseProperties = thisAnswer.Split(new char[1] { '_' }); if (!(theseProperties.Length < 2)) { AnswerApp.Models.SelectModel thisModel = new AnswerApp.Models.SelectModel(); thisModel.Textbook = theseProperties[0]; thisModel.Unit = theseProperties[1]; thisModel.Chapter = theseProperties[2]; thisModel.Section = theseProperties[3]; thisModel.Page = theseProperties[4]; thisModel.Question = theseProperties[5].Split(new char[1] { '.' })[0];//Truncate ".pdf" from the end of the file name if (model.Contains(thisModel))//thisModel.Textbook.Equals(model.Textbook))//YOU ARE HERE!!! { SelectionList += Collapsable( "<a style=\"color: #00AAFF\" href=\"/Answers/ViewAnswer/" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\"><img src=\"/Answers/GetImage/" + theTextbook.Title + "\" height=\"200px\" alt=\"" + theTextbook.Title + "\"/></a><br />", GenerateSelectionList(model, Index)); break; } } else { SelectionList += GenerateSelectionList(model, Index); } } } model.Textbook = "All"; } } if (model.Unit.Equals("All"))//All units have been specified { IQueryable<AnswerApp.Models.Unit> retrieved = from theAnswers in db.Units where theAnswers.Textbook_Title.Equals(model.Textbook) select theAnswers; AnswerApp.Models.Unit[] preresults = retrieved.ToArray<AnswerApp.Models.Unit>(); System.Linq.IOrderedEnumerable<AnswerApp.Models.Unit> results = preresults.OrderBy(Unit => Unit.Unit_Title); foreach (Unit theUnit in results) { model.Unit = theUnit.Unit_Title; if (UserHasAccess(User.Identity.Name, model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf") && (NumberOfQuestions(model, db) > 0)) { SelectionList += Collapsable( "<a href=\"/Answers/ViewAnswer/" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">" + theUnit.Unit_Title + "</a><br />", GenerateSelectionList(model, Index)); } else { foreach (String thisAnswer in ThisUsersAnswers) { String[] theseProperties = thisAnswer.Split(new char[1] { '_' }); if (!(theseProperties.Length < 2)) { AnswerApp.Models.SelectModel thisModel = new AnswerApp.Models.SelectModel(); thisModel.Textbook = theseProperties[0]; thisModel.Unit = theseProperties[1]; thisModel.Chapter = theseProperties[2]; thisModel.Section = theseProperties[3]; thisModel.Page = theseProperties[4]; thisModel.Question = theseProperties[5].Split(new char[1] { '.' })[0];//Truncate ".pdf" from the end of the file name if (model.Contains(thisModel))//thisModel.Unit.Equals(model.Unit))//YOU ARE HERE!!! { SelectionList += Collapsable( "<a style=\"color: #00AAFF\" href=\"/Answers/ViewAnswer/" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">" + theUnit.Unit_Title + "</a><br />", GenerateSelectionList(model, Index)); break; } } else { SelectionList += GenerateSelectionList(model, Index); } } } model.Unit = "All"; } } else if (model.Chapter.Equals("All"))//Only one unit has been specified { IQueryable<AnswerApp.Models.Chapter> retrieved = from theAnswers in db.Chapters where theAnswers.Textbook_Title.Equals(model.Textbook) && theAnswers.Unit_Title.Equals(model.Unit) select theAnswers; AnswerApp.Models.Chapter[] preresults = retrieved.ToArray<AnswerApp.Models.Chapter>(); System.Linq.IOrderedEnumerable<AnswerApp.Models.Chapter> results = preresults.OrderBy(Chapter => Chapter.Chapter_Title); foreach (Chapter theChapter in results) { model.Chapter = theChapter.Chapter_Title; if (UserHasAccess(User.Identity.Name, model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf") && (NumberOfQuestions(model, db) > 0)) { SelectionList += Collapsable( "<a href=\"/Answers/ViewAnswer/" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">" + theChapter.Chapter_Title + "</a><br />", GenerateSelectionList(model, Index)); } else { foreach (String thisAnswer in ThisUsersAnswers) { String[] theseProperties = thisAnswer.Split(new char[1] { '_' }); if (!(theseProperties.Length < 2)) { AnswerApp.Models.SelectModel thisModel = new AnswerApp.Models.SelectModel(); thisModel.Textbook = theseProperties[0]; thisModel.Unit = theseProperties[1]; thisModel.Chapter = theseProperties[2]; thisModel.Section = theseProperties[3]; thisModel.Page = theseProperties[4]; thisModel.Question = theseProperties[5].Split(new char[1] { '.' })[0];//Truncate ".pdf" from the end of the file name if (model.Contains(thisModel))//thisModel.Chapter.Equals(model.Chapter))//YOU ARE HERE!!! { SelectionList += Collapsable( "<a style=\"color: #00AAFF\" href=\"/Answers/ViewAnswer/" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">" + theChapter.Chapter_Title + "</a><br />", GenerateSelectionList(model, Index)); break; } } else { SelectionList += GenerateSelectionList(model, Index); } } } model.Chapter = "All"; } } else if (model.Section.Equals("All"))//Only one Chapter has been specified { IQueryable<AnswerApp.Models.Section> retrieved = from theAnswers in db.Sections where theAnswers.Textbook_Title.Equals(model.Textbook) && theAnswers.Unit_Title.Equals(model.Unit) && theAnswers.Chapter_Title.Equals(model.Chapter) select theAnswers; AnswerApp.Models.Section[] preresults = retrieved.ToArray<AnswerApp.Models.Section>(); System.Linq.IOrderedEnumerable<AnswerApp.Models.Section> results = preresults.OrderBy(Section => Section.Section_Title); foreach (Section theSection in results) { model.Section = theSection.Section_Title; if (UserHasAccess(User.Identity.Name, model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf") && (NumberOfQuestions(model, db) > 0)) { SelectionList += Collapsable( "<a href=\"/Answers/ViewAnswer/" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">" + theSection.Section_Title + "</a><br />", GenerateSelectionList(model, Index)); } else { foreach (String thisAnswer in ThisUsersAnswers) { String[] theseProperties = thisAnswer.Split(new char[1] { '_' }); if (!(theseProperties.Length < 2)) { AnswerApp.Models.SelectModel thisModel = new AnswerApp.Models.SelectModel(); thisModel.Textbook = theseProperties[0]; thisModel.Unit = theseProperties[1]; thisModel.Chapter = theseProperties[2]; thisModel.Section = theseProperties[3]; thisModel.Page = theseProperties[4]; thisModel.Question = theseProperties[5].Split(new char[1] { '.' })[0];//Truncate ".pdf" from the end of the file name if (model.Contains(thisModel))//thisModel.Section.Equals(model.Section))//YOU ARE HERE!!! { SelectionList += Collapsable( "<a style=\"color: #00AAFF\" href=\"/Answers/ViewAnswer/" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">" + theSection.Section_Title + "</a><br />", GenerateSelectionList(model, Index)); break; } } else { SelectionList += GenerateSelectionList(model, Index); } } } model.Section = "All"; } } else if (model.Page.Equals("All"))//Only one Section has been specified { IQueryable<AnswerApp.Models.Page> retrieved = from theAnswers in db.Pages where theAnswers.Textbook_Title.Equals(model.Textbook) && theAnswers.Unit_Title.Equals(model.Unit) && theAnswers.Chapter_Title.Equals(model.Chapter) && theAnswers.Section_Title.Equals(model.Section) select theAnswers; AnswerApp.Models.Page[] preresults = retrieved.ToArray<AnswerApp.Models.Page>(); System.Linq.IOrderedEnumerable<AnswerApp.Models.Page> results = preresults.OrderBy(Page => Page.Page_Number); foreach (Page thePage in results) { model.Page = thePage.Page_Number; if (UserHasAccess(User.Identity.Name, model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf") && (NumberOfQuestions(model, db) > 0)) { SelectionList += Collapsable( "<a href=\"/Answers/ViewAnswer/" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">Page " + thePage.Page_Number + "</a><br />", GenerateSelectionList(model, Index)); } else { foreach (String thisAnswer in ThisUsersAnswers) { String[] theseProperties = thisAnswer.Split(new char[1] { '_' }); if (!(theseProperties.Length < 2)) { AnswerApp.Models.SelectModel thisModel = new AnswerApp.Models.SelectModel(); thisModel.Textbook = theseProperties[0]; thisModel.Unit = theseProperties[1]; thisModel.Chapter = theseProperties[2]; thisModel.Section = theseProperties[3]; thisModel.Page = theseProperties[4]; thisModel.Question = theseProperties[5].Split(new char[1] { '.' })[0];//Truncate ".pdf" from the end of the file name if (model.Contains(thisModel))//thisModel.Page.Equals(model.Page) && thisModel.Section)//YOU ARE HERE!!! { SelectionList += Collapsable( "<a style=\"color: #00AAFF\" href=\"/Answers/ViewAnswer/" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">Page " + thePage.Page_Number + "</a><br />", GenerateSelectionList(model, Index)); break; } } else { SelectionList += GenerateSelectionList(model, Index); } } } model.Page = "All"; } } else if (model.Question.Equals("All"))//Only one page has been specified { IQueryable<AnswerApp.Models.Question> retrieved = from theAnswers in db.Questions where theAnswers.Textbook_Title.Equals(model.Textbook) && theAnswers.Unit_Title.Equals(model.Unit) && theAnswers.Chapter_Title.Equals(model.Chapter) && theAnswers.Section_Title.Equals(model.Section) && theAnswers.Page_Number.Equals(model.Page) select theAnswers; AnswerApp.Models.Question[] preresults = retrieved.ToArray<AnswerApp.Models.Question>(); System.Linq.IOrderedEnumerable<AnswerApp.Models.Question> results = preresults.OrderBy(Question => Convert.ToInt32(Question.Question_Number)); foreach (Question theQuestion in results) { model.Question = theQuestion.Question_Number; if (UserHasAccess(User.Identity.Name, model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf") && (NumberOfQuestions(model, db) > 0)) { SelectionList += "<a href=\"/Answers/ViewAnswer/" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">Question " + theQuestion.Question_Number + "</a><br />" + GenerateSelectionList(model, Index); } else { foreach (String thisAnswer in ThisUsersAnswers) { String[] theseProperties = thisAnswer.Split(new char[1] { '_' }); if (!(theseProperties.Length < 2)) { AnswerApp.Models.SelectModel thisModel = new AnswerApp.Models.SelectModel(); thisModel.Textbook = theseProperties[0]; thisModel.Unit = theseProperties[1]; thisModel.Chapter = theseProperties[2]; thisModel.Section = theseProperties[3]; thisModel.Page = theseProperties[4]; thisModel.Question = theseProperties[5].Split(new char[1] { '.' })[0];//Truncate ".pdf" from the end of the file name if (model.Contains(thisModel))//thisModel.Question.Equals(model.Question))//YOU ARE HERE!!! { SelectionList += "<a style=\"color: #00AAFF\" href=\"/Answers/ViewAnswer/" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">Question " + theQuestion.Question_Number + "</a><br />" + GenerateSelectionList(model, Index); break; } } else { SelectionList += GenerateSelectionList(model, Index); } } } model.Question = "All"; } } return SelectionList; }
public string Test() { string argument = "n/a"; AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); AnswerApp.Models.User administrator = db.Users.Single<AnswerApp.Models.User>(a => a.UserName.Equals("administrator")); administrator.MetaData += "(in) "; //Post back to either sandbox or live string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr"; string strLive = "https://www.paypal.com/cgi-bin/webscr"; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strLive);//Sandbox); //Set values for the request back req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; byte[] param = HttpContext.Current.Request.BinaryRead(HttpContext.Current.Request.ContentLength);//byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength); string strRequest = Encoding.ASCII.GetString(param); strRequest += "&cmd=_notify-validate"; req.ContentLength = strRequest.Length; //Send the request to PayPal and get the response StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII); streamOut.Write(strRequest); streamOut.Close(); StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream()); string strResponse = streamIn.ReadToEnd(); streamIn.Close(); if (strResponse == "VERIFIED") { String[] parameters = strRequest.Split(new char[1] { '&' }); String theParameterProxy = "error 03148"; String[] KeyValue = new String[2]; String Key = "", Value = ""; String Properties = ""; String UserName = ""; String FileName = ""; String[] ParsedFileProperties = null; double Price = 0; String ItemName = ""; foreach (String theParameter in parameters) { KeyValue = theParameter.Split(new char[1] { '=' }); Key = KeyValue[0]; Value = KeyValue[1]; if (Key.Equals("transaction_subject")) { administrator.MetaData += " transaction_subject: " + Value;//debug db.SubmitChanges();//debug Properties = Value.Replace('+', ' '); UserName = Properties.Split(new char[1] { '_' })[0]; FileName = Properties.Replace(UserName + "_", ""); ParsedFileProperties = FileName.Split(new char[1] { '_' }); } else if (Key.Equals("mc_gross")) { administrator.MetaData += " mc_gross: " + Value;//debug db.SubmitChanges();//debug Price = Convert.ToDouble(Value); } else if (Key.Equals("item_name")) { administrator.MetaData += " item_name: " + Value;//debug db.SubmitChanges();//debug ItemName = Value.Replace('+', ' '); } } AnswerApp.Models.User theUser = db.Users.Single<User>(u => u.UserName.Equals(UserName)); SelectModel model = new AnswerApp.Models.SelectModel(); if (ParsedFileProperties.Length > 0) { model.Textbook = ParsedFileProperties[0]; } if (ParsedFileProperties.Length > 1) { model.Unit = ParsedFileProperties[1]; } else { if (ItemName.Equals("1000-Pack of Solvation Credits")) { if (Math.Abs(Price - AnswerApp.Controllers.AnswersController.PriceOf1000Pack) < 0.01) { theUser.Credit += 1000; } } else if (ItemName.Equals("250-Pack of Solvation Credits")) { if (Math.Abs(Price - AnswerApp.Controllers.AnswersController.PriceOf250Pack) < 0.01) { theUser.Credit += 250; } } else if (ItemName.Equals("100-Pack of Solvation Credits")) { if (Math.Abs(Price - AnswerApp.Controllers.AnswersController.PriceOf100Pack) < 0.01) { theUser.Credit += 100; } } else if (ItemName.Equals("50-Pack of Solvation Credits")) { if (Math.Abs(Price - AnswerApp.Controllers.AnswersController.PriceOf50Pack) < 0.01) { theUser.Credit += 50; } } else if (ItemName.Equals("10-Pack of Solvation Credits")) { if (Math.Abs(Price - AnswerApp.Controllers.AnswersController.PriceOf10Pack) < 0.01) { theUser.Credit += 10; } } else if (ItemName.Equals("Single Solvation Credit")) { if (Math.Abs(Price - AnswerApp.Controllers.AnswersController.PriceOfSingleSolution) < 0.01) { theUser.Credit += 1; } } administrator.MetaData += "ItemName: " + ItemName; db.SubmitChanges(); return strResponse; } if (ParsedFileProperties.Length > 2) { model.Chapter = ParsedFileProperties[2]; } if (ParsedFileProperties.Length > 3) { model.Section = ParsedFileProperties[3]; } if (ParsedFileProperties.Length > 4) { model.Page = ParsedFileProperties[4]; } if (ParsedFileProperties.Length > 5) { model.Question = ParsedFileProperties[5]; } if (ParsedFileProperties.Length > 6) { FileName = model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question; } PriceBreakdown thePriceBreakdown = new PriceBreakdown(model, theUser, db); if (ParsedFileProperties.Length > 6)//the upgrade was selected { administrator.MetaData += " UpgradePrice: " + thePriceBreakdown.UpgradePrice.ToString("C");//debug /*if (Math.Abs(Price - thePriceBreakdown.UpgradePrice) >= 0.01) { return strResponse; }//*/ theUser.Credit = Convert.ToInt32(ParsedFileProperties[6]); db.SubmitChanges();//debug } else//the individual solutions were purchased { administrator.MetaData += " TotalRemainingPrice: " + thePriceBreakdown.TotalRemainingPrice.ToString("C");//debug /*if (Math.Abs(Price - thePriceBreakdown.TotalRemainingPrice) >= 0.01) { return strResponse; }//*/ theUser.Credit = Convert.ToInt32("0"); db.SubmitChanges();//debug } //make sure the selection contains solutions AnswerApp.Controllers.AnswersController theAnswersController = new AnswerApp.Controllers.AnswersController(); if(!(theAnswersController.NumberOfQuestions(model, db) > 0)){return strResponse;} //Enter this answer String[] UserAnswers; UserAnswers= null; if (theUser.Answers != null) { UserAnswers = theUser.Answers.Split(new char[1] { ';' }); foreach (String Answer in UserAnswers) { String thisAnswer = Answer.Replace(".pdf", ""); if (model.Contains(thisAnswer)) { theUser.Answers = theUser.Answers.Replace(thisAnswer + ".pdf;", ""); } } } theUser.Answers += FileName + ".pdf;"; bool done = false; if (!model.Question.Equals("All") && !done) { //Find all questions from the selected section IQueryable<AnswerApp.Models.Question> retrieved = from theAnswers in db.Questions where theAnswers.Page_Number.Equals(model.Page) select theAnswers; Question[] results = retrieved.ToArray<Question>(); bool UserHasAll = true; foreach (Question theQuestion in results) { if (!UserHasAccess(theUser, theQuestion.Textbook_Title + "_" + theQuestion.Unit_Title + "_" + theQuestion.Chapter_Title + "_" + theQuestion.Section_Title + "_" + theQuestion.Page_Number + "_" + theQuestion.Question_Number + ".pdf", db)) { UserHasAll = false; break; } } if (UserHasAll) { model.Question = "All"; FileName = model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_All"; UserAnswers = theUser.Answers.Split(new char[1] { ';' }); foreach (String Answer in UserAnswers) { String thisAnswer = Answer.Replace(".pdf", ""); if (model.Contains(thisAnswer)) { theUser.Answers = theUser.Answers.Replace(thisAnswer + ".pdf;", ""); } } theUser.Answers += FileName + ".pdf;"; } else { done = true; } } if (!model.Page.Equals("All") && !done) { //Find all questions from the selected section IQueryable<AnswerApp.Models.Page> retrieved = from thePages in db.Pages where thePages.Section_Title.Equals(model.Section) select thePages; AnswerApp.Models.Page[] results = retrieved.ToArray<AnswerApp.Models.Page>(); bool UserHasAll = true; foreach (AnswerApp.Models.Page thePage in results) { if (!UserHasAccess(theUser, thePage.Textbook_Title + "_" + thePage.Unit_Title + "_" + thePage.Chapter_Title + "_" + thePage.Section_Title + "_" + thePage.Page_Number + "_All", db)) { UserHasAll = false; break; } } if (UserHasAll) { model.Page = "All"; FileName = model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_All_All"; UserAnswers = theUser.Answers.Split(new char[1] { ';' }); foreach (String Answer in UserAnswers) { String thisAnswer = Answer.Replace(".pdf", ""); if (model.Contains(thisAnswer)) { theUser.Answers = theUser.Answers.Replace(thisAnswer + ".pdf;", ""); } } theUser.Answers += FileName + ".pdf;"; } else { done = true; } } if (!model.Section.Equals("All") && !done) { //Find all Secrtions from the selected Chapter IQueryable<AnswerApp.Models.Section> retrieved = from theSections in db.Sections where theSections.Chapter_Title.Equals(model.Chapter) select theSections; AnswerApp.Models.Section[] results = retrieved.ToArray<AnswerApp.Models.Section>(); bool UserHasAll = true; foreach (AnswerApp.Models.Section theSection in results) { if (!UserHasAccess(theUser, theSection.Textbook_Title + "_" + theSection.Unit_Title + "_" + theSection.Chapter_Title + "_" + theSection.Section_Title + "_All_All", db)) { UserHasAll = false; break; } } if (UserHasAll) { model.Section = "All"; FileName = model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_All_All_All"; UserAnswers = theUser.Answers.Split(new char[1] { ';' }); foreach (String Answer in UserAnswers) { String thisAnswer = Answer.Replace(".pdf", ""); if (model.Contains(thisAnswer)) { theUser.Answers = theUser.Answers.Replace(thisAnswer + ".pdf;", ""); } } theUser.Answers += FileName + ".pdf;"; } else { done = true; } } if (!model.Chapter.Equals("All") && !done) { //Find all Chapters from the selected Unit IQueryable<AnswerApp.Models.Chapter> retrieved = from theChapters in db.Chapters where theChapters.Unit_Title.Equals(model.Unit) select theChapters; AnswerApp.Models.Chapter[] results = retrieved.ToArray<AnswerApp.Models.Chapter>(); bool UserHasAll = true; foreach (AnswerApp.Models.Chapter theChapter in results) { if (!UserHasAccess(theUser, theChapter.Textbook_Title + "_" + theChapter.Unit_Title + "_" + theChapter.Chapter_Title + "_All_All_All", db)) { UserHasAll = false; break; } } if (UserHasAll) { model.Chapter = "All"; FileName = model.Textbook + "_" + model.Unit + "_All_All_All_All"; UserAnswers = theUser.Answers.Split(new char[1] { ';' }); foreach (String Answer in UserAnswers) { String thisAnswer = Answer.Replace(".pdf", ""); if (model.Contains(thisAnswer)) { theUser.Answers = theUser.Answers.Replace(thisAnswer + ".pdf;", ""); } } theUser.Answers += FileName + ".pdf;"; } else { done = true; } } if (!model.Unit.Equals("All") && !done) { //Find all Units from the selected Textbook IQueryable<AnswerApp.Models.Unit> retrieved = from theUnits in db.Units where theUnits.Textbook_Title.Equals(model.Textbook) select theUnits; AnswerApp.Models.Unit[] results = retrieved.ToArray<AnswerApp.Models.Unit>(); bool UserHasAll = true; foreach (AnswerApp.Models.Unit theUnit in results) { if (!UserHasAccess(theUser, theUnit.Textbook_Title + "_" + theUnit.Unit_Title + "_All_All_All_All", db)) { UserHasAll = false; break; } } if (UserHasAll) { model.Unit = "All"; FileName = model.Textbook + "_All_All_All_All_All"; UserAnswers = theUser.Answers.Split(new char[1] { ';' }); foreach (String Answer in UserAnswers) { String thisAnswer = Answer.Replace(".pdf", ""); if (model.Contains(thisAnswer)) { theUser.Answers = theUser.Answers.Replace(thisAnswer + ".pdf;", ""); } } theUser.Answers += FileName + ".pdf;"; } else { done = true; } } administrator.MetaData += " request: " + strRequest + " response: " + strResponse + " if: " + theParameterProxy; db.SubmitChanges(); //check the payment_status is Completed //check that txn_id has not been previously processed //check that receiver_email is your Primary PayPal email //check that payment_amount/payment_currency are correct //process payment } else if (strResponse == "INVALID") { //log for manual investigation administrator.MetaData += " request: " + strRequest + " response: " + strResponse + " else if: " + argument; db.SubmitChanges(); } else { //log response/ipn data for manual investigation administrator.MetaData += " request: " + strRequest + " response: " + strResponse + " else: " + argument; db.SubmitChanges(); } return strResponse; }