partial void UpdateUser(User instance);
partial void DeleteUser(User instance);
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; }
partial void InsertUser(User instance);
//Determines whether a user has access to a given grouping of solutions public Boolean UserHasAccess(User theUser, String FileName, AnswerAppDataContext db) { Boolean UserHasAccess = false; //Disect the file name for it's file properties String[] properties = FileName.Split(new char[1] { '_' }); AnswerApp.Models.SelectModel model = new AnswerApp.Models.SelectModel(); model.Textbook = properties[0]; model.Unit = properties[1]; model.Chapter = properties[2]; model.Section = properties[3]; model.Page = properties[4]; model.Question = properties[5].Split(new char[1] { '.' })[0];//Truncate ".pdf" from the end of the file name if (theUser.Answers == null) { return false; } String[] UserAnswers = theUser.Answers.Split(new char[2] { ',', ';' }); if (UserAnswers.Length < 2) { return false; } foreach (String thisAnswer in UserAnswers) { if (thisAnswer.Equals(FileName) || thisAnswer.Equals(FileName + ".pdf")) { return true; }//They have purchased this exact selection previously String[] theseProperties = thisAnswer.Split(new char[1] { '_' }); if (theseProperties.Length < 2) { return false; } 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 (thisModel.Unit.Equals("All") && thisModel.Textbook.Equals(model.Textbook)) { return true; } else if (thisModel.Chapter.Equals("All") && thisModel.Unit.Equals(model.Unit) && !thisModel.Unit.Equals("All")) { return true; } else if (thisModel.Section.Equals("All") && thisModel.Chapter.Equals(model.Chapter) && !thisModel.Chapter.Equals("All")) { return true; } else if (thisModel.Page.Equals("All") && thisModel.Section.Equals(model.Section) && !thisModel.Section.Equals("All")) { return true; } else if (thisModel.Question.Equals("All") && thisModel.Page.Equals(model.Page) && !thisModel.Page.Equals("All")) { return true; } } return UserHasAccess; }
public ActionResult ViewAnswer(string argument, SelectModel model) { ViewData["SelectionList"] = "Error: No list"; ViewData["RenderAnswer"] = "false";//don't render practice answer before the user has answered it String FilenameExtensionless = "" + model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question; ViewData["FileNameExtensionless"] = FilenameExtensionless; String FileName = "" + FilenameExtensionless + ".pdf"; ViewData["FileName"] = FileName; ViewData["PracticeProblemFileName"] = "" + ViewData["FileNameExtensionless"] + "_Practice Problem.png"; //ViewData["CorrectAnswer"] = "";// null; ViewData["HasPracticeProblem"] = "false"; ViewData["SelectionList"] = GenerateSelectionList(model); AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); AnswerApp.Models.User theUser = new AnswerApp.Models.User(); theUser = db.Users.Single(u => u.UserName.Equals(User.Identity.Name)); //if (theUser != null) { //if (theUser.Answers != null) { if (UserHasAccess(User.Identity.Name, FileName)) { if ((NumberOfQuestions(model, db) == 1) && model.Question.Equals("All")) { IQueryable<Question> find = from theQuestions in db.Questions where theQuestions.Textbook_Title.Equals(model.Textbook) && theQuestions.Unit_Title.Equals(model.Unit) && theQuestions.Chapter_Title.Equals(model.Chapter) && theQuestions.Section_Title.Equals(model.Section) && theQuestions.Page_Number.Equals(model.Page) //&& theQuestions.Question_Number.Equals(model.Question) select theQuestions; Question result = find.First(); model.Question = result.Question_Number; FileName = model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf"; ViewData["FileName"] = FileName; } IQueryable<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) && theAnswers.Question_Number.Equals(model.Question) select theAnswers; Question[] results = retrieved.ToArray<Question>(); if (results.Length != 0) { AnswerApp.Models.Question theSolution = results.First<Question>(); if (theSolution.Practice_Problem != null) { ViewData["HasPracticeProblem"] = "true"; } } //AnswerApp.Models.Question theSolution = db.Questions.Single(u => u.Question_Id.Equals return View("ViewAnswer", model); } else { if (NumberOfQuestions(model, db) > 0) { if (AddSolutionByCredit(theUser, db, model)) { if ((NumberOfQuestions(model, db) == 1) && model.Question.Equals("All")) { IQueryable<Question> find = from theQuestions in db.Questions where theQuestions.Textbook_Title.Equals(model.Textbook) && theQuestions.Unit_Title.Equals(model.Unit) && theQuestions.Chapter_Title.Equals(model.Chapter) && theQuestions.Section_Title.Equals(model.Section) && theQuestions.Page_Number.Equals(model.Page) //&& theQuestions.Question_Number.Equals(model.Question) select theQuestions; Question[] findings = find.ToArray(); if (findings.Length > 0) { Question result = findings.First(); model.Question = result.Question_Number; FileName = model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf"; ViewData["FileName"] = FileName; } } IQueryable<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) && theAnswers.Question_Number.Equals(model.Question) select theAnswers; Question[] results = retrieved.ToArray<Question>(); if (results.Length != 0) { AnswerApp.Models.Question theSolution = results.First<Question>(); if (theSolution.Practice_Problem != null) { ViewData["HasPracticeProblem"] = "true"; } } return View("ViewAnswer", model); } else { return RedirectToAction("Pay", "Answers", model); } } else { return RedirectToAction("Index", "Home", model); } } } } return View(model);// RedirectToAction("LogIn", "Account"); }
public PriceBreakdown Price(SelectModel model, User thisUser, AnswerAppDataContext db) { return new PriceBreakdown(model, thisUser, db); }
//Determines whether a user has access to a given grouping of solutions public Boolean UserHasAccess(User theUser, SelectModel model, AnswerAppDataContext db) { String FileName = model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf"; return UserHasAccess(theUser, FileName, db); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { if(model.UserName.Contains("_")) { ModelState.AddModelError("", "Your user name cannot contain underscores"); return View(model); } if ((!model.Email.Contains("@")) || (!model.Email.Split(new char[1] { '@' })[1].Contains(".")) || (model.Email.Split(new char[1] { '@' })[1].Contains("@")) || (model.Email.Split(new char[1] { '@' })[1].Length < 1) || (model.Email.Split(new char[1] { '@' })[0].Length < 1)) { ModelState.AddModelError("", "You have entered an invalid e-mail address");//"Your e-mail address must contain only one '@' symbol and at least one '.' symbol afterwards."); return View(model); } //Add the new user to the Answer Database AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); IQueryable<AnswerApp.Models.User> retrieved = from theUsers in db.Users where theUsers.UserName.Equals(model.UserName) select theUsers; User[] Users_in_Answer_Database_by_theUser_Name = retrieved.ToArray<User>(); //If the user does not already exist AnswerApp.Models.User theNewUser = new AnswerApp.Models.User(); if (Users_in_Answer_Database_by_theUser_Name.Length < 1) { theNewUser.UserName = model.UserName; theNewUser.Password = model.Password; theNewUser.Email = model.Email; theNewUser.PasswordQuestion = model.PasswordQuestion; theNewUser.PasswordAnswer = model.PasswordAnswer; theNewUser.MetaData = theNewUser.UserName.GetHashCode().ToString();//theNewUser.UserName;//.GetHashCode().ToString(); db.Users.InsertOnSubmit(theNewUser); db.SubmitChanges();//*/--D.A.P. MailAddress fromAddress = new MailAddress("*****@*****.**"); MailAddress toAddress = new MailAddress(theNewUser.Email); SendEmail(fromAddress, toAddress, "Solvation - E-mail Registration Confirmation", "Hello " + theNewUser.UserName + ". Before you can complete registration with Solvation.ca we must first confirm that this is a valid e-mail addres. To confirm that this is a valid e-mail address you will need to proceed to the following address using your web browser. http://Solvation.ca/Account/ConfirmRegistration/?SecretCode=" /*+ theNewUser.UserName + "_"*/ + theNewUser.UserName.GetHashCode().ToString()); return RedirectToAction("LogIn", "Account"); } // Attempt to register the user /*MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { FormsAuthentication.SetAuthCookie(model.UserName, false );// createPersistentCookie MailAddress fromAddress = new MailAddress("*****@*****.**"); MailAddress toAddress = new MailAddress(theNewUser.Email); SendEmail(fromAddress, toAddress, "Salutations!", "Hello " + theNewUser.UserName + " and welcome to Solvation.ca"); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); }//*/ } // If we got this far, something failed, redisplay form return View(model); }
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 ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { //Add the new user to the Answer Database AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); AnswerApp.Models.User theNewUser = new AnswerApp.Models.User(); theNewUser.UserName = model.UserName; theNewUser.Password = model.Password; theNewUser.Email = model.Email; db.Users.InsertOnSubmit(theNewUser); db.SubmitChanges();//*/--D.A.P. // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return View(model); }
public ActionResult ViewAnswer(string argument, SelectModel model) { ViewData["RenderAnswer"] = "false";//don't render practice answer before the user has answered it ViewData["FileNameExtensionless"] = "" + model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question; ViewData["FileName"] = "" + ViewData["FileNameExtensionless"] + ".pdf"; ViewData["PracticeProblemFileName"] = "" + ViewData["FileNameExtensionless"] + "_Practice Problem.png"; AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); AnswerApp.Models.User theUser = new AnswerApp.Models.User(); theUser = db.Users.Single(u => u.UserName.Equals(User.Identity.Name)); if (theUser != null) { if (theUser.Answers != null) { string[] UserAnswers = new string[100]; UserAnswers = theUser.Answers.Split(new char[2] { ',', ';' }); for (int i = 0; i < UserAnswers.Length; i++) { if (UserAnswers[i].Equals(ViewData["FileName"])) { return View("ViewAnswer", model); } } } } return RedirectToAction("Pay", "Answers", model); }
public ActionResult ViewAnswer(string argument, SelectModel model) { ViewData["SelectionList"] = "Error: No list"; ViewData["RenderAnswer"] = "false";//don't render practice answer before the user has answered it String FilenameExtensionless = "" + model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question; ViewData["FileNameExtensionless"] = FilenameExtensionless; String FileName = "" + FilenameExtensionless + ".pdf"; ViewData["FileName"] = FileName; ViewData["PracticeProblemFileName"] = "" + ViewData["FileNameExtensionless"] + "_Practice Problem.png"; AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); AnswerApp.Models.User theUser = new AnswerApp.Models.User(); theUser = db.Users.Single(u => u.UserName.Equals(User.Identity.Name)); if (theUser != null) { if (theUser.Answers != null) { if (UserHasAccess(User.Identity.Name, FileName)) { if (model.Unit.Equals("All") || model.Chapter.Equals("All") || model.Section.Equals("All") || model.Page.Equals("All") || model.Question.Equals("All")) { RedirectToAction("Index", "Home"); } ViewData["SelectionList"] = GenerateSelectionList(model); return View("ViewAnswer", model); } } return RedirectToAction("Pay", "Answers", model); } return RedirectToAction("Logon", "Account"); }
public ActionResult ViewAnswer(string argument, SelectModel model, string returnUrl) { ViewData["PracticeProblemAnswer"] = model.PracticeProblemAnswer; ViewData["RenderAnswer"] = "true"; if (User.Identity.Name.Equals(argument)) { ViewData["FileName"] = "" + model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf"; ViewData["FileNameExtensionless"] = "" + model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question; ViewData["PracticeProblemFileName"] = "" + model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + "_Practice Problem.png"; AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); AnswerApp.Models.User theUser = new AnswerApp.Models.User(); theUser = db.Users.Single(u => u.UserName.Equals(User.Identity.Name)); if (theUser != null) { if (theUser.Answers != null) { string[] UserAnswers = new string[100]; UserAnswers = theUser.Answers.Split(new char[2] { ',', ';' }); ViewData["AnswerString"] = theUser.Answers; ViewData["UserName"] = theUser.UserName; ViewData["UserIdentity"] = User.Identity.Name; for (int i = 0; i < UserAnswers.Length; i++) { if (UserAnswers[i].Equals(ViewData["FileName"])) { ////String PracticeProblemAnswer = db.ExecuteQuery("SELECT Practice_Problem_Answer FROM Question WHERE Textbook_Title = {0}", model.Textbook); model.CorrectAnswer = "Error 1";//<br />" + model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question; IQueryable<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) && theAnswers.Question_Number.Equals(model.Question) select theAnswers; Question[] results = retrieved.ToArray<Question>(); if (results.Length != 0) { model.CorrectAnswer = results.First().Practice_Problem_Answer; } db.SubmitChanges(); return View("ViewAnswer", model); } } } } return RedirectToAction("Pay", "Answers", model);//pay here!!!! } else//This user just purchased the answer { AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); AnswerApp.Models.User thisUser = db.Users.Single(d => d.UserName.Equals(User.Identity.Name)); if (thisUser == null) { RedirectToAction("LogOn", "Account"); }//This should never happen //If the user has previous answers then check them to see if this is one of them if (thisUser.Answers != null) { string[] UserAnswers = new string[100]; UserAnswers = thisUser.Answers.Split(new char[2] { ',', ';' }); ViewData["UserAnswers"] = UserAnswers[0]; ViewData["AnswerString"] = thisUser.Answers; ViewData["UserName"] = thisUser.UserName; ViewData["UserIdentity"] = User.Identity.Name; //Check to see if the user already has that answer (This will only be necesary for when a user uses the back button to reach the purchase page again. for (int index = 0; index < UserAnswers.Length; index++) { if (UserAnswers[index].Equals(ViewData["FileName"])) { model.CorrectAnswer = "Error 2"; IQueryable<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) && theAnswers.Question_Number.Equals(model.Question) select theAnswers; Question[] results = retrieved.ToArray<Question>(); if (results.Length != 0) { model.CorrectAnswer = results.First().Practice_Problem_Answer; } db.SubmitChanges(); return View("ViewAnswer", model/*, r*/);//If the user already has the answer then show it. } } } //Once it is certain that the user doesn't have this answer then it will be added to their list of answers. ViewData["FileName"] = model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf"; ViewData["FileNameExtensionless"] = model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question; ViewData["PracticeProblemFileName"] = model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + "_Practice Problem.png"; thisUser.Answers += ViewData["FileName"] + ",0%;"; model.CorrectAnswer = "Error 3"; IQueryable<Question> retrieved2 = 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) && theAnswers.Question_Number.Equals(model.Question) select theAnswers; Question[] results2 = retrieved2.ToArray<Question>(); if (results2.Length != 0) { model.CorrectAnswer = results2.First().Practice_Problem_Answer; } db.SubmitChanges(); return View("ViewAnswer", model/*, r*/); } }
public ActionResult ViewAnswer(string argument, SelectModel model) { ViewData["RenderAnswer"] = "false"; if (User.Identity.Name.Equals(argument)) { ViewData["FileName"] = "" + model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf"; ViewData["FileNameExtensionless"] = "" + model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question; ViewData["PracticeProblemFileName"] = "" + model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + "_Practice Problem.png"; AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); AnswerApp.Models.User theUser = new AnswerApp.Models.User(); theUser = db.Users.Single(u => u.UserName.Equals(User.Identity.Name)); if (theUser != null) { if (theUser.Answers != null) { string[] UserAnswers = new string[100]; UserAnswers = theUser.Answers.Split(new char[2] { ',', ';' }); ViewData["AnswerString"] = theUser.Answers; ViewData["UserName"] = theUser.UserName; ViewData["UserIdentity"] = User.Identity.Name; for (int i = 0; i < UserAnswers.Length; i++) { if (UserAnswers[i].Equals(ViewData["FileName"])) { return View("ViewAnswer", model/*, r*/); } } } } return RedirectToAction("Pay", "Answers", model);//pay here!!!! } else { AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); AnswerApp.Models.User thisUser = db.Users.Single(d => d.UserName.Equals(User.Identity.Name)); if (thisUser == null) { RedirectToAction("LogOn", "Account"); }//This should never happen //If the user has previous answers then check them to see if this is one of them if (thisUser.Answers != null) { string[] UserAnswers = new string[100]; UserAnswers = thisUser.Answers.Split(new char[2] { ',', ';' }); ViewData["UserAnswers"] = UserAnswers[0]; ViewData["AnswerString"] = thisUser.Answers; ViewData["UserName"] = thisUser.UserName; ViewData["UserIdentity"] = User.Identity.Name; //Check to see if the user already has that answer (THis will only be necesary for when a user uses the back button to reach the purchase page again. for (int index = 0; index < UserAnswers.Length; index++) { if (UserAnswers[index].Equals(ViewData["FileName"])) { return View("ViewAnswer", model/*, r*/);//If the user already has the answer then show it. } } } //Once it is certain that the user doesn't have this answer then it will be added to their list of answers. ViewData["FileName"] = "" + model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf"; ViewData["FileNameExtensionless"] = "" + model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question; ViewData["PracticeProblemFileName"] = "" + model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + "_Practice Problem.png"; thisUser.Answers += ViewData["FileName"] + ",0%;"; db.SubmitChanges(); return View("ViewAnswer", model/*, r*/); } }