public ActionResult ChangePassword(ChangePasswordModel model) { if (ModelState.IsValid) { // ChangePassword will throw an exception rather // than return false in certain failure scenarios. bool changePasswordSucceeded; try { MembershipUser currentUser = Membership.GetUser(User.Identity.Name, true /* userIsOnline */); changePasswordSucceeded = currentUser.ChangePassword(model.OldPassword, model.NewPassword); } catch (Exception) { changePasswordSucceeded = false; } if (changePasswordSucceeded) { AnswerAppDataContext db = new AnswerAppDataContext(); User theUser = db.Users.Single(u => u.UserName.Equals(User.Identity.Name)); theUser.Password = model.NewPassword; db.SubmitChanges(); return RedirectToAction("ChangePasswordSuccess"); } else { ModelState.AddModelError("", "The current password is incorrect or the new password is invalid."); } } // If we got this far, something failed, redisplay form return View(model); }
public ActionResult Account(HomeModel model) { if (Request.IsAuthenticated) { ViewBag.Message = "The Answer App"; ViewBag.Username = User.Identity.Name; AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); AnswerApp.Models.User thisUser = db.Users.Single(d => d.UserName.Equals(User.Identity.Name)); //thisUser.MetaData = ""; db.SubmitChanges(); if (thisUser == null) { return RedirectToAction("LogIn", "Account"); }//This should never happen AnswerApp.Models.SelectModel fakeModel = new AnswerApp.Models.SelectModel(); fakeModel.Textbook = "All"; fakeModel.Unit = "All"; fakeModel.Chapter = "All"; fakeModel.Section = "All"; fakeModel.Page = "All"; fakeModel.Question = "All"; ViewData["SelectionList"] = GenerateSelectionList(fakeModel, 1); //TESTING AND OR DEBUGGING PURPOSES ONLY if (User.Identity.Name.Equals("administrator")) { //AnswerAppDataContext db = new AnswerAppDataContext(); List<User> UserList = new List<User>(); UserList = db.Users.ToList<User>(); foreach (User theUser in UserList) { ViewData["UserList"] += "[" + theUser.Unique_Id + "," + theUser.UserName + "," + theUser.Email + "," + theUser.Password + "," + theUser.PasswordQuestion + "," + theUser.PasswordAnswer + "," + theUser.Answers + "," + theUser.MetaData + "]"; } } //TESTING AND OR DEBUGGING PURPOSES ONLY*/ ViewData["Test"] = Collapsable("Test1", "Testtext"); ViewData["Test"] += Collapsable("Test2", "Testtext"); ViewData["Test"] += Collapsable("Test3", Collapsable("Test4", "Testtext")); ViewData["AllContent"] = AllContent; ViewData["AllHeader"] = AllHeader; ViewData["Credit"] = thisUser.Credit; return View(model); } else { return RedirectToAction("LogIn", "Account"); //return View(); } }
public ActionResult Pay(SelectModel model) { 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 //thisUser.Answers += "," + model.FileName; db.SubmitChanges(); return View(model);//RedirectToAction("ViewAnswer/" + User.Identity.Name, "Answers"); }
public ActionResult Pay(SelectModel model, string returnUrl) { 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 //thisUser.Answers += "," + model.FileName; List<Question> All_PracticeProblems = db.Questions.ToList(); foreach (Question thisPracticeProblem in All_PracticeProblems) { if ((thisPracticeProblem.Textbook_Title == model.Textbook) && (thisPracticeProblem.Unit_Title == model.Unit) && (thisPracticeProblem.Chapter_Title == model.Chapter) && (thisPracticeProblem.Section_Title == model.Section) && (thisPracticeProblem.Page_Number == model.Page) && (thisPracticeProblem.Question_Number == model.Question)) { model.CorrectAnswer = thisPracticeProblem.Practice_Problem_Answer; } } db.SubmitChanges(); return RedirectToAction("ViewAnswer/purchase", "Answers", model); }
//INCOMPLETE public ActionResult Upload(UploadModel model, string returnUrl) { List<ViewDataUploadFilesResult> r = new List<ViewDataUploadFilesResult>(); HttpPostedFileBase hpf = null;// = Request.Files[file] as HttpPostedFileBase; String FileName = null; foreach (string file in Request.Files) { hpf = Request.Files[file] as HttpPostedFileBase; if (hpf.ContentLength == 0) continue; string savedFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "images\\" + Path.GetFileName(hpf.FileName)); hpf.SaveAs(savedFileName);//Replace this with database insertion FileName = hpf.FileName; r.Add(new ViewDataUploadFilesResult() { Name = savedFileName, Length = hpf.ContentLength }); } AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); AnswerApp.Models.Question theQuestion = db.Questions.Single<Question>(d => d.Question_Id == 2);// new AnswerApp.Models.Question(); if (hpf != null) { //Disect the file name for it's file properties String[] properties = new String[7]; properties = FileName.Split(new char[1] { '_' }); //String Textbook_Title = properties[0]; //String Unit_Title = properties[2]; //String Chapter_Title = properties[2]; //String Section_Title = properties[3]; //String Page_Number = properties[4]; //String Question_Number = properties[5]; String Practice_Problem = properties[6].Split(new char[1] { '.' })[0]; if (Practice_Problem.Equals("Practice Problem")) { theQuestion.Practice_Problem = new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length); } else { theQuestion.Answer = new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length); } } db.SubmitChanges(); Question retrieved = db.Questions.Single(d => d.Question_Id == theQuestion.Question_Id); ViewBag.RetrievedAnswer = retrieved.ToString(); ViewBag.RetrievedAnswer = retrieved.Question_Id; return View("Upload", r); }
public ActionResult Pay(SelectModel model, string returnUrl) { 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"); } String filename = "" + model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf"; thisUser.Answers += filename + ";"; 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 RedirectToAction("ViewAnswer/purchase", "Answers", model); }
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; }
public ActionResult Pay(SelectModel model) { 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("LogIn", "Account"); } String filename = "" + model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf"; 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(); PriceBreakdown thePriceBreakdown = new PriceBreakdown(model, thisUser, db); ViewData["UpgradeLevel"] = thePriceBreakdown.UpgradeLevel; ViewData["CurrentLevel"] = thePriceBreakdown.CurrentLevel; ViewData["Credit"] = thePriceBreakdown.Credit; ViewData["NumberOfSolutionsToPurchase"] = thePriceBreakdown.NumberOfSolutionsToPurchase; ViewData["TotalValue"] = (thePriceBreakdown.NumberOfSolutionsToPurchase * PriceOfSingleSolution).ToString("C"); ViewData["NumberOfSolutionsForThisUser"] = thePriceBreakdown.NumberOfSolutionsForThisUser; ViewData["NumberSelectedUserAlreadyHas"] = thePriceBreakdown.NumberSelectedUserAlreadyHas; ViewData["SolutionsRemainingToBePurchased"] = thePriceBreakdown.SolutionsRemainingToBePurchased; ViewData["RemainingCost"] = thePriceBreakdown.RemainingCost.ToString("C"); ViewData["UserCredit"] = thisUser.Credit; ViewData["TotalRemainingSolutions"] = thePriceBreakdown.TotalRemainingSolutions; ViewData["TotalRemainingCost"] = thePriceBreakdown.TotalRemainingPrice.ToString("C"); ViewData["UserLevel"] = thePriceBreakdown.UserLevel; ViewData["UserLevelAfterPurchase"] = thePriceBreakdown.UserLevelAfterPurchase; ViewData["UpgradePrice"] = thePriceBreakdown.UpgradePrice.ToString("C"); ViewData["AdditionalCredits"] = thePriceBreakdown.AdditionalCredits; ViewData["ShowUpgradeSavings"] = thePriceBreakdown.ShowUpgradeSavings; ViewData["UpgradeSavings"] = thePriceBreakdown.UpgradeSavings.ToString("C"); ViewData["DisplayIndividualPurchasePrice"] = thePriceBreakdown.DisplayIndividualPurchasePrice;//*/ return View(model); }
public bool AddSolutionByCredit(AnswerApp.Models.User theUser, AnswerAppDataContext db, SelectModel model) { if (model.Question.Equals("All")) { if (model.Page.Equals("All")) { if (model.Section.Equals("All")) { if (model.Chapter.Equals("All")) { if (model.Unit.Equals("All")) { if (model.Textbook.Equals("All")) { IQueryable<Question> retrieved = from theAnswers in db.Questions select theAnswers; Question[] results = retrieved.ToArray<Question>(); int ResultsUserAlreadyHas = 0; foreach (Question theQuestion in results) { SelectModel theModel = new SelectModel(theQuestion); if (UserHasAccess(theUser.UserName, theModel.ToString())) { ResultsUserAlreadyHas += NumberOfQuestions(theModel, db); } } int SolutionsToAdd = results.Length - ResultsUserAlreadyHas; if (SolutionsToAdd <= theUser.Credit) { theUser.Credit -= SolutionsToAdd; AddSolution(theUser, model, db); db.SubmitChanges(); } else { return false; } } else { IQueryable<Question> retrieved = from theAnswers in db.Questions where theAnswers.Textbook_Title.Equals(model.Textbook) select theAnswers; Question[] results = retrieved.ToArray<Question>(); int ResultsUserAlreadyHas = 0; foreach (Question theQuestion in results) { SelectModel theModel = new SelectModel(theQuestion); if (UserHasAccess(theUser.UserName, theModel.ToString())) { ResultsUserAlreadyHas += NumberOfQuestions(theModel, db); } } int SolutionsToAdd = results.Length - ResultsUserAlreadyHas; if (SolutionsToAdd <= theUser.Credit) { theUser.Credit -= SolutionsToAdd; AddSolution(theUser, model, db); db.SubmitChanges(); } else { return false; } } } else { IQueryable<Question> retrieved = from theAnswers in db.Questions where theAnswers.Textbook_Title.Equals(model.Textbook) && theAnswers.Unit_Title.Equals(model.Unit) select theAnswers; Question[] results = retrieved.ToArray<Question>(); int ResultsUserAlreadyHas = 0; foreach (Question theQuestion in results) { SelectModel theModel = new SelectModel(theQuestion); if (UserHasAccess(theUser.UserName, theModel.ToString())) { ResultsUserAlreadyHas += NumberOfQuestions(theModel, db); } } int SolutionsToAdd = results.Length - ResultsUserAlreadyHas; if (SolutionsToAdd <= theUser.Credit) { theUser.Credit -= SolutionsToAdd; AddSolution(theUser, model, db); db.SubmitChanges(); } else { return false; } } } else { 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) select theAnswers; Question[] results = retrieved.ToArray<Question>(); int ResultsUserAlreadyHas = 0; foreach (Question theQuestion in results) { SelectModel theModel = new SelectModel(theQuestion); if (UserHasAccess(theUser.UserName, theModel.ToString())) { ResultsUserAlreadyHas += NumberOfQuestions(theModel, db); } } int SolutionsToAdd = results.Length - ResultsUserAlreadyHas; if (SolutionsToAdd <= theUser.Credit) { theUser.Credit -= SolutionsToAdd; AddSolution(theUser, model, db); db.SubmitChanges(); } else { return false; } } } else { 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) select theAnswers; Question[] results = retrieved.ToArray<Question>(); int ResultsUserAlreadyHas = 0; foreach (Question theQuestion in results) { SelectModel theModel = new SelectModel(theQuestion); if (UserHasAccess(theUser.UserName, theModel.ToString())) { ResultsUserAlreadyHas += NumberOfQuestions(theModel, db); } } int SolutionsToAdd = results.Length - ResultsUserAlreadyHas; if (SolutionsToAdd <= theUser.Credit) { theUser.Credit -= SolutionsToAdd; AddSolution(theUser, model, db); db.SubmitChanges(); } else { return false; } } } else { 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) select theAnswers; Question[] results = retrieved.ToArray<Question>(); int ResultsUserAlreadyHas = 0; foreach (Question theQuestion in results) { SelectModel theModel = new SelectModel(theQuestion); if (UserHasAccess(theUser.UserName, theModel.ToString())) { ResultsUserAlreadyHas += NumberOfQuestions(theModel, db); } } int SolutionsToAdd = results.Length - ResultsUserAlreadyHas; if (SolutionsToAdd <= theUser.Credit) { theUser.Credit -= SolutionsToAdd; AddSolution(theUser, model, db); db.SubmitChanges(); } else { return false; } } } else { 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>(); int ResultsUserAlreadyHas = 0; foreach (Question theQuestion in results) { SelectModel theModel = new SelectModel(theQuestion); if (UserHasAccess(theUser.UserName, theModel.ToString())) { ResultsUserAlreadyHas += NumberOfQuestions(theModel, db); } } int SolutionsToAdd = results.Length - ResultsUserAlreadyHas; if (SolutionsToAdd <= theUser.Credit) { theUser.Credit -= SolutionsToAdd; AddSolution(theUser, model, db); db.SubmitChanges(); } else { return false; } } return true; }
public CascadingDropDownNameValue[] SetQuestions(string knownCategoryValues, string category) { AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); AnswerApp.Models.User thisUser = db.Users.Single(d => d.UserName.Equals(User.Identity.Name)); StringDictionary incomingKnownCatagories = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); if (!incomingKnownCatagories.ContainsKey("question")) { return null; } thisUser.MetaData = knownCategoryValues;// +"ready"; List<CascadingDropDownNameValue> theList = new List<CascadingDropDownNameValue>(); theList.Add(new CascadingDropDownNameValue(thisUser.UserName, thisUser.UserName)); db.SubmitChanges(); return theList.ToArray(); }
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 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) "; //db.SubmitChanges(); //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 strparam = param.ToString(); //String splitstrparam = strparam.Split(new char[1] { '&' })[1]; string strRequest = Encoding.ASCII.GetString(param); strRequest += "&cmd=_notify-validate"; req.ContentLength = strRequest.Length; //for proxy //WebProxy proxy = new WebProxy(new Uri("http://url:port#")); //req.Proxy = proxy; //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] { '&' }); //List<String> ParameterList = parameters.ToList<String>(); String theParameterProxy = "error 03148"; String[] KeyValue = new String[2]; String Key = "", Value = ""; foreach (String theParameter in parameters) { KeyValue = theParameter.Split(new char[1] { '=' }); Key = KeyValue[0]; Value = KeyValue[1]; if (Key.Equals("transaction_subject")) { administrator.MetaData += " argument: " + Value;//YOU ARE HERE!!! //theParameterProxy = Value.Replace('+', ' '); db.SubmitChanges(); String Properties = Value.Replace('+', ' '); String UserName = Properties.Split(new char[1] { '_' })[0]; String FileName = Properties.Replace(UserName + "_", ""); AnswerApp.Models.User theUser = db.Users.Single<User>(u => u.UserName.Equals(UserName)); theUser.Answers += FileName + ".pdf;"; theParameterProxy = UserName + "hello" + FileName + ".pdf;"; } } //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 += " 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 //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 += " request: " + strRequest + " response: " + strResponse + " else if: " + argument; db.SubmitChanges(); } else { //log response/ipn data for manual investigation //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 += " request: " + strRequest + " response: " + strResponse + " else: " + argument; db.SubmitChanges(); } //administrator.MetaData += "request: " + strRequest + " response: " + strResponse + " argument: " + argument; //db.SubmitChanges(); return strResponse; }
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*/); } }
//INCOMPLETE public ActionResult Upload(UploadModel model, string returnUrl) { List<ViewDataUploadFilesResult> r = new List<ViewDataUploadFilesResult>(); HttpPostedFileBase hpf = null;// = Request.Files[file] as HttpPostedFileBase; foreach (string file in Request.Files) { hpf = Request.Files[file] as HttpPostedFileBase; if (hpf.ContentLength == 0) continue; string savedFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "images\\" + Path.GetFileName(hpf.FileName)); hpf.SaveAs(savedFileName);//Replace this with database insertion r.Add(new ViewDataUploadFilesResult() { Name = savedFileName, Length = hpf.ContentLength }); } ViewData["FileName"] = "This is a file name."; AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); AnswerApp.Models.Question theQuestion = new AnswerApp.Models.Question(); //db.Questions.Single(d => d.Question_Number.Equals("8"));// if (hpf != null) { theQuestion.Answer = new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length); //db.Questions.InsertOnSubmit(theQuestion); } db.SubmitChanges(); Question retrieved = db.Questions.Single(d => d.Question_Id == theQuestion.Question_Id); ViewBag.RetrievedAnswer = retrieved.ToString(); ViewBag.RetrievedAnswer = retrieved.Question_Id; return View("Upload", r); }
public CascadingDropDownNameValue[] SetQuestions(string knownCategoryValues, string category) { AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); StringDictionary knownCatagories = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); DictionaryEntry[] CatagoryArray = new DictionaryEntry[knownCatagories.Count]; knownCatagories.CopyTo(CatagoryArray, 0); String SelectedQuestion = "Error: No Question Selected"; foreach (DictionaryEntry theEntry in CatagoryArray) { if (theEntry.Key.ToString().Equals("question")) { SelectedQuestion = theEntry.Value.ToString(); } } AnswerApp.Models.User thisUser = db.Users.Single(d => d.UserName.Equals(User.Identity.Name)); thisUser.MetaData = knownCategoryValues; db.SubmitChanges(); List<CascadingDropDownNameValue> theList = new List<CascadingDropDownNameValue>(); theList.Add(new CascadingDropDownNameValue(thisUser.UserName, thisUser.UserName)); //return RedirectToAction("Answers", "ViewAnswer"); return theList.ToArray(); }
public ActionResult TestPurchase(string argument) { if (!Request.IsAuthenticated) { return RedirectToAction("LogIn", "Account"); } AnswerAppDataContext db = new AnswerAppDataContext(); User thisUser = db.Users.Single<User>(u => u.UserName.Equals(User.Identity.Name)); String[] properties = argument.Split(new char[1] { '_' }); if (properties.Length == 1) { thisUser.Credit += Convert.ToInt32(properties[0]); } else if (properties.Length == 6) { SelectModel thisSelection = new SelectModel(argument); AddSolution(thisUser, thisSelection, db); //thisUser.Answers += argument + ";"; } else if (properties.Length == 7) { SelectModel thisSelection = new SelectModel(argument); AddSolution(thisUser, thisSelection, db); thisUser.Credit += Convert.ToInt32(properties[6]); } else { //nothing } db.SubmitChanges(); return RedirectToAction("Index", "Home"); }
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); }
//This method adds entry information //and also file contents to the database //whenever new Images are added Boolean AddImageFromZip(byte[] data, String FileName) { AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); //Disect the file name for it's file properties String ExtensionlessFileName = FileName.Replace(".jpg", ""); ExtensionlessFileName = ExtensionlessFileName.Replace(".gif", ""); String[] properties = ExtensionlessFileName.Split(new char[2] { '_', '/' }); String Textbook_Title = null; String Unit_Title = null; String Chapter_Title = null; //String Section_Title = null; if (properties.Length > 0) { Textbook_Title = properties[0]; } if (properties.Length > 1) { Unit_Title = properties[1]; } if (properties.Length > 2) { Chapter_Title = properties[2]; } //if (properties.Length > 3) { Section_Title = properties[2]; } Boolean Textbook_Image = false; Boolean Unit_Image = false; Boolean Chapter_Image = false; //Boolean Section_Image = false; if (properties.Length == 1) { Textbook_Image = true; } if (properties.Length == 2) { Unit_Image = true; } if (properties.Length == 3) { Chapter_Image = true; } //if (properties.Length == 4) { SectionImage = true; } if (Textbook_Title != null) { //ViewData["Info"] += "(in3)"; //Search the database for this Textbook IQueryable<Textbook> RetrievedTextbooks = from theTextbooks in db.Textbooks where theTextbooks.Title.Equals(Textbook_Title) select theTextbooks; Textbook[] TextbookResults = RetrievedTextbooks.ToArray<Textbook>(); if (TextbookResults.Length == 0)//The Textbook does not yet exists { //Create a new Textbook AnswerApp.Models.Textbook theTextbook = new AnswerApp.Models.Textbook(); //Populate the Textbook with the properties extracted from the file name theTextbook.Title = Textbook_Title; if (theTextbook.Title.Length < 1) { return false; } if (Textbook_Image) { theTextbook.Image = data;// new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length); } db.Textbooks.InsertOnSubmit(theTextbook); } else if (Textbook_Image) { //Gather a handle to the existing textbook AnswerApp.Models.Textbook theTextbook = TextbookResults.First(); //Populate the existing Textbook with the properties extracted from the file name theTextbook.Title = Textbook_Title; theTextbook.Image = data;// new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length); } db.SubmitChanges(); } if (Unit_Title != null) { //Search teh database for this Unit IQueryable<Unit> RetrievedUnits = from theUnits in db.Units where theUnits.Textbook_Title.Equals(Textbook_Title) && theUnits.Unit_Title.Equals(Unit_Title) select theUnits; Unit[] UnitResults = RetrievedUnits.ToArray<Unit>(); if (UnitResults.Length == 0)//The Unit does not yet exists { //Create a new Unit AnswerApp.Models.Unit theUnit = new AnswerApp.Models.Unit(); //Populate the Unit with the properties extracted from the file name theUnit.Textbook_Title = Textbook_Title; theUnit.Unit_Title = Unit_Title; //Populate the relational Id's based on previous hierarchical entries theUnit.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id; if (theUnit.Unit_Title.Length < 1) { return false;// "Error: You have attempted to add a gUnit without a Unit Title. skipping..."; } if (Unit_Image) { theUnit.Image = data;// new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length); } db.Units.InsertOnSubmit(theUnit); } else if (Unit_Image) { //Gather a handle to the existing Unit AnswerApp.Models.Unit theUnit = UnitResults.First(); //Populate the existing Unit with the properties extracted from the file name theUnit.Unit_Title = Unit_Title; theUnit.Image = data;// new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length); } db.SubmitChanges(); } if (Chapter_Title != null) { //Search the database for this Chapter IQueryable<Chapter> RetrievedChapters = from theChapters in db.Chapters where theChapters.Textbook_Title.Equals(Textbook_Title) && theChapters.Unit_Title.Equals(Unit_Title) && theChapters.Chapter_Title.Equals(Chapter_Title) select theChapters; Chapter[] ChapterResults = RetrievedChapters.ToArray<Chapter>(); if (ChapterResults.Length == 0)//The Chapter does not yet exists { //Create a new Chapter AnswerApp.Models.Chapter theChapter = new AnswerApp.Models.Chapter(); //Populate the Chapter with the properties extracted from the file name theChapter.Textbook_Title = Textbook_Title; theChapter.Unit_Title = Unit_Title; theChapter.Chapter_Title = Chapter_Title; //Populate the relational Id's based on previous hierarchical entries theChapter.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id; theChapter.Unit_Id = db.Units.Single(d => d.Unit_Title.Equals(Unit_Title)).Unit_Id; if(theChapter.Chapter_Title.Equals("MACOSX")) { return false;//"Error: You have attempted to add a chapter titled MACOSX... ... ... gAwD! O.o ...skipping..."; } if (Chapter_Image) { theChapter.Image = data;// new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length); } db.Chapters.InsertOnSubmit(theChapter); } else if (Chapter_Image) { //Gather a handle to the existing Chapter AnswerApp.Models.Chapter theChapter = ChapterResults.First(); //Populate the existing CHapter with the properties extracted from the file name theChapter.Chapter_Title = Chapter_Title; theChapter.Image = data;// new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length); } db.SubmitChanges(); } /* if(Section_Title != null) { //Search the database for this Section IQueryable<Section> RetrievedSections = from theSections in db.Sections where theSections.Textbook_Title.Equals(Textbook_Title) && theSections.Unit_Title.Equals(Unit_Title) && theSections.Chapter_Title.Equals(Chapter_Title) && theSections.Section_Title.Equals(Section_Title) select theSections; Section[] SectionResults = RetrievedSections.ToArray<Section>(); if (SectionResults.Length == 0)//The Section does not yet exists { //Create a new Section AnswerApp.Models.Section theSection = new AnswerApp.Models.Section(); //Populate the Section with the properties extracted from the file name theSection.Textbook_Title = Textbook_Title; theSection.Unit_Title = Unit_Title; theSection.Chapter_Title = Chapter_Title; theSection.Section_Title = Section_Title; //Populate the relational Id's based on previous hierarchical entries theSection.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id; theSection.Unit_Id = db.Units.Single(d => d.Unit_Title.Equals(Unit_Title)).Unit_Id; theSection.Chapter_Id = db.Chapters.Single(d => d.Chapter_Title.Equals(Chapter_Title)).Chapter_Id; db.Sections.InsertOnSubmit(theSection); db.SubmitChanges(); } } */ db.SubmitChanges();//Commit the changes to the database. return true; }
public ActionResult Index(SelectModel model, String returnUrl) { //Extract the known catagory values from the user's meta data AnswerApp.Models.AnswerAppDataContext db = new AnswerAppDataContext(); AnswerApp.Models.User thisUser = db.Users.Single(d => d.UserName.Equals(User.Identity.Name)); String knownCategoryValues = thisUser.MetaData; thisUser.MetaData = ""; db.SubmitChanges(); ViewBag.Username = User.Identity.Name; //Use a fake selection model to generate the selection list for All the user's solutions AnswerApp.Models.SelectModel fakeModel = new AnswerApp.Models.SelectModel(); fakeModel.Textbook = "All"; fakeModel.Unit = "All"; fakeModel.Chapter = "All"; fakeModel.Section = "All"; fakeModel.Page = "All"; fakeModel.Question = "All"; ViewData["SelectionList"] = GenerateSelectionList(fakeModel, 1); ViewData["AllContent"] = AllContent; ViewData["AllHeader"] = AllHeader; ViewData["Credit"] = thisUser.Credit; //Convert to proper format knownCategoryValues = knownCategoryValues.Replace("Textbook:", ""); knownCategoryValues = knownCategoryValues.Replace("Unit:", ""); knownCategoryValues = knownCategoryValues.Replace("Chapter:", ""); knownCategoryValues = knownCategoryValues.Replace("Section:", ""); knownCategoryValues = knownCategoryValues.Replace("Page:", ""); knownCategoryValues = knownCategoryValues.Replace("Question:", ""); //Disect the file name for it's file properties String[] properties = knownCategoryValues.Split(new char[1] { ';' }); String Textbook_Title = null; String Unit_Title = null; String Chapter_Title = null; String Section_Title = null; String Page_Number = null; String Question_Number = null; if (properties.Length > 0) { Textbook_Title = properties[0]; } if (properties.Length > 1) { Unit_Title = properties[1]; } if (properties.Length > 2) { Chapter_Title = properties[2]; } if (properties.Length > 3) { Section_Title = properties[3]; } if (properties.Length > 4) { Page_Number = properties[4]; } if (properties.Length > 5) { Question_Number = properties[5]; }//.Split(new char[1] { '.' })[0];//Truncate ".pdf" from the end of the file name if ((Page_Number == null) || (Textbook_Title == null)) { ViewData["SelectionInfo"] = "You must specify a textbook."; return View(model); } //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) { ViewData["SelectionInfo"] = "There are multiple Questions with that number. Please make a more specific selection."; return View(model); } 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) { ViewData["SelectionInfo"] += "Error: The selected Question could not be found. Please contact the Solvation.ca developement team. " + knownCategoryValues; return View(model); } } 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 View(); } AnswerApp.Models.SelectModel theSelectModel = new SelectModel(); theSelectModel.Textbook = Textbook_Title; theSelectModel.Unit = Unit_Title; theSelectModel.Chapter = Chapter_Title; theSelectModel.Section = Section_Title; theSelectModel.Page = Page_Number; theSelectModel.Question = Question_Number; if(Textbook_Title.Equals("")) { return RedirectToAction("Index/" + knownCategoryValues + Textbook_Title, "Home"); } else { AnswerApp.Controllers.AnswersController theAnswerController = new AnswerApp.Controllers.AnswersController(); if (theAnswerController.NumberOfQuestions(theSelectModel, db) > 0) { return RedirectToAction("ViewAnswer/" + User.Identity.Name, "Answers", theSelectModel); } else { ViewData["SelectionInfo"] += "There were no solutions within your selection."; return View(model); } } }
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; }
//This method adds entry information //and also file contents to the database //whenever new Questions are added using //the bulk uploader String AddFromZip(byte[] data, String FileName) { AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); if (FileName == null) { return "Error: Archive file name is null."; } if (FileName.Equals("")) { return "Error: No file name."; } if (FileName.Length < 2) { return "Error: Archive file name too short."; } String _Info = ""; //Page.ClientScript.RegisterStartupScript(GetType(), "UserDialogScript", "alert(\"User successfully updated\");", true); //Disect the file name for it's file properties FileName = FileName.Replace(".pdf", "");//Remove file extension String[] ParsedFileName = FileName.Split(new char[1] { '/' });//separate file and path text String PathlessFileName = ParsedFileName.Last<String>();//The last string will be the file name if (PathlessFileName.Length < 1) { return "Error: The directory tree is empty. "; } String Path = FileName.Replace(PathlessFileName, "");//Everything but the file name is the path(test) String Textbook_Title = null; String Unit_Title = null; String Chapter_Title = null; String Section_Title = null; String Page_Number = null; String Question_Number = null; String Practice_Problem_Answer = null; String[] PathlessFileNameParsed = PathlessFileName.Split(new char[2] { '_', ' ' }); if (PathlessFileNameParsed.Length == 3)//This is a practice problem { _Info += "Practice Problem"; if (PathlessFileName.Contains("p") || PathlessFileName.Contains("q"))//If the file name contains p or q { Boolean Page = false, Question = false, Answer = false; foreach (String theElement in PathlessFileNameParsed) { if (theElement.Contains("p"))//this must be a page number { Page_Number = theElement.Replace("p", "").Replace("g", ""); Page = true; } else if (theElement.Contains("q"))//this must be a question number { Question_Number = theElement.Replace("q", ""); Question = true; } else { Practice_Problem_Answer = theElement; //_Info += "[" + Practice_Problem_Answer + "]"; Answer = true; } } if ((Page == false) || (Question == false) || (Answer == false)) { _Info += "Error: File naming convention not followed \"" + PathlessFileName + "\". The parser could not understand the file name of the practice problem because it is ambiguous. skipping..."; } } else//No symbols were added thus the order of the numbers in the file name determines their meaning { if (PathlessFileNameParsed.Length > 0) { Page_Number = PathlessFileNameParsed[0]; } if (PathlessFileNameParsed.Length > 1) { Question_Number = PathlessFileNameParsed[1]; } if (PathlessFileNameParsed.Length > 2) { Practice_Problem_Answer = PathlessFileNameParsed[2]; } } } else if (PathlessFileNameParsed.Length == 2)//This is a solution { _Info += "Solution "; if (PathlessFileName.Contains("p") || PathlessFileName.Contains("q"))//If the file name contains p or q { Boolean Page = false, Question = false; foreach (String theElement in PathlessFileNameParsed)//use the p and q to denote page and question { if (theElement.Contains("p"))//this must be a page number { Page_Number = theElement.Replace("p", "").Replace("g", ""); Page = true; } else if (theElement.Contains("q"))//this must be a question number { Question_Number = theElement.Replace("q", ""); Question = true; } else { _Info += "Error: File naming convention not followed \"" + PathlessFileName + "\". Missing one or more 'p' and or 'q' disambiguation parameters. skipping..."; } } if ((Page == false) || (Question == false)) { _Info += "Error: File naming convention not followed \"" + PathlessFileName + "\". The parser could not understand the file name of the solution because it is ambiguous. skipping..."; } } else//No symbols were added thus the order of the numbers in the file name determines their meaning { if (PathlessFileNameParsed.Length > 0) { Page_Number = PathlessFileNameParsed[0]; } if (PathlessFileNameParsed.Length > 1) { Question_Number = PathlessFileNameParsed[1]; } } } else//(PathlessFileNameParsed.Length < 2) || (PathlessFileNameParsed.Length > 3) { _Info += "Error: File naming convention not followed \"" + PathlessFileName + "\". " + PathlessFileNameParsed.Length + "is not the right number of elements. skipping..."; } String[] PathParsed = Path.Split(new char[2] { '_', '/' }); if (PathParsed.Length < 3) { return "Error uploading files: The path labeling convention had not been followed and as a result the path is ambiguous. The parser cannot complete this uploaduntil the path has been corrected. skipping..."; } //Section_Title = PathParsed[PathParsed.Length - 2]; //Chapter_Title = PathParsed[PathParsed.Length - 3]; //Unit_Title = PathParsed[PathParsed.Length - 4]; //Textbook_Title = PathParsed[PathParsed.Length - 5]; if(PathParsed.Length < 4){ return "Error: The path could not be understood because it was too short. skipping..."; } Textbook_Title = PathParsed[0]; Unit_Title = PathParsed[1]; Chapter_Title = PathParsed[2]; Section_Title = PathParsed[3]; _Info += Path + PathlessFileName + ".pdf ► " + Textbook_Title + " ► " + Unit_Title + " ► " + Chapter_Title + " ► " + Section_Title + " ► Page " + Page_Number + " ► Question " + Question_Number + " ► Practice Problem Answer " + Practice_Problem_Answer; //Search the database for this Textbook IQueryable<Textbook> RetrievedTextbooks = from theTextbooks in db.Textbooks where theTextbooks.Title.Equals(Textbook_Title) select theTextbooks; Textbook[] TextbookResults = RetrievedTextbooks.ToArray<Textbook>(); if (TextbookResults.Length == 0)//The Textbook does not yet exists { //Create a new Textbook AnswerApp.Models.Textbook theTextbook = new AnswerApp.Models.Textbook(); //Populate the Textbook with the properties extracted from the file name theTextbook.Title = Textbook_Title; if(theTextbook.Title.Length < 1) { return "Warning: You have attempted to add a textbook without a title. skipping... "; } db.Textbooks.InsertOnSubmit(theTextbook); db.SubmitChanges(); } //Search teh database for this Unit IQueryable<Unit> RetrievedUnits = from theUnits in db.Units where theUnits.Textbook_Title.Equals(Textbook_Title) && theUnits.Unit_Title.Equals(Unit_Title) select theUnits; Unit[] UnitResults = RetrievedUnits.ToArray<Unit>(); if (UnitResults.Length == 0)//The Unit does not yet exists { //Create a new Unit AnswerApp.Models.Unit theUnit = new AnswerApp.Models.Unit(); //Populate the Unit with the properties extracted from the file name theUnit.Textbook_Title = Textbook_Title; theUnit.Unit_Title = Unit_Title; //Populate the relational Id's based on previous hierarchical entries theUnit.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id; if (theUnit.Unit_Title.Length < 1) { return "Warning: You have attempted to add a gUnit without a Unit Title. skipping..."; } db.Units.InsertOnSubmit(theUnit); db.SubmitChanges(); } //Search the database for this Chapter IQueryable<Chapter> RetrievedChapters = from theChapters in db.Chapters where theChapters.Textbook_Title.Equals(Textbook_Title) && theChapters.Unit_Title.Equals(Unit_Title) && theChapters.Chapter_Title.Equals(Chapter_Title) select theChapters; Chapter[] ChapterResults = RetrievedChapters.ToArray<Chapter>(); if (ChapterResults.Length == 0)//The Chapter does not yet exists { //Create a new Chapter AnswerApp.Models.Chapter theChapter = new AnswerApp.Models.Chapter(); //Populate the Chapter with the properties extracted from the file name theChapter.Textbook_Title = Textbook_Title; theChapter.Unit_Title = Unit_Title; theChapter.Chapter_Title = Chapter_Title; //Populate the relational Id's based on previous hierarchical entries theChapter.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id; theChapter.Unit_Id = db.Units.Single(d => d.Unit_Title.Equals(Unit_Title)).Unit_Id;//YOU ARE HERE!!! (This needs tobe rewritten in case multiple textbooks ahve the same unit titles within them if (theChapter.Chapter_Title.Equals("MACOSX")) { return "Warning: You have attempted to add a chapter titled MACOSX... ... ... gAwD! O.o ...skipping..."; } db.Chapters.InsertOnSubmit(theChapter); db.SubmitChanges(); } //Search teh database for this Section IQueryable<Section> RetrievedSections = from theSections in db.Sections where theSections.Textbook_Title.Equals(Textbook_Title) && theSections.Unit_Title.Equals(Unit_Title) && theSections.Chapter_Title.Equals(Chapter_Title) && theSections.Section_Title.Equals(Section_Title) select theSections; Section[] SectionResults = RetrievedSections.ToArray<Section>(); if (SectionResults.Length == 0)//The Section does not yet exists { //Create a new Section AnswerApp.Models.Section theSection = new AnswerApp.Models.Section(); //Populate the Section with the properties extracted from the file name theSection.Textbook_Title = Textbook_Title; theSection.Unit_Title = Unit_Title; theSection.Chapter_Title = Chapter_Title; theSection.Section_Title = Section_Title; //Populate the relational Id's based on previous hierarchical entries theSection.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id; theSection.Unit_Id = db.Units.Single(d => d.Unit_Title.Equals(Unit_Title)).Unit_Id; theSection.Chapter_Id = db.Chapters.Single(d => d.Chapter_Title.Equals(Chapter_Title)).Chapter_Id; if (Section_Title.Length < 1) { return "Warning: You have attempted to add a section that does not have a title. skipping..."; } db.Sections.InsertOnSubmit(theSection); db.SubmitChanges(); } //Search teh database for this Page IQueryable<Page> RetrievedPages = from thePages in db.Pages where thePages.Textbook_Title.Equals(Textbook_Title) && thePages.Unit_Title.Equals(Unit_Title) && thePages.Chapter_Title.Equals(Chapter_Title) && thePages.Section_Title.Equals(Section_Title) && thePages.Page_Number.Equals(Page_Number) select thePages; Page[] PageResults = RetrievedPages.ToArray<Page>(); int Page_Id = -1; if (PageResults.Length == 0)//The Page does not yet exist { //Create a new Page AnswerApp.Models.Page thePage = new AnswerApp.Models.Page(); Page_Id = thePage.Page_Id; //Populate the Page with the properties extracted from the file name thePage.Textbook_Title = Textbook_Title; thePage.Unit_Title = Unit_Title; thePage.Chapter_Title = Chapter_Title; thePage.Section_Title = Section_Title; thePage.Page_Number = Page_Number; //Populate the relational Id's based on previous hierarchical entries thePage.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id; thePage.Unit_Id = db.Units.Single(d => d.Unit_Title.Equals(Unit_Title)).Unit_Id; thePage.Chapter_Id = db.Chapters.Single(d => d.Chapter_Title.Equals(Chapter_Title)).Chapter_Id; RetrievedSections = from theSections in db.Sections where theSections.Textbook_Title.Equals(Textbook_Title) && theSections.Unit_Title.Equals(Unit_Title) && theSections.Chapter_Title.Equals(Chapter_Title) && theSections.Section_Title.Equals(Section_Title) select theSections; thePage.Section_Id = RetrievedSections.First().Section_Id;// db.Sections.Single(d => d.Section_Title.Equals(Section_Title)).Section_Id; int test; if (!int.TryParse(thePage.Page_Number, out test)) { return "Error: You have attempted to add a page with a page number of '" + thePage.Page_Number + "'. The question number must be a number. You will have to correct this and try again. skipping... "; } db.Pages.InsertOnSubmit(thePage); db.SubmitChanges(); } //Search teh database for this Question IQueryable<Question> retrieved = from theAnswers in db.Questions where theAnswers.Textbook_Title.Equals(Textbook_Title) && theAnswers.Unit_Title.Equals(Unit_Title) && theAnswers.Chapter_Title.Equals(Chapter_Title) && theAnswers.Section_Title.Equals(Section_Title) && theAnswers.Page_Number.Equals(Page_Number) && theAnswers.Question_Number.Equals(Question_Number) select theAnswers; Question[] results = retrieved.ToArray<Question>(); if (results.Length != 0)//The Answer already exists { //Use the existing Question AnswerApp.Models.Question theQuestion = results.First(); if (Practice_Problem_Answer != null)//This is a Practice Problem { theQuestion.Practice_Problem = data; theQuestion.Practice_Problem_Answer = Practice_Problem_Answer; } else//(Practice_Problem == null) This is an Answer { theQuestion.Answer = data; //theQuestion.Practice_Problem_Answer = Practice_Problem_Answer; } } else//(results.Length == 0) This is a new Answer { //Create a new Question AnswerApp.Models.Question theQuestion = new AnswerApp.Models.Question(); //Populate the Question with the properties extracted from the file name theQuestion.Textbook_Title = Textbook_Title; theQuestion.Unit_Title = Unit_Title; theQuestion.Chapter_Title = Chapter_Title; theQuestion.Section_Title = Section_Title; theQuestion.Page_Number = Page_Number; theQuestion.Question_Number = Question_Number; //Populate the relational Id's based on previous hierarchical entries theQuestion.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id; theQuestion.Unit_Id = db.Units.Single(d => d.Unit_Title.Equals(Unit_Title)).Unit_Id; theQuestion.Chapter_Id = db.Chapters.Single(d => d.Chapter_Title.Equals(Chapter_Title)).Chapter_Id; //theQuestion.Section_Id = db.Sections.Single(d => d.Section_Title.Equals(Section_Title)).Section_Id; RetrievedSections = from theSections in db.Sections where theSections.Textbook_Title.Equals(Textbook_Title) && theSections.Unit_Title.Equals(Unit_Title) && theSections.Chapter_Title.Equals(Chapter_Title) && theSections.Section_Title.Equals(Section_Title) select theSections; theQuestion.Section_Id = RetrievedSections.First().Section_Id;// db.Questions.Single(d => d.Question_Title.Equals(Question_Title)).Question_Id; if (Page_Id != -1) { theQuestion.Page_Id = Page_Id; } else { //try //{ //theQuestion.Page_Id = db.Pages.Single(d => d.Page_Number.Equals(Page_Number)).Page_Id; RetrievedPages = from thePages in db.Pages where thePages.Textbook_Title.Equals(Textbook_Title) //&& thePages.Unit_Title.Equals(Unit_Title) //&& thePages.Chapter_Title.Equals(Chapter_Title) //&& thePages.Section_Title.Equals(Section_Title) && thePages.Page_Number.Equals(Page_Number) select thePages; theQuestion.Page_Id = RetrievedPages.First().Page_Id; //results = retrieved.ToArray<Question>(); /*} catch { IQueryable<Page> OldPages = from thePages in db.Pages where thePages.Textbook_Title.Equals(Textbook_Title) //&& thePages.Unit_Title.Equals(Unit_Title) //&& thePages.Chapter_Title.Equals(Chapter_Title) //&& thePages.Section_Title.Equals(Section_Title) //&& thePages.Page_Number.Equals(Page_Number) select thePages; Page[] theOldPages = OldPages.ToArray<Page>(); return "Error: The page you are attempting to add, Page " + theQuestion.Page_Number + ", already exists in a previously uploaded section with a different title. The title of the previously uploaded section is: " + theQuestion.Section_Title + ". The Title of the section you are presently uploading is: " + theOldPages[0].Section_Title + ". You will have to appropriately alter the section headings of your zipped directory and try again. skipping..."; }*/ } int test; if (!int.TryParse(theQuestion.Question_Number, out test)) { return "Error: You have attempted to add a question numbered '" + theQuestion.Question_Number + "'. The question number must be a number. You will have to correct this and try again. skipping... "; } if (Practice_Problem_Answer != null)//This is a Practice Problem { theQuestion.Practice_Problem = data; theQuestion.Practice_Problem_Answer = Practice_Problem_Answer; } else//(Practice_Problem == null) This is an Answer { theQuestion.Answer = data; //theQuestion.Practice_Problem_Answer = Practice_Problem_Answer; } //Insert the new Question into the database db.Questions.InsertOnSubmit(theQuestion); } db.SubmitChanges();//Commit the changes to the database.*/ return _Info; }
public ActionResult ResourceUnavailable(string argument) { if (argument == null) { return View(); } if (argument.Length < 1) { return View(); } if (!User.Identity.Name.Equals("administrator")) { return View(); } if (argument.Equals("delete Mathematics and Unit 10 textbook image")) { AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); Textbook Mathematics = db.Textbooks.Single<Textbook>(t => t.Title.Equals("Mathematics")); db.Textbooks.DeleteOnSubmit(Mathematics); Unit Unit10 = db.Units.Single<Unit>(U => U.Unit_Title.Equals("10")); db.Units.DeleteOnSubmit(Unit10); db.SubmitChanges(); } else if (argument.Equals("delete Pre-Calculus 11(Unit1)")) { AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); Textbook PreCalculus11Unit1 = db.Textbooks.Single<Textbook>(t => t.Title.Equals("Pre-Calculus 11(Unit1)")); db.Textbooks.DeleteOnSubmit(PreCalculus11Unit1); IQueryable<AnswerApp.Models.Unit> AllUnits = from theUnits in db.Units where theUnits.Textbook_Title.Equals("Pre-Calculus 11(Unit1)") select theUnits; foreach (Unit currentUnit in AllUnits) { db.Units.DeleteOnSubmit(currentUnit); } IQueryable<AnswerApp.Models.Chapter> AllChapters = from theChapters in db.Chapters where theChapters.Textbook_Title.Equals("Pre-Calculus 11(Unit1)") select theChapters; foreach (Chapter currentChapter in AllChapters) { db.Chapters.DeleteOnSubmit(currentChapter); } IQueryable<AnswerApp.Models.Section> AllSections = from theSections in db.Sections where theSections.Textbook_Title.Equals("Pre-Calculus 11(Unit1)") select theSections; foreach (Section currentSection in AllSections) { db.Sections.DeleteOnSubmit(currentSection); } IQueryable<AnswerApp.Models.Page> AllPages = from thePages in db.Pages where thePages.Textbook_Title.Equals("Pre-Calculus 11(Unit1)") select thePages; foreach (Page currentPage in AllPages) { db.Pages.DeleteOnSubmit(currentPage); } IQueryable<AnswerApp.Models.Question> AllQuestions = from theQuestions in db.Questions where theQuestions.Textbook_Title.Equals("Pre-Calculus 11(Unit1)") select theQuestions; foreach (Question currentQuestion in AllQuestions) { db.Questions.DeleteOnSubmit(currentQuestion); } db.SubmitChanges(); } else if (argument.Equals("delete Pre-Calculus 11(Section 2.1-2.4)")) { AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); Textbook PreCalculus11Unit1 = db.Textbooks.Single<Textbook>(t => t.Title.Equals("Pre-Calculus 11(Section 2.1-2.4)")); db.Textbooks.DeleteOnSubmit(PreCalculus11Unit1); IQueryable<AnswerApp.Models.Unit> AllUnits = from theUnits in db.Units where theUnits.Textbook_Title.Equals("Pre-Calculus 11(Section 2.1-2.4)") select theUnits; foreach (Unit currentUnit in AllUnits) { db.Units.DeleteOnSubmit(currentUnit); } IQueryable<AnswerApp.Models.Chapter> AllChapters = from theChapters in db.Chapters where theChapters.Textbook_Title.Equals("Pre-Calculus 11(Section 2.1-2.4)") select theChapters; foreach (Chapter currentChapter in AllChapters) { db.Chapters.DeleteOnSubmit(currentChapter); } IQueryable<AnswerApp.Models.Section> AllSections = from theSections in db.Sections where theSections.Textbook_Title.Equals("Pre-Calculus 11(Section 2.1-2.4)") select theSections; foreach (Section currentSection in AllSections) { db.Sections.DeleteOnSubmit(currentSection); } IQueryable<AnswerApp.Models.Page> AllPages = from thePages in db.Pages where thePages.Textbook_Title.Equals("Pre-Calculus 11(Section 2.1-2.4)") select thePages; foreach (Page currentPage in AllPages) { db.Pages.DeleteOnSubmit(currentPage); } IQueryable<AnswerApp.Models.Question> AllQuestions = from theQuestions in db.Questions where theQuestions.Textbook_Title.Equals("Pre-Calculus 11(Section 2.1-2.4)") select theQuestions; foreach (Question currentQuestion in AllQuestions) { db.Questions.DeleteOnSubmit(currentQuestion); } db.SubmitChanges(); } else if (argument.Equals("delete all user answers"))//false)//User.Identity.Name.Equals("administrator")) { AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); IQueryable<AnswerApp.Models.User> AllUsers = from theUsers in db.Users //where theUsers.Textbook_Title.Equals(Textbook_Title) //where theUsers.Question_Number.Equals(Question_Number) select theUsers; foreach (User currentUser in AllUsers) { currentUser.Answers = ""; currentUser.Credit = Convert.ToInt32("0"); } db.SubmitChanges(); } else if(argument.Equals("reset administrator")) { AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); User administrator = db.Users.Single<User>(u => u.UserName.Equals("administrator")); administrator.Credit = 3; administrator.Answers = ""; db.SubmitChanges(); } else { } return View(); }
//This method adds entry information //and also file contents to the database //whenever new Questions are added Boolean AddSolution(HttpPostedFileBase hpf, String FileName, UploadModel model) { AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); //Disect the file name for it's file properties String[] properties = FileName.Split(new char[1] { '_' }); String Textbook_Title = properties[0]; String Unit_Title = properties[1]; String Chapter_Title = properties[2]; String Section_Title = properties[3]; String Page_Number = properties[4]; String Question_Number = properties[5].Split(new char[1] { '.' })[0];//Truncate ".pdf" from the end of the file name String Practice_Problem = null; if (properties.Length > 6) { Practice_Problem = properties[6]; }//An 7th argument indicates a Practice Problem if (Practice_Problem != null) { Practice_Problem = properties[6].Split(new char[1] { '.' })[0]; }//Truncate ".pdf" from the end of the file name //Search teh database for this Textbook IQueryable<Textbook> RetrievedTextbooks = from theTextbooks in db.Textbooks where theTextbooks.Title.Equals(Textbook_Title) select theTextbooks; Textbook[] TextbookResults = RetrievedTextbooks.ToArray<Textbook>(); if (TextbookResults.Length == 0)//The Textbook does not yet exists { //Create a new Textbook AnswerApp.Models.Textbook theTextbook = new AnswerApp.Models.Textbook(); //Populate the Textbook with the properties extracted from the file name theTextbook.Title = Textbook_Title; if (theTextbook.Title.Length < 1) { return false; } db.Textbooks.InsertOnSubmit(theTextbook); db.SubmitChanges(); } //Search teh database for this Unit IQueryable<Unit> RetrievedUnits = from theUnits in db.Units where theUnits.Textbook_Title.Equals(Textbook_Title) && theUnits.Unit_Title.Equals(Unit_Title) select theUnits; Unit[] UnitResults = RetrievedUnits.ToArray<Unit>(); if (UnitResults.Length == 0)//The Unit does not yet exists { //Create a new Unit AnswerApp.Models.Unit theUnit = new AnswerApp.Models.Unit(); //Populate the Unit with the properties extracted from the file name theUnit.Textbook_Title = Textbook_Title; theUnit.Unit_Title = Unit_Title; //Populate the relational Id's based on previous hierarchical entries theUnit.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id; db.Units.InsertOnSubmit(theUnit); db.SubmitChanges(); } //Search the database for this Chapter IQueryable<Chapter> RetrievedChapters = from theChapters in db.Chapters where theChapters.Textbook_Title.Equals(Textbook_Title) && theChapters.Unit_Title.Equals(Unit_Title) && theChapters.Chapter_Title.Equals(Chapter_Title) select theChapters; Chapter[] ChapterResults = RetrievedChapters.ToArray<Chapter>(); if (ChapterResults.Length == 0)//The Chapter does not yet exists { //Create a new Chapter AnswerApp.Models.Chapter theChapter = new AnswerApp.Models.Chapter(); //Populate the Chapter with the properties extracted from the file name theChapter.Textbook_Title = Textbook_Title; theChapter.Unit_Title = Unit_Title; theChapter.Chapter_Title = Chapter_Title; //Populate the relational Id's based on previous hierarchical entries theChapter.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id; theChapter.Unit_Id = db.Units.Single(d => d.Unit_Title.Equals(Unit_Title)).Unit_Id; if (theChapter.Chapter_Title.Equals("MACOSX")) { return false;//"Error: You have attempted to add a chapter titled MACOSX... ... ... gAwD! O.o ...skipping..."; } db.Chapters.InsertOnSubmit(theChapter); db.SubmitChanges(); } //Search teh database for this Section IQueryable<Section> RetrievedSections = from theSections in db.Sections where theSections.Textbook_Title.Equals(Textbook_Title) && theSections.Unit_Title.Equals(Unit_Title) && theSections.Chapter_Title.Equals(Chapter_Title) && theSections.Section_Title.Equals(Section_Title) select theSections; Section[] SectionResults = RetrievedSections.ToArray<Section>(); if (SectionResults.Length == 0)//The Section does not yet exists { //Create a new Section AnswerApp.Models.Section theSection = new AnswerApp.Models.Section(); //Populate the Section with the properties extracted from the file name theSection.Textbook_Title = Textbook_Title; theSection.Unit_Title = Unit_Title; theSection.Chapter_Title = Chapter_Title; theSection.Section_Title = Section_Title; //Populate the relational Id's based on previous hierarchical entries theSection.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id; theSection.Unit_Id = db.Units.Single(d => d.Unit_Title.Equals(Unit_Title)).Unit_Id; theSection.Chapter_Id = db.Chapters.Single(d => d.Chapter_Title.Equals(Chapter_Title)).Chapter_Id; if (theSection.Section_Title.Length < 1) { return false; } db.Sections.InsertOnSubmit(theSection); db.SubmitChanges(); } //Search teh database for this Page IQueryable<Page> RetrievedPages = from thePages in db.Pages where thePages.Textbook_Title.Equals(Textbook_Title) //&& thePages.Unit_Title.Equals(Unit_Title) //&& thePages.Chapter_Title.Equals(Chapter_Title) //&& thePages.Section_Title.Equals(Section_Title) && thePages.Page_Number.Equals(Page_Number) select thePages; Page[] PageResults = RetrievedPages.ToArray<Page>(); if (PageResults.Length == 0)//The Page does not yet exists { //Create a new Page AnswerApp.Models.Page thePage = new AnswerApp.Models.Page(); //Populate the Page with the properties extracted from the file name thePage.Textbook_Title = Textbook_Title; thePage.Unit_Title = Unit_Title; thePage.Chapter_Title = Chapter_Title; thePage.Section_Title = Section_Title; thePage.Page_Number = Page_Number; //Populate the relational Id's based on previous hierarchical entries thePage.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id; thePage.Unit_Id = db.Units.Single(d => d.Unit_Title.Equals(Unit_Title)).Unit_Id; thePage.Chapter_Id = db.Chapters.Single(d => d.Chapter_Title.Equals(Chapter_Title)).Chapter_Id; thePage.Section_Id = db.Sections.Single(d => d.Section_Title.Equals(Section_Title)).Section_Id; int test; if (!int.TryParse(thePage.Page_Number, out test)) { return false; } db.Pages.InsertOnSubmit(thePage); db.SubmitChanges(); } //Search teh database for this Question IQueryable<Question> retrieved = from theAnswers in db.Questions where theAnswers.Textbook_Title.Equals(Textbook_Title) && theAnswers.Unit_Title.Equals(Unit_Title) && theAnswers.Chapter_Title.Equals(Chapter_Title) && theAnswers.Section_Title.Equals(Section_Title) && theAnswers.Page_Number.Equals(Page_Number) && theAnswers.Question_Number.Equals(Question_Number) select theAnswers; Question[] results = retrieved.ToArray<Question>(); if (results.Length != 0)//The Answer already exists { //Use the existing Question AnswerApp.Models.Question theQuestion = results.First(); if (Practice_Problem != null)//This is a Practice Problem { theQuestion.Practice_Problem = new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length); theQuestion.Practice_Problem_Answer = model.PracticeProblemAnswer; } else//(Practice_Problem == null) This is an Answer { theQuestion.Answer = new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length); theQuestion.Practice_Problem_Answer = model.PracticeProblemAnswer; } } else//(results.Length == 0) This is a new Answer { //Create a new Question AnswerApp.Models.Question theQuestion = new AnswerApp.Models.Question(); //Populate the Question with the properties extracted from the file name theQuestion.Textbook_Title = Textbook_Title; theQuestion.Unit_Title = Unit_Title; theQuestion.Chapter_Title = Chapter_Title; theQuestion.Section_Title = Section_Title; theQuestion.Page_Number = Page_Number; theQuestion.Question_Number = Question_Number; //Populate the relational Id's based on previous hierarchical entries theQuestion.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id; theQuestion.Unit_Id = db.Units.Single(d => d.Unit_Title.Equals(Unit_Title)).Unit_Id; theQuestion.Chapter_Id = db.Chapters.Single(d => d.Chapter_Title.Equals(Chapter_Title)).Chapter_Id; theQuestion.Section_Id = db.Sections.Single(d => d.Section_Title.Equals(Section_Title)).Section_Id; theQuestion.Page_Id = db.Pages.Single(d => d.Page_Number.Equals(Page_Number)).Page_Id; if (Practice_Problem != null)//This is a Practice Problem { theQuestion.Practice_Problem = new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length); theQuestion.Practice_Problem_Answer = model.PracticeProblemAnswer; } else//(Practice_Problem == null) This is an Answer { theQuestion.Answer = new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length); theQuestion.Practice_Problem_Answer = model.PracticeProblemAnswer; } int test; if (!int.TryParse(theQuestion.Page_Number, out test)) { return false; } //Insert the new Question into the database db.Questions.InsertOnSubmit(theQuestion); } db.SubmitChanges();//Commit the changes to the database. return true; }
public ActionResult PayPal(String argument, String returnURL) { 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) { return RedirectToAction("LogOn", "Account"); } String thisUsersAnswers = thisUser.Answers.Replace("Purchase_", "*");// += Filename_of_Solution_to_Purchase +";"; String[] Solution_Just_Purchased = thisUsersAnswers.Split(new char[1] { '*' }); String[] Local_Filename_of_Solution_to_Purchase = Solution_Just_Purchased[1].Split(new char[1] { ';' }); thisUser.Answers = thisUser.Answers.Replace("Purchase_", ""); db.SubmitChanges(); //Disect the file name for it's file properties String[] properties = Local_Filename_of_Solution_to_Purchase[0].Split(new char[1] { '_' }); String Textbook_Title = properties[0]; String Unit_Title = properties[1]; String Chapter_Title = properties[2]; String Section_Title = properties[3]; String Page_Number = properties[4]; String Question_Number = properties[5].Split(new char[1] { '.' })[0];//Truncate ".pdf" from the end of the file name String Practice_Problem = null; if (properties.Length > 6) { Practice_Problem = properties[6]; }//An 7th argument indicates a Practice Problem if (Practice_Problem != null) { Practice_Problem = properties[6].Split(new char[1] { '.' })[0]; }//Truncate ".pdf" from the end of the file name//*/ AnswerApp.Models.SelectModel model = new AnswerApp.Models.SelectModel(); model.Textbook = Textbook_Title; model.Unit = Unit_Title; model.Chapter = Chapter_Title; model.Section = Section_Title; model.Page = Page_Number; model.Question = Question_Number; //return RedirectToAction("ViewAnswer/" + User.Identity.Name, "Answers", model); return RedirectToAction("ViewAnswer/" + argument, "Answers"); }
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; }
//Allows the user to upload new Answers along with their respective //Practice Problem and the answer to that Practice Problem public ActionResult Upload(UploadModel model, string returnUrl) { List<ViewDataUploadFilesResult> r = new List<ViewDataUploadFilesResult>(); HttpPostedFileBase hpf = null;// = Request.Files[file] as HttpPostedFileBase; String FileName = null; foreach (string file in Request.Files) { hpf = Request.Files[file] as HttpPostedFileBase; if (hpf.ContentLength == 0) continue; //string savedFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "images\\" + Path.GetFileName(hpf.FileName)); string savedFileName = Path.Combine(Path.GetFileName(hpf.FileName)); //hpf.SaveAs(savedFileName);//Replace this with database insertion FileName = Path.GetFileName(hpf.FileName);// hpf.FileName; r.Add(new ViewDataUploadFilesResult() { Name = savedFileName, Length = hpf.ContentLength }); AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); //Disect the file name for it's file properties String[] properties = FileName.Split(new char[1] { '_' }); String Textbook_Title = properties[0]; String Unit_Title = properties[1]; String Chapter_Title = properties[2]; String Section_Title = properties[3]; String Page_Number = properties[4]; String Question_Number = properties[5].Split(new char[1] { '.' })[0];//Truncate ".pdf" from the end of the file name String Practice_Problem = null; if (properties.Length > 6) { Practice_Problem = properties[6]; }//An 7th argument indicates a Practice Problem if (Practice_Problem != null) { Practice_Problem = properties[6].Split(new char[1] { '.' })[0]; }//Truncate ".pdf" from the end of the file name //Search teh database for this Textbook IQueryable<Textbook> RetrievedTextbooks = from theTextbooks in db.Textbooks where theTextbooks.Title.Equals(Textbook_Title) select theTextbooks; Textbook[] TextbookResults = RetrievedTextbooks.ToArray<Textbook>(); if (TextbookResults.Length == 0)//The Textbook does not yet exists { //Create a new Textbook AnswerApp.Models.Textbook theTextbook = new AnswerApp.Models.Textbook(); //Populate the Textbook with the properties extracted from the file name theTextbook.Title = Textbook_Title; db.Textbooks.InsertOnSubmit(theTextbook); db.SubmitChanges(); } //Search teh database for this Unit IQueryable<Unit> RetrievedUnits = from theUnits in db.Units where theUnits.Textbook_Title.Equals(Textbook_Title) && theUnits.Unit_Title.Equals(Unit_Title) select theUnits; Unit[] UnitResults = RetrievedUnits.ToArray<Unit>(); if (UnitResults.Length == 0)//The Unit does not yet exists { //Create a new Unit AnswerApp.Models.Unit theUnit = new AnswerApp.Models.Unit(); //Populate the Unit with the properties extracted from the file name theUnit.Textbook_Title = Textbook_Title; theUnit.Unit_Title = Unit_Title; //Populate the relational Id's based on previous hierarchical entries theUnit.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id; db.Units.InsertOnSubmit(theUnit); db.SubmitChanges(); } //Search the database for this Chapter IQueryable<Chapter> RetrievedChapters = from theChapters in db.Chapters where theChapters.Textbook_Title.Equals(Textbook_Title) && theChapters.Unit_Title.Equals(Unit_Title) && theChapters.Chapter_Title.Equals(Chapter_Title) select theChapters; Chapter[] ChapterResults = RetrievedChapters.ToArray<Chapter>(); if (ChapterResults.Length == 0)//The Chapter does not yet exists { //Create a new Chapter AnswerApp.Models.Chapter theChapter = new AnswerApp.Models.Chapter(); //Populate the Chapter with the properties extracted from the file name theChapter.Textbook_Title = Textbook_Title; theChapter.Unit_Title = Unit_Title; theChapter.Chapter_Title = Chapter_Title; //Populate the relational Id's based on previous hierarchical entries theChapter.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id; theChapter.Unit_Id = db.Units.Single(d => d.Unit_Title.Equals(Unit_Title)).Unit_Id; db.Chapters.InsertOnSubmit(theChapter); db.SubmitChanges(); } //Search teh database for this Section IQueryable<Section> RetrievedSections = from theSections in db.Sections where theSections.Textbook_Title.Equals(Textbook_Title) && theSections.Unit_Title.Equals(Unit_Title) && theSections.Chapter_Title.Equals(Chapter_Title) && theSections.Section_Title.Equals(Section_Title) select theSections; Section[] SectionResults = RetrievedSections.ToArray<Section>(); if (SectionResults.Length == 0)//The Section does not yet exists { //Create a new Section AnswerApp.Models.Section theSection = new AnswerApp.Models.Section(); //Populate the Section with the properties extracted from the file name theSection.Textbook_Title = Textbook_Title; theSection.Unit_Title = Unit_Title; theSection.Chapter_Title = Chapter_Title; theSection.Section_Title = Section_Title; //Populate the relational Id's based on previous hierarchical entries theSection.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id; theSection.Unit_Id = db.Units.Single(d => d.Unit_Title.Equals(Unit_Title)).Unit_Id; theSection.Chapter_Id = db.Chapters.Single(d => d.Chapter_Title.Equals(Chapter_Title)).Chapter_Id; db.Sections.InsertOnSubmit(theSection); db.SubmitChanges(); } //Search teh database for this Page IQueryable<Page> RetrievedPages = from thePages in db.Pages where thePages.Textbook_Title.Equals(Textbook_Title) && thePages.Unit_Title.Equals(Unit_Title) && thePages.Chapter_Title.Equals(Chapter_Title) && thePages.Section_Title.Equals(Section_Title) && thePages.Page_Number.Equals(Page_Number) select thePages; Page[] PageResults = RetrievedPages.ToArray<Page>(); if (PageResults.Length == 0)//The Page does not yet exists { //Create a new Page AnswerApp.Models.Page thePage = new AnswerApp.Models.Page(); //Populate the Page with the properties extracted from the file name thePage.Textbook_Title = Textbook_Title; thePage.Unit_Title = Unit_Title; thePage.Chapter_Title = Chapter_Title; thePage.Section_Title = Section_Title; thePage.Page_Number = Page_Number; //Populate the relational Id's based on previous hierarchical entries thePage.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id; thePage.Unit_Id = db.Units.Single(d => d.Unit_Title.Equals(Unit_Title)).Unit_Id; thePage.Chapter_Id = db.Chapters.Single(d => d.Chapter_Title.Equals(Chapter_Title)).Chapter_Id; thePage.Section_Id = db.Sections.Single(d => d.Section_Title.Equals(Section_Title)).Section_Id; db.Pages.InsertOnSubmit(thePage); } //Search teh database for this Question IQueryable<Question> retrieved = from theAnswers in db.Questions where theAnswers.Textbook_Title.Equals(Textbook_Title) && theAnswers.Unit_Title.Equals(Unit_Title) && theAnswers.Chapter_Title.Equals(Chapter_Title) && theAnswers.Section_Title.Equals(Section_Title) && theAnswers.Page_Number.Equals(Page_Number) && theAnswers.Question_Number.Equals(Question_Number) select theAnswers; Question[] results = retrieved.ToArray<Question>(); if (results.Length != 0)//The Answer already exists { //Use the existing Question AnswerApp.Models.Question theQuestion = results.First(); if (Practice_Problem != null)//This is a Practice Problem { theQuestion.Practice_Problem = new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length); theQuestion.Practice_Problem_Answer = model.PracticeProblemAnswer; } else//(Practice_Problem == null) This is an Answer { theQuestion.Answer = new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length); theQuestion.Practice_Problem_Answer = model.PracticeProblemAnswer; } } else//(results.Length == 0) This is a new Answer { //Create a new Question AnswerApp.Models.Question theQuestion = new AnswerApp.Models.Question(); //Populate the Question with the properties extracted from the file name theQuestion.Textbook_Title = Textbook_Title; theQuestion.Unit_Title = Unit_Title; theQuestion.Chapter_Title = Chapter_Title; theQuestion.Section_Title = Section_Title; theQuestion.Page_Number = Page_Number; theQuestion.Question_Number = Question_Number; //Populate the relational Id's based on previous hierarchical entries theQuestion.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id; theQuestion.Unit_Id = db.Units.Single(d => d.Unit_Title.Equals(Unit_Title)).Unit_Id; theQuestion.Chapter_Id = db.Chapters.Single(d => d.Chapter_Title.Equals(Chapter_Title)).Chapter_Id; theQuestion.Section_Id = db.Sections.Single(d => d.Section_Title.Equals(Section_Title)).Section_Id; theQuestion.Page_Id = db.Pages.Single(d => d.Page_Number.Equals(Page_Number)).Page_Id; if (Practice_Problem != null)//This is a Practice Problem { theQuestion.Practice_Problem = new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length); theQuestion.Practice_Problem_Answer = model.PracticeProblemAnswer; } else//(Practice_Problem == null) This is an Answer { theQuestion.Answer = new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length); theQuestion.Practice_Problem_Answer = model.PracticeProblemAnswer; } //Insert the new Question into the database db.Questions.InsertOnSubmit(theQuestion); } db.SubmitChanges();//Commit the changes to the database. } if(User.Identity.Name.Equals("administrator")){} return View("Upload", r); }
public ActionResult Pay(SelectModel model, string returnUrl) { 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("LogIn", "Account"); } String filename = "" + model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf"; /*TO DO * Go through all previous purchases and * erase them from the user's List of Answers: * Use String.Replace to finally replace the Purchase_ clause * Then split the answer string based on the * replacing string (which must also be a single character) * "*" for example. * Save each component of the string so that it can be * reconstructed to the original answer string for that user * The frist string in the array will be al answers * before the recent purcahse, the following strings will be * all purchases after that one. * It is important to note that all of the strings other than the first * will be ones that started with purchase meaning they will have the * answer that has just been purchased plus all answers already payed for * after that purcahase up until the next new purchase. * Each of these substrings should be split on the ';' character to isolate * the file name of the solution just purchased. * * Or the easy way is to replace "Purchase_" with "". * //*/ //thisUser.Answers += "" + "Purchase_" + filename + ";";//Purchase indicates that the item is not yet payed for. 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(); if (model.Unit.Equals("All")) { ViewData["grouping"] = "Textbook"; } else if (model.Chapter.Equals("All")) { ViewData["grouping"] = "Unit"; } else if (model.Section.Equals("All")) { ViewData["grouping"] = "Chapter"; } else if (model.Page.Equals("All")) { ViewData["grouping"] = "Section"; } else if (model.Question.Equals("All")) { ViewData["grouping"] = "Page"; } else { ViewData["grouping"] = "Question"; } return RedirectToAction("ViewAnswer/purchase", "Answers", model); }
public ActionResult ResourceUnavailable(HomeModel model) { AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); AnswerApp.Models.User administrator = db.Users.Single<User>(u => u.UserName.Equals("administrator")); //administrator.Answers = ""; db.SubmitChanges(); return View(); }