Exemplo n.º 1
0
        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();
            }
        }
Exemplo n.º 2
0
        public void Index()
        {
            // Arrange
            HomeController controller = new HomeController();

            // Act
            SelectModel model = new SelectModel();
            ViewResult result = controller.Index(model) as ViewResult;

            // Assert
            Assert.AreEqual("Welcome to ASP.NET MVC!", result.ViewBag.Message);
        }
Exemplo n.º 3
0
        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");
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        public String GenerateSelectionList(SelectModel model)
        {
            //This algorithm populates an html markup of links based on the user's selected set of solutions
            String SelectionList = "";

            AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext();

            if (model.Textbook.Equals("All"))//All Textbooks have been specified
            {
                //Retrieve all textbook
                IQueryable<AnswerApp.Models.Textbook> retrieved = from theAnswers in db.Textbooks
                                                                  select theAnswers;
                AnswerApp.Models.Textbook[] results = retrieved.ToArray<AnswerApp.Models.Textbook>();
                foreach (Textbook theTextbook in results)//For each textbook
                {
                    //If the user has access to atextbook with this title,
                    model.Textbook = theTextbook.Title;
                    if (UserHasAccess(User.Identity.Name, model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf"))
                    {
                        SelectionList += "<a href=\"" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">" + theTextbook.Title + "</a><br />" + GenerateSelectionList(model);
                    }
                    else
                    {
                        SelectionList += "<a style=\"color: #FF0000\" href=\"" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">" + theTextbook.Title + "</a><br />" + GenerateSelectionList(model);
                    }
                    model.Textbook = "All";
                }
            }
            if (model.Unit.Equals("All"))//All units have been specified
            {
                IQueryable<AnswerApp.Models.Unit> retrieved = from theAnswers in db.Units
                                                              where theAnswers.Textbook_Title.Equals(model.Textbook)
                                                              select theAnswers;
                AnswerApp.Models.Unit[] preresults = retrieved.ToArray<AnswerApp.Models.Unit>();
                System.Linq.IOrderedEnumerable<AnswerApp.Models.Unit> results = preresults.OrderBy(Unit => Unit.Unit_Title);
                foreach (Unit theUnit in results)
                {
                    model.Unit = theUnit.Unit_Title;
                    if (UserHasAccess(User.Identity.Name, model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf"))
                    {
                        SelectionList += "&nbsp;<a href=\"" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">" + theUnit.Unit_Title + "</a><br />" + GenerateSelectionList(model);
                    }
                    else
                    {
                        SelectionList += "&nbsp;<a style=\"color: #FF0000\" href=\"" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">" + theUnit.Unit_Title + "</a><br />" + GenerateSelectionList(model);
                    }
                    model.Unit = "All";
                }
            }
            else if (model.Chapter.Equals("All"))//All chapters have been selected
            {
                IQueryable<AnswerApp.Models.Chapter> retrieved = from theAnswers in db.Chapters
                                                                 where theAnswers.Textbook_Title.Equals(model.Textbook)
                                                                 && theAnswers.Unit_Title.Equals(model.Unit)
                                                                 select theAnswers;
                AnswerApp.Models.Chapter[] preresults = retrieved.ToArray<AnswerApp.Models.Chapter>();
                System.Linq.IOrderedEnumerable<AnswerApp.Models.Chapter> results = preresults.OrderBy(Chapter => Chapter.Chapter_Title);
                foreach (Chapter theChapter in results)
                {
                    model.Chapter = theChapter.Chapter_Title;
                    if (UserHasAccess(User.Identity.Name, model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf"))
                    {
                        SelectionList += "&nbsp;&nbsp;<a href=\"" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">" + theChapter.Chapter_Title + "</a><br />" + GenerateSelectionList(model);
                    }
                    else
                    {
                        SelectionList += "&nbsp;&nbsp;<a style=\"color: #FF0000\" href=\"" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">" + theChapter.Chapter_Title + "</a><br />" + GenerateSelectionList(model);
                    }
                    model.Chapter = "All";
                }
            }
            else if (model.Section.Equals("All"))//All Sections have been selected
            {
                IQueryable<AnswerApp.Models.Section> retrieved = from theAnswers in db.Sections
                                                                 where theAnswers.Textbook_Title.Equals(model.Textbook)
                                                                 && theAnswers.Unit_Title.Equals(model.Unit)
                                                                 && theAnswers.Chapter_Title.Equals(model.Chapter)
                                                                 select theAnswers;
                AnswerApp.Models.Section[] preresults = retrieved.ToArray<AnswerApp.Models.Section>();
                System.Linq.IOrderedEnumerable<AnswerApp.Models.Section> results = preresults.OrderBy(Section => Section.Section_Title);
                foreach (Section theSection in results)
                {
                    model.Section = theSection.Section_Title;
                    if (UserHasAccess(User.Identity.Name, model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf"))
                    {
                        SelectionList += "&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">" + theSection.Section_Title + "</a><br />" + GenerateSelectionList(model);
                    }
                    else
                    {
                        SelectionList += "&nbsp;&nbsp;&nbsp;&nbsp;<a style=\"color: #FF0000\" href=\"" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">" + theSection.Section_Title + "</a><br />" + GenerateSelectionList(model);
                    }
                    model.Section = "All";
                }
            }
            else if (model.Page.Equals("All"))//Only one unit has been specified
            {
                IQueryable<AnswerApp.Models.Page> retrieved = from theAnswers in db.Pages
                                                              where theAnswers.Textbook_Title.Equals(model.Textbook)
                                                              && theAnswers.Unit_Title.Equals(model.Unit)
                                                              && theAnswers.Chapter_Title.Equals(model.Chapter)
                                                              && theAnswers.Section_Title.Equals(model.Section)
                                                              select theAnswers;
                AnswerApp.Models.Page[] preresults = retrieved.ToArray<AnswerApp.Models.Page>();
                System.Linq.IOrderedEnumerable<AnswerApp.Models.Page> results = preresults.OrderBy(Page => Page.Page_Number);
                foreach (Page thePage in results)
                {
                    model.Page = thePage.Page_Number;
                    //newModel.Page = thePage.Page_Number;
                    if (UserHasAccess(User.Identity.Name, model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf"))
                    {
                        SelectionList += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">Page " + thePage.Page_Number + "</a><br />" + GenerateSelectionList(model);
                    }
                    else
                    {
                        SelectionList += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a style=\"color: #FF0000\" href=\"" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">Page " + thePage.Page_Number + "</a><br />" + GenerateSelectionList(model);
                    }
                    model.Page = "All";
                }
            }
            else if (model.Question.Equals("All"))//Only one unit has been specified
            {
                IQueryable<AnswerApp.Models.Question> retrieved = from theAnswers in db.Questions
                                                                  where theAnswers.Textbook_Title.Equals(model.Textbook)
                                                                  && theAnswers.Unit_Title.Equals(model.Unit)
                                                                  && theAnswers.Chapter_Title.Equals(model.Chapter)
                                                                  && theAnswers.Section_Title.Equals(model.Section)
                                                                  && theAnswers.Page_Number.Equals(model.Page)
                                                                  select theAnswers;
                AnswerApp.Models.Question[] preresults = retrieved.ToArray<AnswerApp.Models.Question>();
                System.Linq.IOrderedEnumerable<AnswerApp.Models.Question> results = preresults.OrderBy(Question => Question.Question_Number);
                foreach (Question theQuestion in results)
                {
                    model.Question = theQuestion.Question_Number;
                    //newModel.Question = theQuestion.Question_Number;
                    if (UserHasAccess(User.Identity.Name, model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf"))
                    {
                        SelectionList += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">Question " + theQuestion.Question_Number + "</a><br />" + GenerateSelectionList(model);
                    }
                    else
                    {
                        SelectionList += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a style=\"color: #FF0000\" href=\"" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">Question " + theQuestion.Question_Number + "</a><br />" + GenerateSelectionList(model);
                    }
                    //~/Answers/ViewAnswer/123456?Textbook=Mathematics 10&Unit=All&Chapter=All&Section=All&Page=All&Question=All
                    model.Question = "All";
                }
            }

            return SelectionList;
        }
Exemplo n.º 7
0
 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;
 }
Exemplo n.º 8
0
        public ActionResult ViewAnswer(string argument, SelectModel model)
        {
            ViewData["SelectionList"] = "Error: No list";
            ViewData["RenderAnswer"] = "false";//don't render practice answer before the user has answered it

            String FilenameExtensionless = "" + model.Textbook +
                              "_" + model.Unit +
                              "_" + model.Chapter +
                              "_" + model.Section +
                              "_" + model.Page +
                              "_" + model.Question;
            ViewData["FileNameExtensionless"] = FilenameExtensionless;
            String FileName = "" + FilenameExtensionless + ".pdf";
            ViewData["FileName"] = FileName;
            ViewData["PracticeProblemFileName"] = "" + ViewData["FileNameExtensionless"] + "_Practice Problem.png";

            //ViewData["CorrectAnswer"] = "";// null;
            ViewData["HasPracticeProblem"] = "false";
            ViewData["SelectionList"] = GenerateSelectionList(model);

            AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext();

            AnswerApp.Models.User theUser = new AnswerApp.Models.User();
            theUser = db.Users.Single(u => u.UserName.Equals(User.Identity.Name));
            //if (theUser != null)
            {
                //if (theUser.Answers != null)
                {
                    if (UserHasAccess(User.Identity.Name, FileName))
                    {
                        if ((NumberOfQuestions(model, db) == 1) && model.Question.Equals("All"))
                        {
                            IQueryable<Question> find = from theQuestions in db.Questions
                                                        where theQuestions.Textbook_Title.Equals(model.Textbook)
                                                        && theQuestions.Unit_Title.Equals(model.Unit)
                                                        && theQuestions.Chapter_Title.Equals(model.Chapter)
                                                        && theQuestions.Section_Title.Equals(model.Section)
                                                        && theQuestions.Page_Number.Equals(model.Page)
                                                        //&& theQuestions.Question_Number.Equals(model.Question)
                                                        select theQuestions;
                            Question result = find.First();
                            model.Question = result.Question_Number;
                            FileName = model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf";
                            ViewData["FileName"] = FileName;
                        }
                        IQueryable<Question> retrieved = from theAnswers in db.Questions
                                                         where theAnswers.Textbook_Title.Equals(model.Textbook)
                                                         && theAnswers.Unit_Title.Equals(model.Unit)
                                                         && theAnswers.Chapter_Title.Equals(model.Chapter)
                                                         && theAnswers.Section_Title.Equals(model.Section)
                                                         && theAnswers.Page_Number.Equals(model.Page)
                                                         && theAnswers.Question_Number.Equals(model.Question)
                                                         select theAnswers;
                        Question[] results = retrieved.ToArray<Question>();
                        if (results.Length != 0)
                        {
                            AnswerApp.Models.Question theSolution = results.First<Question>();
                            if (theSolution.Practice_Problem != null)
                            {
                                ViewData["HasPracticeProblem"] = "true";
                            }
                        }
                        //AnswerApp.Models.Question theSolution = db.Questions.Single(u => u.Question_Id.Equals
                        return View("ViewAnswer", model);
                    }
                    else
                    {
                        if (NumberOfQuestions(model, db) > 0)
                        {
                            if (AddSolutionByCredit(theUser, db, model))
                            {
                                if ((NumberOfQuestions(model, db) == 1) && model.Question.Equals("All"))
                                {
                                    IQueryable<Question> find = from theQuestions in db.Questions
                                                                where theQuestions.Textbook_Title.Equals(model.Textbook)
                                                                && theQuestions.Unit_Title.Equals(model.Unit)
                                                                && theQuestions.Chapter_Title.Equals(model.Chapter)
                                                                && theQuestions.Section_Title.Equals(model.Section)
                                                                && theQuestions.Page_Number.Equals(model.Page)
                                                                //&& theQuestions.Question_Number.Equals(model.Question)
                                                                select theQuestions;
                                    Question[] findings = find.ToArray();
                                    if (findings.Length > 0)
                                    {
                                        Question result = findings.First();
                                        model.Question = result.Question_Number;
                                        FileName = model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf";
                                        ViewData["FileName"] = FileName;
                                    }
                                }
                                IQueryable<Question> retrieved = from theAnswers in db.Questions
                                                                 where theAnswers.Textbook_Title.Equals(model.Textbook)
                                                                 && theAnswers.Unit_Title.Equals(model.Unit)
                                                                 && theAnswers.Chapter_Title.Equals(model.Chapter)
                                                                 && theAnswers.Section_Title.Equals(model.Section)
                                                                 && theAnswers.Page_Number.Equals(model.Page)
                                                                 && theAnswers.Question_Number.Equals(model.Question)
                                                                 select theAnswers;
                                Question[] results = retrieved.ToArray<Question>();
                                if (results.Length != 0)
                                {
                                    AnswerApp.Models.Question theSolution = results.First<Question>();
                                    if (theSolution.Practice_Problem != null)
                                    {
                                        ViewData["HasPracticeProblem"] = "true";
                                    }
                                }
                                return View("ViewAnswer", model);
                            }
                            else
                            {
                                return RedirectToAction("Pay", "Answers", model);
                            }
                        }
                        else
                        {
                            return RedirectToAction("Index", "Home", model);
                        }
                    }
                }
            }
            return View(model);// RedirectToAction("LogIn", "Account");
        }
Exemplo n.º 9
0
 //Determines whether a user has access to a given grouping of solutions
 public Boolean UserHasAccess(User theUser, SelectModel model, AnswerAppDataContext db)
 {
     String FileName = model.Textbook +
                       "_" + model.Unit +
                       "_" + model.Chapter +
                       "_" + model.Section +
                       "_" + model.Page +
                       "_" + model.Question +
                       ".pdf";
     return UserHasAccess(theUser, FileName, db);
 }
Exemplo n.º 10
0
        public ActionResult PayPal(String argument, String returnURL)
        {
            return RedirectToAction("Index", "Home");

            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("LogIn", "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");
        }
Exemplo n.º 11
0
        public ActionResult ViewAnswer(string argument, SelectModel model)
        {
            ViewData["SelectionList"] = "Error: No list";
            ViewData["RenderAnswer"] = "false";//don't render practice answer before the user has answered it

            String FilenameExtensionless = "" + model.Textbook +
                              "_" + model.Unit +
                              "_" + model.Chapter +
                              "_" + model.Section +
                              "_" + model.Page +
                              "_" + model.Question;
            ViewData["FileNameExtensionless"] = FilenameExtensionless;
            String FileName = "" + FilenameExtensionless + ".pdf";
            ViewData["FileName"] = FileName;
            ViewData["PracticeProblemFileName"] = "" + ViewData["FileNameExtensionless"] + "_Practice Problem.png";

            AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext();

            AnswerApp.Models.User theUser = new AnswerApp.Models.User();
            theUser = db.Users.Single(u => u.UserName.Equals(User.Identity.Name));
            if (theUser != null)
            {
                if (theUser.Answers != null)
                {
                    if (UserHasAccess(User.Identity.Name, FileName))
                    {
                        if (model.Unit.Equals("All") || model.Chapter.Equals("All") || model.Section.Equals("All") || model.Page.Equals("All") || model.Question.Equals("All"))
                        {
                            RedirectToAction("Index", "Home");
                        }
                        ViewData["SelectionList"] = GenerateSelectionList(model);
                        return View("ViewAnswer", model);
                    }
                }
                return RedirectToAction("Pay", "Answers", model);
            }
            return RedirectToAction("Logon", "Account");
        }
Exemplo n.º 12
0
        public ActionResult Select(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;

            //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

            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);
        }
Exemplo n.º 13
0
        public ActionResult Index(HomeModel 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;

            //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

            //Populate parent groupings based on childgroupings
            if (!Question_Number.Equals("All") && Page_Number.Equals("All"))
            {
                Page_Number = db.Questions.Single<Question>(q => q.Question_Number.Equals(Question_Number)).Page_Number;
            }
            if (!Page_Number.Equals("All") && Section_Title.Equals("All"))
            {
                Section_Title = db.Pages.Single<Page>(p => p.Page_Number.Equals(Page_Number)).Section_Title;
            }
            if (!Section_Title.Equals("All") && Chapter_Title.Equals("All"))
            {
                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;
            }
            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;

            return RedirectToAction("ViewAnswer/" + User.Identity.Name, "Answers", theSelectModel);
        }
Exemplo n.º 14
0
        public ActionResult Index(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));

                if (thisUser == null) { return RedirectToAction("LogOn", "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);
                return View(model);
            }
            else
            {
                return RedirectToAction("LogOn", "Account"); //return View();
            }
        }
Exemplo n.º 15
0
        public String GenerateSelectionList(SelectModel model)
        {
            String SelectionList = "";

            AnswerApp.Models.SelectModel newModel = new AnswerApp.Models.SelectModel();
            newModel.Textbook = model.Textbook;
            newModel.Unit = model.Unit;
            newModel.Chapter = model.Chapter;
            newModel.Section = model.Section;
            newModel.Page = model.Page;
            newModel.Question = model.Question;
            AnswerApp.Controllers.AnswersController thisAnswerController = new AnswerApp.Controllers.AnswersController();

            AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext();
            AnswerApp.Models.User thisUser = db.Users.Single<User>(u => u.UserName.Equals(User.Identity.Name));
            if (thisUser.Answers == null) { return null; }
            String[] ThisUsersAnswers = thisUser.Answers.Split(new char[1] { ';' });
            if (model.Textbook.Equals("All"))//All Textbooks have been specified
            {
                IQueryable<AnswerApp.Models.Textbook> retrieved = from theAnswers in db.Textbooks
                                                                  select theAnswers;
                AnswerApp.Models.Textbook[] results = retrieved.ToArray<AnswerApp.Models.Textbook>();
                foreach (Textbook theTextbook in results)
                {
                    model.Textbook = theTextbook.Title;
                    if (UserHasAccess(User.Identity.Name, model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf"))
                    {
                        SelectionList += "<a href=\"Answers/ViewAnswer/" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">" + theTextbook.Title + "</a><br />" + GenerateSelectionList(model);
                    }
                    else
                    {
                        foreach (String thisAnswer in ThisUsersAnswers)
                        {
                            String[] theseProperties = thisAnswer.Split(new char[1] { '_' });
                            if (!(theseProperties.Length < 2))
                            {
                                AnswerApp.Models.SelectModel thisModel = new AnswerApp.Models.SelectModel();
                                thisModel.Textbook = theseProperties[0];
                                thisModel.Unit = theseProperties[1];
                                thisModel.Chapter = theseProperties[2];
                                thisModel.Section = theseProperties[3];
                                thisModel.Page = theseProperties[4];
                                thisModel.Question = theseProperties[5].Split(new char[1] { '.' })[0];//Truncate ".pdf" from the end of the file name
                                if (thisModel.Textbook.Equals(model.Textbook)) { SelectionList += "<a style=\"color: #FF0000\" href=\"Answers/ViewAnswer/" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">" + theTextbook.Title + "</a><br />" + GenerateSelectionList(model); break; }
                            }
                            else { SelectionList += GenerateSelectionList(model); }
                        }
                    }
                    model.Textbook = "All";
                }
            }
            if (model.Unit.Equals("All"))//All units have been specified
            {
                IQueryable<AnswerApp.Models.Unit> retrieved = from theAnswers in db.Units
                                                              where theAnswers.Textbook_Title.Equals(model.Textbook)
                                                              select theAnswers;
                AnswerApp.Models.Unit[] results = retrieved.ToArray<AnswerApp.Models.Unit>();
                foreach (Unit theUnit in results)
                {
                    model.Unit = theUnit.Unit_Title;
                    if (UserHasAccess(User.Identity.Name, model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf"))
                    {
                        SelectionList += "&nbsp;<a href=\"Answers/ViewAnswer/" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">" + theUnit.Unit_Title + "</a><br />" + GenerateSelectionList(model);
                    }
                    else
                    {
                        foreach (String thisAnswer in ThisUsersAnswers)
                        {
                            String[] theseProperties = thisAnswer.Split(new char[1] { '_' });
                            if (!(theseProperties.Length < 2))
                            {
                                AnswerApp.Models.SelectModel thisModel = new AnswerApp.Models.SelectModel();
                                thisModel.Textbook = theseProperties[0];
                                thisModel.Unit = theseProperties[1];
                                thisModel.Chapter = theseProperties[2];
                                thisModel.Section = theseProperties[3];
                                thisModel.Page = theseProperties[4];
                                thisModel.Question = theseProperties[5].Split(new char[1] { '.' })[0];//Truncate ".pdf" from the end of the file name
                                if (thisModel.Unit.Equals(model.Unit)) { SelectionList += "&nbsp;<a style=\"color: #FF0000\" href=\"Answers/ViewAnswer/" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">" + theUnit.Unit_Title + "</a><br />" + GenerateSelectionList(model); break; }
                            }
                            else { SelectionList += GenerateSelectionList(model); }
                        }
                    }
                    model.Unit = "All";
                }
            }
            else if (model.Chapter.Equals("All"))//Only one unit has been specified
            {
                IQueryable<AnswerApp.Models.Chapter> retrieved = from theAnswers in db.Chapters
                                                                 where theAnswers.Textbook_Title.Equals(model.Textbook)
                                                                 && theAnswers.Unit_Title.Equals(model.Unit)
                                                                 select theAnswers;
                AnswerApp.Models.Chapter[] results = retrieved.ToArray<AnswerApp.Models.Chapter>();
                foreach (Chapter theChapter in results)
                {
                    model.Chapter = theChapter.Chapter_Title;
                    if (UserHasAccess(User.Identity.Name, model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf"))
                    {
                        SelectionList += "&nbsp;&nbsp;<a href=\"Answers/ViewAnswer/" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">" + theChapter.Chapter_Title + "</a><br />" + GenerateSelectionList(model);
                    }
                    else
                    {
                        foreach (String thisAnswer in ThisUsersAnswers)
                        {
                            String[] theseProperties = thisAnswer.Split(new char[1] { '_' });
                            if (!(theseProperties.Length < 2))
                            {
                                AnswerApp.Models.SelectModel thisModel = new AnswerApp.Models.SelectModel();
                                thisModel.Textbook = theseProperties[0];
                                thisModel.Unit = theseProperties[1];
                                thisModel.Chapter = theseProperties[2];
                                thisModel.Section = theseProperties[3];
                                thisModel.Page = theseProperties[4];
                                thisModel.Question = theseProperties[5].Split(new char[1] { '.' })[0];//Truncate ".pdf" from the end of the file name
                                if (thisModel.Chapter.Equals(model.Chapter)) { SelectionList += "&nbsp;&nbsp;<a style=\"color: #FF0000\" href=\"Answers/ViewAnswer/" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">" + theChapter.Chapter_Title + "</a><br />" + GenerateSelectionList(model); break; }
                            }
                            else { SelectionList += GenerateSelectionList(model); }
                        }
                    }
                    model.Chapter = "All";
                }
            }
            else if (model.Section.Equals("All"))//Only one unit has been specified
            {
                IQueryable<AnswerApp.Models.Section> retrieved = from theAnswers in db.Sections
                                                                 where theAnswers.Textbook_Title.Equals(model.Textbook)
                                                                 && theAnswers.Unit_Title.Equals(model.Unit)
                                                                 && theAnswers.Chapter_Title.Equals(model.Chapter)
                                                                 select theAnswers;
                AnswerApp.Models.Section[] results = retrieved.ToArray<AnswerApp.Models.Section>();
                foreach (Section theSection in results)
                {
                    model.Section = theSection.Section_Title;
                    if (UserHasAccess(User.Identity.Name, model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf"))
                    {
                        SelectionList += "&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"Answers/ViewAnswer/" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">Section " + theSection.Section_Title + "</a><br />" + GenerateSelectionList(model);
                    }
                    else
                    {
                        foreach (String thisAnswer in ThisUsersAnswers)
                        {
                            String[] theseProperties = thisAnswer.Split(new char[1] { '_' });
                            if (!(theseProperties.Length < 2))
                            {
                                AnswerApp.Models.SelectModel thisModel = new AnswerApp.Models.SelectModel();
                                thisModel.Textbook = theseProperties[0];
                                thisModel.Unit = theseProperties[1];
                                thisModel.Chapter = theseProperties[2];
                                thisModel.Section = theseProperties[3];
                                thisModel.Page = theseProperties[4];
                                thisModel.Question = theseProperties[5].Split(new char[1] { '.' })[0];//Truncate ".pdf" from the end of the file name
                                if (thisModel.Section.Equals(model.Section)) { SelectionList += "&nbsp;&nbsp;&nbsp;&nbsp;<a style=\"color: #FF0000\" href=\"Answers/ViewAnswer/" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">Section " + theSection.Section_Title + "</a><br />" + GenerateSelectionList(model); break; }
                            }
                            else { SelectionList += GenerateSelectionList(model); }
                        }
                    }
                    model.Section = "All";
                }
            }
            else if (model.Page.Equals("All"))//Only one unit has been specified
            {
                IQueryable<AnswerApp.Models.Page> retrieved = from theAnswers in db.Pages
                                                              where theAnswers.Textbook_Title.Equals(model.Textbook)
                                                              && theAnswers.Unit_Title.Equals(model.Unit)
                                                              && theAnswers.Chapter_Title.Equals(model.Chapter)
                                                              && theAnswers.Section_Title.Equals(model.Section)
                                                              select theAnswers;
                AnswerApp.Models.Page[] results = retrieved.ToArray<AnswerApp.Models.Page>();
                foreach (Page thePage in results)
                {
                    model.Page = thePage.Page_Number;
                    if (UserHasAccess(User.Identity.Name, model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf"))
                    {
                        SelectionList += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"Answers/ViewAnswer/" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">Page " + thePage.Page_Number + "</a><br />" + GenerateSelectionList(model);
                    }
                    else
                    {
                        foreach (String thisAnswer in ThisUsersAnswers)
                        {
                            String[] theseProperties = thisAnswer.Split(new char[1] { '_' });
                            if (!(theseProperties.Length < 2))
                            {
                                AnswerApp.Models.SelectModel thisModel = new AnswerApp.Models.SelectModel();
                                thisModel.Textbook = theseProperties[0];
                                thisModel.Unit = theseProperties[1];
                                thisModel.Chapter = theseProperties[2];
                                thisModel.Section = theseProperties[3];
                                thisModel.Page = theseProperties[4];
                                thisModel.Question = theseProperties[5].Split(new char[1] { '.' })[0];//Truncate ".pdf" from the end of the file name
                                if (thisModel.Page.Equals(model.Page)) { SelectionList += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a style=\"color: #FF0000\" href=\"Answers/ViewAnswer/" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">Page " + thePage.Page_Number + "</a><br />" + GenerateSelectionList(model); break; }
                            }
                            else { SelectionList += GenerateSelectionList(model); }
                        }
                    }
                    model.Page = "All";
                }
            }
            else if (model.Question.Equals("All"))//Only one unit has been specified
            {
                IQueryable<AnswerApp.Models.Question> retrieved = from theAnswers in db.Questions
                                                                  where theAnswers.Textbook_Title.Equals(model.Textbook)
                                                                  && theAnswers.Unit_Title.Equals(model.Unit)
                                                                  && theAnswers.Chapter_Title.Equals(model.Chapter)
                                                                  && theAnswers.Section_Title.Equals(model.Section)
                                                                  && theAnswers.Page_Number.Equals(model.Page)
                                                                  select theAnswers;
                AnswerApp.Models.Question[] results = retrieved.ToArray<AnswerApp.Models.Question>();
                foreach (Question theQuestion in results)
                {
                    model.Question = theQuestion.Question_Number;
                    if(UserHasAccess(User.Identity.Name, model.Textbook + "_" + model.Unit + "_" + model.Chapter + "_" + model.Section + "_" + model.Page + "_" + model.Question + ".pdf"))
                    {
                        SelectionList += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"Answers/ViewAnswer/" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">Question " + theQuestion.Question_Number + "</a><br />" + GenerateSelectionList(model);
                    }
                    else
                    {
                        foreach (String thisAnswer in ThisUsersAnswers)
                        {
                            String[] theseProperties = thisAnswer.Split(new char[1] { '_' });
                            if (!(theseProperties.Length < 2))
                            {
                                AnswerApp.Models.SelectModel thisModel = new AnswerApp.Models.SelectModel();
                                thisModel.Textbook = theseProperties[0];
                                thisModel.Unit = theseProperties[1];
                                thisModel.Chapter = theseProperties[2];
                                thisModel.Section = theseProperties[3];
                                thisModel.Page = theseProperties[4];
                                thisModel.Question = theseProperties[5].Split(new char[1] { '.' })[0];//Truncate ".pdf" from the end of the file name
                                if (thisModel.Question.Equals(model.Question)) { SelectionList += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a style=\"color: #FF0000\" href=\"Answers/ViewAnswer/" + User.Identity.Name + "?Textbook=" + model.Textbook + "&Unit=" + model.Unit + "&Chapter=" + model.Chapter + "&Section=" + model.Section + "&Page=" + model.Page + "&Question=" + model.Question + "\">Question " + theQuestion.Question_Number + "</a><br />" + GenerateSelectionList(model); break; }
                            }
                            else { SelectionList += GenerateSelectionList(model); }
                        }
                    }
                    model.Question = "All";
                }
            }

            return SelectionList;
        }
Exemplo n.º 16
0
 public bool Contains(SelectModel Containee)
 {
     if(this.Textbook.Equals("All"))
     {
         return true;
     }
     else if (this.Textbook.Equals(Containee.Textbook))
     {
         if (this.Unit.Equals("All"))
         {
             return true;
         }
         else if(this.Unit.Equals(Containee.Unit))
         {
             if (this.Chapter.Equals("All"))
             {
                 return true;
             }
             else if(this.Chapter.Equals(Containee.Chapter))
             {
                 if (this.Section.Equals("All"))
                 {
                     return true;
                 }
                 else if(this.Section.Equals(Containee.Section))
                 {
                     if (this.Page.Equals("All"))
                     {
                         return true;
                     }
                     else if(this.Page.Equals(Containee.Page))
                     {
                         if (this.Question.Equals("All"))
                         {
                             return true;
                         }
                         else if (this.Question.Equals(Containee.Question))
                         {
                             return true;
                         }
                         else
                         {
                             return false;
                         }
                     }
                     else
                     {
                         return false;
                     }
                 }
                 else
                 {
                     return false;
                 }
             }
             else
             {
                 return false;
             }
         }
         else
         {
             return false;
         }
     }
     else
     {
         return false;
     }
 }
Exemplo n.º 17
0
        public bool Contains(String ContaineeString)
        {
            ContaineeString = ContaineeString.Replace(".pdf", "");
            String[] Properties = ContaineeString.Split(new char[1] { '_' });
            SelectModel Containee = new AnswerApp.Models.SelectModel();
            if (Properties.Length > 0) { Containee.Textbook = Properties[0]; } else { return false; }
            if (Properties.Length > 1) { Containee.Unit = Properties[1]; } else { return false; }
            if (Properties.Length > 2) { Containee.Chapter = Properties[2]; } else { return false; }
            if (Properties.Length > 3) { Containee.Section = Properties[3]; } else { return false; }
            if (Properties.Length > 4) { Containee.Page = Properties[4]; } else { return false; }
            if (Properties.Length > 5) { Containee.Question = Properties[5]; } else { return false; }

            return this.Contains(Containee);
        }
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
        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");
        }
Exemplo n.º 20
0
        //
        // GET: /Answers/
        public ActionResult Select(string argument, SelectModel model)
        {
            AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext();
            model.Textbook = argument;
            List<string> TextbookList = new List<string>();
            TextbookList.Add(model.Textbook);

            //Populate List of Units
            List<string> UnitList = new List<string>();
            List<AnswerApp.Models.Unit> All_Units = new List<AnswerApp.Models.Unit>();
            All_Units = db.Units.ToList();
            foreach (Unit theUnit in All_Units)
            {
                if (theUnit.Textbook_Title == model.Textbook)
                {
                    UnitList.Add(theUnit.Unit_Title);
                }
            }

            //Populate List of Chapters
            List<string> ChapterList = new List<string>();
            List<AnswerApp.Models.Chapter> All_Chapters = new List<AnswerApp.Models.Chapter>();
            All_Chapters = db.Chapters.ToList();
            foreach (Chapter theChapter in All_Chapters)
            {
                if (theChapter.Textbook_Title == model.Textbook)
                {
                    ChapterList.Add(theChapter.Chapter_Title);
                }
            }

            //Populate List of Sections
            List<string> SectionList = new List<string>();
            List<AnswerApp.Models.Section> All_Sections = new List<AnswerApp.Models.Section>();
            All_Sections = db.Sections.ToList();
            foreach (Section theSection in All_Sections)
            {
                if (theSection.Textbook_Title == model.Textbook)
                {
                    SectionList.Add(theSection.Section_Title);
                }
            }

            //Populate List of Pages
            List<string> PageList = new List<string>();
            List<AnswerApp.Models.Page> All_Pages = new List<AnswerApp.Models.Page>();
            All_Pages = db.Pages.ToList();
            foreach (Page thePage in All_Pages)
            {
                if (thePage.Textbook_Title == model.Textbook)
                {
                    PageList.Add(thePage.Page_Number);
                }
            }

            //Populate List of Questions
            List<string> QuestionList = new List<string>();
            List<AnswerApp.Models.Question> All_Questions = new List<AnswerApp.Models.Question>();
            All_Questions = db.Questions.ToList();
            foreach (Question thequestion in All_Questions)
            {
                if (thequestion.Question_Number != null)//This filters out test data
                {
                    QuestionList.Add(thequestion.Question_Number);
                }
            }

            ViewBag.TextbookDropDownList = new SelectList(TextbookList);
            ViewBag.UnitDropDownList = new SelectList(UnitList);
            ViewBag.ChapterDropDownList = new SelectList(ChapterList);
            ViewBag.SectionDropDownList = new SelectList(SectionList);
            ViewBag.PageDropDownList = new SelectList(PageList);
            ViewBag.QuestionDropDownList = new SelectList(QuestionList);

            return View(model);
        }
Exemplo n.º 21
0
        //Determines whether a user has access to a given grouping of solutions
        public Boolean UserHasAccess(User theUser, String FileName, AnswerAppDataContext db)
        {
            Boolean UserHasAccess = false;

            //Disect the file name for it's file properties
            String[] properties = FileName.Split(new char[1] { '_' });
            AnswerApp.Models.SelectModel model = new AnswerApp.Models.SelectModel();
            model.Textbook = properties[0];
            model.Unit = properties[1];
            model.Chapter = properties[2];
            model.Section = properties[3];
            model.Page = properties[4];
            model.Question = properties[5].Split(new char[1] { '.' })[0];//Truncate ".pdf" from the end of the file name

            if (theUser.Answers == null) { return false; }

            String[] UserAnswers = theUser.Answers.Split(new char[2] { ',', ';' });
            if (UserAnswers.Length < 2) { return false; }
            foreach (String thisAnswer in UserAnswers)
            {
                if (thisAnswer.Equals(FileName) || thisAnswer.Equals(FileName + ".pdf")) { return true; }//They have purchased this exact selection previously
                String[] theseProperties = thisAnswer.Split(new char[1] { '_' });
                if (theseProperties.Length < 2) { return false; }
                AnswerApp.Models.SelectModel thisModel = new AnswerApp.Models.SelectModel();
                thisModel.Textbook = theseProperties[0];
                thisModel.Unit = theseProperties[1];
                thisModel.Chapter = theseProperties[2];
                thisModel.Section = theseProperties[3];
                thisModel.Page = theseProperties[4];
                thisModel.Question = theseProperties[5].Split(new char[1] { '.' })[0];//Truncate ".pdf" from the end of the file name

                if (thisModel.Unit.Equals("All") && thisModel.Textbook.Equals(model.Textbook))
                {
                    return true;
                }
                else if (thisModel.Chapter.Equals("All") && thisModel.Unit.Equals(model.Unit) && !thisModel.Unit.Equals("All"))
                {
                    return true;
                }
                else if (thisModel.Section.Equals("All") && thisModel.Chapter.Equals(model.Chapter) && !thisModel.Chapter.Equals("All"))
                {
                    return true;
                }
                else if (thisModel.Page.Equals("All") && thisModel.Section.Equals(model.Section) && !thisModel.Section.Equals("All"))
                {
                    return true;
                }
                else if (thisModel.Question.Equals("All") && thisModel.Page.Equals(model.Page) && !thisModel.Page.Equals("All"))
                {
                    return true;
                }

            }
            return UserHasAccess;
        }
Exemplo n.º 22
0
 public ActionResult Select(SelectModel model, string returnUrl)
 {
     return RedirectToAction("ViewAnswer/" + User.Identity.Name, "Answers", model);
 }
Exemplo n.º 23
0
        public ActionResult ViewAnswer(string argument, SelectModel model, string returnUrl)
        {
            ViewData["RenderAnswer"] = "true";//The answer will be rendered since this is a post back
            ViewData["PracticeProblemAnswer"] = model.PracticeProblemAnswer;//populate the correct answer

            ViewData["FileNameExtensionless"] = "" + model.Textbook +
                                                    "_" + model.Unit +
                                                    "_" + model.Chapter +
                                                    "_" + model.Section +
                                                    "_" + model.Page +
                                                    "_" + model.Question;
            ViewData["FileName"] = "" + ViewData["FileNameExtensionless"] + ".pdf";
            ViewData["PracticeProblemFileName"] = "" + ViewData["FileNameExtensionless"] + "_Practice Problem.png";

            ViewData["CorrectAnswer"]= null;
            ViewData["HasPracticeProblem"] = "false";

            //Retrieve the practice problem answer
            AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext();
            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;
                ViewData["HasPracticeProblem"] = "true";
            }
            ViewData["SelectionList"] = GenerateSelectionList(model);
            return View("ViewAnswer", model);
        }
Exemplo n.º 24
0
        public ActionResult ViewAnswer(string argument, SelectModel model)
        {
            ViewData["RenderAnswer"] = "false";//don't render practice answer before the user has answered it

            ViewData["FileNameExtensionless"] = "" + model.Textbook +
                                                    "_" + model.Unit +
                                                    "_" + model.Chapter +
                                                    "_" + model.Section +
                                                    "_" + model.Page +
                                                    "_" + model.Question;
            ViewData["FileName"] = "" + ViewData["FileNameExtensionless"] + ".pdf";
            ViewData["PracticeProblemFileName"] = "" + ViewData["FileNameExtensionless"] + "_Practice Problem.png";

            AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext();
            AnswerApp.Models.User theUser = new AnswerApp.Models.User();
            theUser = db.Users.Single(u => u.UserName.Equals(User.Identity.Name));
            if (theUser != null)
            {
                if (theUser.Answers != null)
                {
                    string[] UserAnswers = new string[100];
                    UserAnswers = theUser.Answers.Split(new char[2] { ',', ';' });

                    for (int i = 0; i < UserAnswers.Length; i++)
                    {
                        if (UserAnswers[i].Equals(ViewData["FileName"]))
                        {
                            return View("ViewAnswer", model);
                        }
                    }
                }
            }
            return RedirectToAction("Pay", "Answers", model);
        }
Exemplo n.º 25
0
        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;
        }
Exemplo n.º 26
0
 public ActionResult Pay(SelectModel model)
 {
     return View(model);
 }
Exemplo n.º 27
0
 public int NumberOfQuestions(SelectModel model, AnswerAppDataContext db)
 {
     if ((model.Question == null) || (model.Page == null) || (model.Section == null) || (model.Chapter == null) || (model.Unit == null) || (model.Textbook == null))
     {
         return 0;
     }
     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>();
                             return results.Length;
                         }
                         else
                         {
                             IQueryable<Question> retrieved = from theAnswers in db.Questions
                                                              where theAnswers.Textbook_Title.Equals(model.Textbook)
                                                              select theAnswers;
                             Question[] results = retrieved.ToArray<Question>();
                             return results.Length;
                         }
                     }
                     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>();
                         return results.Length;
                     }
                 }
                 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>();
                     return results.Length;
                 }
             }
             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>();
                 return results.Length;
             }
         }
         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>();
             return results.Length;
         }
     }
     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>();
         return results.Length;
     }
 }
Exemplo n.º 28
0
        public PriceBreakdown(SelectModel model, User thisUser, AnswerAppDataContext db)
        {
            this.Credit = thisUser.Credit;
            AnswerApp.Controllers.AnswersController theAnswerController = new AnswerApp.Controllers.AnswersController();
            this.NumberOfSolutionsToPurchase = theAnswerController.NumberOfQuestions(model, db);
            //ViewData["NumberOfSolutionsToPurchase"] = this.NumberOfSolutionsToPurchase;
            //ViewData["TotalValue"] = (this.NumberOfSolutionsToPurchase * PriceOfSingleSolution).ToString("C");

            //this.NumberOfSolutionsForThisUser = 0;
            //this.NumberSelectedUserAlreadyHas = 0;
            String[] UserAnswers;
            if (thisUser.Answers != null)
            {
                UserAnswers = thisUser.Answers.Split(new char[1] { ';' });
                foreach (String theAnswer in UserAnswers)
                {
                    SelectModel theModel = new SelectModel(theAnswer);
                    int NumberOfSolutions = theAnswerController.NumberOfQuestions(theModel, db);
                    this.NumberOfSolutionsForThisUser += NumberOfSolutions;
                    if (model.Contains(theModel))
                    {
                        this.NumberSelectedUserAlreadyHas += NumberOfSolutions;
                    }
                }
            }
            //ViewData["NumberOfSolutionsForThisUser"] = this.NumberOfSolutionsForThisUser;
            //ViewData["NumberSelectedUserAlreadyHas"] = this.NumberSelectedUserAlreadyHas;
            this.SolutionsRemainingToBePurchased = (this.NumberOfSolutionsToPurchase - this.NumberSelectedUserAlreadyHas);
            //ViewData["SolutionsRemainingToBePurchased"] = this.SolutionsRemainingToBePurchased;
            this.RemainingCost = (this.NumberOfSolutionsToPurchase - this.NumberSelectedUserAlreadyHas) * PriceOfSingleSolution;
            //ViewData["RemainingCost"] = this.RemainingCost.ToString("C");
            //ViewData["UserCredit"] = thisUser.Credit;
            this.TotalRemainingSolutions = this.SolutionsRemainingToBePurchased - thisUser.Credit;
            //ViewData["TotalRemainingSolutions"] = this.TotalRemainingSolutions;
            this.TotalRemainingPrice = this.TotalRemainingSolutions * PriceOfSingleSolution;
            //ViewData["TotalRemainingCost"] = this.TotalRemainingPrice.ToString("C");
            this.UserLevel = this.NumberOfSolutionsForThisUser + thisUser.Credit;
            //ViewData["UserLevel"] = this.UserLevel;

            //int AdditionalCredits = 0;//To be determined below
            this.UpgradePrice = this.TotalRemainingPrice;//To be determined below
            this.UpgradePriceDifference = this.TotalRemainingPrice;//To be determined below

            //if the cost of an upgrade is less than the cost of all the solutions then the user gets the upgrade
            this.TargetNumberOfSolutionsAfterPurchase = this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased;
            if (this.TargetNumberOfSolutionsAfterPurchase > 1000)//they want 1000+ pack
            {

            }
            else if ((this.TargetNumberOfSolutionsAfterPurchase > 250))//want 1000 pack
            {
                if (this.UserLevel >= 250)//250 < UserLevel < 1000
                {
                    this.UpgradePriceDifference = PriceOf1000Pack - PriceOf250Pack;
                    if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade
                    { this.UpgradePrice = this.UpgradePriceDifference; }
                    else
                    { this.UpgradePrice = (1000 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; }
                    this.AdditionalCredits = 1000 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased);
                }
                else if (this.UserLevel >= 100)//100 < UserLevel < 250
                {
                    this.UpgradePriceDifference = PriceOf1000Pack - PriceOf100Pack;
                    if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade
                    { this.UpgradePrice = this.UpgradePriceDifference; }
                    else
                    { this.UpgradePrice = (1000 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; }
                    this.AdditionalCredits = 1000 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased);
                }
                else if (this.UserLevel >= 50)//50 < UserLevel < 100
                {
                    this.UpgradePriceDifference = PriceOf1000Pack - PriceOf50Pack;
                    if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade
                    { this.UpgradePrice = this.UpgradePriceDifference; }
                    else
                    { this.UpgradePrice = (1000 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; }
                    this.AdditionalCredits = 1000 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased);
                }
                else if (this.UserLevel >= 10)//10 < UserLevel < 20
                {
                    this.UpgradePriceDifference = PriceOf1000Pack - PriceOf10Pack;
                    if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade
                    { this.UpgradePrice = this.UpgradePriceDifference; }
                    else
                    { this.UpgradePrice = (1000 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; }
                    this.AdditionalCredits = 1000 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased);
                }
                else//if (UserLevel < 10)//0 < UserLevel < 10
                {
                    this.UpgradePriceDifference = PriceOf1000Pack - ((this.NumberOfSolutionsForThisUser + thisUser.Credit) * PriceOfSingleSolution);
                    if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade
                    { this.UpgradePrice = this.UpgradePriceDifference; }
                    else
                    { this.UpgradePrice = (1000 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; }
                    this.AdditionalCredits = 1000 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased);
                }
            }
            else if ((this.TargetNumberOfSolutionsAfterPurchase > 100))//want 250 pack
            {
                if (this.UserLevel >= 100)//100 < UserLevel < 250
                {
                    this.UpgradePriceDifference = PriceOf250Pack - PriceOf100Pack;
                    if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade
                    { this.UpgradePrice = this.UpgradePriceDifference; }
                    else
                    { this.UpgradePrice = (250 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; }
                    this.AdditionalCredits = 250 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased);
                }
                else if (this.UserLevel >= 50)//50 < UserLevel < 100
                {
                    this.UpgradePriceDifference = PriceOf250Pack - PriceOf50Pack;
                    if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade
                    { this.UpgradePrice = this.UpgradePriceDifference; }
                    else
                    { this.UpgradePrice = (250 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; }
                    this.AdditionalCredits = 250 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased);
                }
                else if (this.UserLevel >= 10)//10 < UserLevel < 20
                {
                    this.UpgradePriceDifference = PriceOf50Pack - PriceOf10Pack;
                    if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade
                    { this.UpgradePrice = this.UpgradePriceDifference; }
                    else
                    { this.UpgradePrice = (250 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; }
                    this.AdditionalCredits = 250 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased);
                }
                else//if (UserLevel < 10)//0 < UserLevel < 10
                {
                    this.UpgradePriceDifference = PriceOf250Pack - ((this.NumberOfSolutionsForThisUser + thisUser.Credit) * PriceOfSingleSolution);
                    if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade
                    { this.UpgradePrice = this.UpgradePriceDifference; }
                    else
                    { this.UpgradePrice = (250 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; }
                    this.AdditionalCredits = 250 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased);
                }
            }
            else if ((this.TargetNumberOfSolutionsAfterPurchase > 50))//want 100 pack
            {
                if (this.UserLevel >= 50)//50 < UserLevel < 100
                {
                    this.UpgradePriceDifference = PriceOf100Pack - PriceOf50Pack;
                    if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade
                    { this.UpgradePrice = this.UpgradePriceDifference; }
                    else
                    { this.UpgradePrice = (100 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; }
                    this.AdditionalCredits = 100 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased);
                }
                else if (this.UserLevel >= 10)//10 < UserLevel < 20
                {
                    this.UpgradePriceDifference = PriceOf100Pack - PriceOf10Pack;
                    if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade
                    { this.UpgradePrice = this.UpgradePriceDifference; }
                    else
                    { this.UpgradePrice = (100 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; }
                    this.AdditionalCredits = 100 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased);
                }
                else//if (UserLevel < 10)//0 < UserLevel < 10
                {
                    this.UpgradePriceDifference = PriceOf100Pack - ((this.NumberOfSolutionsForThisUser + thisUser.Credit) * PriceOfSingleSolution);
                    if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade
                    { this.UpgradePrice = this.UpgradePriceDifference; }
                    else
                    { this.UpgradePrice = (100 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; }
                    this.AdditionalCredits = 100 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased);
                }
            }
            else if ((this.TargetNumberOfSolutionsAfterPurchase > 10))//want 50 pack
            {
                if (this.UserLevel >= 10)//10 < UserLevel < 50
                {
                    this.UpgradePriceDifference = PriceOf50Pack - PriceOf10Pack;
                    if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade
                    { this.UpgradePrice = this.UpgradePriceDifference; }
                    else
                    { this.UpgradePrice = (50 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; }
                    this.AdditionalCredits = 50 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased);
                }
                else//if (UserLevel <= 10)//0 < UserLevel < 10
                {
                    this.UpgradePriceDifference = PriceOf50Pack - ((this.NumberOfSolutionsForThisUser + thisUser.Credit) * PriceOfSingleSolution);
                    if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade
                    { this.UpgradePrice = this.UpgradePriceDifference; }
                    else
                    { this.UpgradePrice = (50 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; }
                    this.AdditionalCredits = 50 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased);
                }
            }
            else//if ((TargetNumberOfSolutionsAfterPurchase <= 10))
            {
                this.UpgradePriceDifference = PriceOf10Pack - ((this.NumberOfSolutionsForThisUser + thisUser.Credit) * PriceOfSingleSolution);
                if (this.TotalRemainingPrice > this.UpgradePriceDifference)//if the cost of the solutions is greater than the cost of the upgrade
                { this.UpgradePrice = this.UpgradePriceDifference; }
                else
                { this.UpgradePrice = (10 - (this.NumberOfSolutionsForThisUser + thisUser.Credit)) * PriceOfSingleSolution; }
                this.AdditionalCredits = 10 - (this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased);
            }
            if (this.UpgradePrice > this.UpgradePriceDifference) { this.UpgradePrice = this.UpgradePriceDifference; }
            this.UserLevelAfterPurchase = this.NumberOfSolutionsForThisUser + this.SolutionsRemainingToBePurchased + this.AdditionalCredits;
            this.UpgradeSavings = this.TotalRemainingPrice - this.UpgradePrice;
            if (this.UpgradeSavings > 0)
            {
                this.ShowUpgradeSavings = "true";
            }
            else
            {
                this.ShowUpgradeSavings = "false";
            }
            //if(this.UpgradePrice < UpgradePriceDifference)
            if (this.UpgradePrice < this.TotalRemainingPrice)
            {
                this.DisplayIndividualPurchasePrice = "false";
            }
            else
            {
                this.DisplayIndividualPurchasePrice = "true";
            }

            if(UserLevel < 10)
            {CurrentLevel = "Novice";}
            else if(UserLevel < 50)
            {CurrentLevel = "Apprentice";}
            else if(UserLevel < 100)
            {CurrentLevel = "Journeyman";}
            else if(UserLevel < 250)
            {CurrentLevel = "Adept";}
            else if(UserLevel < 1000)
            {CurrentLevel = "Expert";}
            else//if(UserLevel > 1000)
            {CurrentLevel = "Master";}

            if (UserLevelAfterPurchase <= 10)
            { UpgradeLevel = "Apprentice"; }
            else if (UserLevelAfterPurchase <= 50)
            { UpgradeLevel = "Journeyman"; }
            else if (UserLevelAfterPurchase <= 100)
            { UpgradeLevel = "Adept"; }
            else if (UserLevelAfterPurchase <= 250)
            { UpgradeLevel = "Expert"; }
            else if (UserLevelAfterPurchase <= 1000)
            { UpgradeLevel = "Master"; }
            else//if(UserLevel > 1000)
            {UpgradeLevel = "Doctor of Philosophy"; }
        }
Exemplo n.º 29
0
        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);
        }
Exemplo n.º 30
0
 public PriceBreakdown Price(SelectModel model, User thisUser, AnswerAppDataContext db)
 {
     return new PriceBreakdown(model, thisUser, db);
 }