コード例 #1
0
        public CascadingDropDownNameValue[] GetPages(string knownCategoryValues, string category)
        {
            AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext();

            StringDictionary knownCatagories = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
            DictionaryEntry[] CatagoryArray = new DictionaryEntry[knownCatagories.Count];
            knownCatagories.CopyTo(CatagoryArray, 0);
            String SelectedSection = "Error 1";
            foreach (DictionaryEntry theEntry in CatagoryArray)
            {
                if (theEntry.Key.ToString().Equals("section"))
                {
                    SelectedSection = theEntry.Value.ToString();
                }
            }

            IQueryable<AnswerApp.Models.Page> retrieved = from theAnswers in db.Pages
                                                              where theAnswers.Section_Title.Equals(SelectedSection)//Textbook_Title)
                                                              select theAnswers;
            AnswerApp.Models.Page[] results = retrieved.ToArray<AnswerApp.Models.Page>();
            List<CascadingDropDownNameValue> theList = new List<CascadingDropDownNameValue>();
            foreach (AnswerApp.Models.Page thePage in results)
            {
                theList.Add(new CascadingDropDownNameValue(thePage.Page_Number, thePage.Page_Number));
            }
            return theList.ToArray();
        }
コード例 #2
0
        public ActionResult GetPdf(String argument)
        {
            String[] arguments = new String[7];
            arguments = argument.Split(new char[1] { '_' });
            String user = arguments[0];
            String Textbook_Title = arguments[1];
            String Unit_Title = arguments[2];
            String Chapter_Title = arguments[3];
            String Section_Title = arguments[4];
            String Page_Number = arguments[5];
            String Question_Number = arguments[6].Split(new char[1] { '.' })[0];//Truncate ".pdf" from the end of the file name

            if (!User.Identity.Name.Equals(user)) { return RedirectToAction("LogOn", "Account"); }

            String filename = argument;//The name of the file will be prefixed by the username of the person retrieving it

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

            AnswerApp.Models.Question theQuestion = new AnswerApp.Models.Question();

            IQueryable<Question> retrieved = from theAnswers in db.Questions
                                 where theAnswers.Textbook_Title.Equals(Textbook_Title)
                                 && theAnswers.Unit_Title.Equals(Unit_Title)
                                 && theAnswers.Chapter_Title.Equals(Chapter_Title)
                                 && theAnswers.Section_Title.Equals(Section_Title)
                                 && theAnswers.Page_Number.Equals(Page_Number)
                                 && theAnswers.Question_Number.Equals(Question_Number)
                                 select theAnswers;
            Question[] results = retrieved.ToArray<Question>();
            if (results.Length == 0) { return RedirectToAction("ResourceUnavailable", "Home"); }
            theQuestion = results.First();// Single<Question>(q => q.Question_Number.Equals(Question_Number));
            byte[] pdfBytes = theQuestion.Answer.ToArray();
            return new PdfResult(pdfBytes, false, filename);
        }
コード例 #3
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (ModelState.IsValid)
            {

                // ChangePassword will throw an exception rather
                // than return false in certain failure scenarios.
                bool changePasswordSucceeded;
                try
                {
                    MembershipUser currentUser = Membership.GetUser(User.Identity.Name, true /* userIsOnline */);
                    changePasswordSucceeded = currentUser.ChangePassword(model.OldPassword, model.NewPassword);
                }
                catch (Exception)
                {
                    changePasswordSucceeded = false;
                }

                if (changePasswordSucceeded)
                {
                    AnswerAppDataContext db = new AnswerAppDataContext();
                    User theUser = db.Users.Single(u => u.UserName.Equals(User.Identity.Name));
                    theUser.Password = model.NewPassword;
                    db.SubmitChanges();
                    return RedirectToAction("ChangePasswordSuccess");
                }
                else
                {
                    ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
コード例 #4
0
        //
        // GET: /Account/ConfirmRegistration
        public ActionResult ConfirmRegistration(string SecretCode)
        {
            //String[] ParsedCode = SecretCode.Split(new char[1] { '_' });
            //String UserName = ParsedCode[0];
            //SecretCode = SecretCode.Replace(UserName + "_", "");
            AnswerAppDataContext db = new AnswerAppDataContext();
            User theNewUser = db.Users.Single<User>(u => u.MetaData.Contains(SecretCode));

            //RegisterModel model = new RegisterModel();
            //model.UserName = theNewUser.UserName;
            //model.Email = theNewUser.Email;
            //model.Password = theNewUser.Password;

            MembershipCreateStatus createStatus;
            Membership.CreateUser(theNewUser.UserName, theNewUser.Password, theNewUser.Email, theNewUser.PasswordQuestion, theNewUser.PasswordAnswer, true, null, out createStatus);

            if (createStatus == MembershipCreateStatus.Success)
            {
                FormsAuthentication.SetAuthCookie(theNewUser.UserName, false);// createPersistentCookie
                MailAddress fromAddress = new MailAddress("*****@*****.**");
                MailAddress toAddress = new MailAddress(theNewUser.Email);
                SendEmail(fromAddress, toAddress, "Salutations!", "Hello " + theNewUser.UserName + " and welcome to Solvation.ca");
                return RedirectToAction("Index", "Home");
            }
            else
            {
                ModelState.AddModelError("", ErrorCodeToString(createStatus));
                return RedirectToAction("Register", "Account");
            }
        }
コード例 #5
0
ファイル: HomeController.cs プロジェクト: aarotech/AnswerApp
        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();
            }
        }
コード例 #6
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");
        }
コード例 #7
0
        public CascadingDropDownNameValue[] GetChapters(string knownCategoryValues, string category)
        {
            AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext();

            StringDictionary knownCatagories = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
            DictionaryEntry[] CatagoryArray = new DictionaryEntry[knownCatagories.Count];
            knownCatagories.CopyTo(CatagoryArray, 0);

            IQueryable<AnswerApp.Models.Chapter> retrieved = null;
            foreach (DictionaryEntry theEntry in CatagoryArray)
            {
                if (theEntry.Key.ToString().Equals("textbook"))
                {
                    String SelectedTextbook = theEntry.Value.ToString();
                    retrieved = from theAnswers in db.Chapters
                                where theAnswers.Textbook_Title.Equals(SelectedTextbook)
                                select theAnswers;
                }
            }
            foreach (DictionaryEntry theEntry in CatagoryArray)
            {
                if (theEntry.Key.ToString().Equals("unit"))
                {
                    String SelectedUnit = theEntry.Value.ToString();
                    if(SelectedUnit.Equals("All"))
                    {
                        retrieved = from theAnswers in db.Chapters
                                    select theAnswers;
                    }
                    else
                    {
                        retrieved = from theAnswers in db.Chapters
                                    where theAnswers.Unit_Title.Equals(SelectedUnit)
                                    select theAnswers;
                    }
                }
            }

            AnswerApp.Models.Chapter[] results = retrieved.ToArray<AnswerApp.Models.Chapter>();
            List<CascadingDropDownNameValue> theList = new List<CascadingDropDownNameValue>();
            theList.Add(new CascadingDropDownNameValue("All", "All"));
            foreach (AnswerApp.Models.Chapter theChapter in results)
            {
                theList.Add(new CascadingDropDownNameValue(theChapter.Chapter_Title, theChapter.Chapter_Title));
            }
            return theList.ToArray();
        }
コード例 #8
0
ファイル: HomeController.cs プロジェクト: HoldFast/AnswerApp
        public ActionResult DisplayUsers(HomeModel model)
        {
            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.UserName;
                }
            }
            return View(model);
        }
コード例 #9
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);
        }
コード例 #10
0
        //
        // GET: /Account/LogOn
        public ActionResult LogOn()
        {
            //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.UserName + "," + theUser.Password + "," + theUser.MetaData + "]";
                }
            }
            //TESTING AND OR DEBUGGING PURPOSES ONLY*/
            return View();
        }
コード例 #11
0
ファイル: HomeController.cs プロジェクト: HoldFast/AnswerApp
        public ActionResult Index(HomeModel model)
        {
            if (Request.IsAuthenticated)
            {
                ViewBag.Message = "The Answer App";
                //String Username = User.Identity.Name;
                ViewBag.Username = User.Identity.Name;//Username;

                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
                else
                {
                    //Calculate the percentages of each textbook the user has purchased
                    /*List<String> UserTextbooks = new List<String>(); ;
                    List<String> UserAnswers = thisUser.Answers.Split(new char[1] { ';' }).ToList();
                    foreach (String theAnswer in UserAnswers)
                    {
                        String[] AnswerProperties = theAnswer.Split(new char[1] { '_' });//AnswerProperties[0] is theTextbook
                        if (!UserTextbooks.Contains(AnswerProperties[0]))
                        {
                            UserTextbooks.Add(AnswerProperties[0]);//If it is not already in the list of textbooks add it
                            String[] AnswerPercentage = theAnswer.Split(new char[1] { ',' });
                            Textbook thisTextbook = new Textbook();
                            thisTextbook.TextbookTitle = AnswerProperties[0];
                            thisTextbook.TextbookPercentage = AnswerPercentage[1];
                            model.UserTextbooks.Add(thisTextbook);
                        }

                    }//*/
                }

                return View(model);
            }
            else
            {
                return RedirectToAction("LogOn", "Account"); //return View();
            }
        }
コード例 #12
0
        //This method adds entry information
        //and also file contents to the database
        //whenever new Questions are added using
        //the bulk uploader
        String AddFromZip(byte[] data, String FileName)
        {
            AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext();

            if (FileName == null) { return "Error: Archive file name is null."; }
            if (FileName.Equals("")) { return "Error: No file name."; }
            if (FileName.Length < 2) { return "Error: Archive file name too short."; }

            String _Info = "";
            //Page.ClientScript.RegisterStartupScript(GetType(), "UserDialogScript", "alert(\"User successfully updated\");", true);

            //Disect the file name for it's file properties
            FileName = FileName.Replace(".pdf", "");//Remove file extension
            String[] ParsedFileName = FileName.Split(new char[1] { '/' });//separate file and path text
            String PathlessFileName = ParsedFileName.Last<String>();//The last string will be the file name
            if (PathlessFileName.Length < 1) { return "Error: The directory tree is empty.  "; }
            String Path = FileName.Replace(PathlessFileName, "");//Everything but the file name is the path(test)

            String Textbook_Title = null;
            String Unit_Title = null;
            String Chapter_Title = null;
            String Section_Title = null;
            String Page_Number = null;
            String Question_Number = null;
            String Practice_Problem_Answer = null;

            String[] PathlessFileNameParsed = PathlessFileName.Split(new char[2] { '_', ' ' });
            if (PathlessFileNameParsed.Length == 3)//This is a practice problem
            {
                _Info += "Practice Problem";
                if (PathlessFileName.Contains("p") || PathlessFileName.Contains("q"))//If the file name contains p or q
                {
                    Boolean Page = false, Question = false, Answer = false;
                    foreach (String theElement in PathlessFileNameParsed)
                    {
                        if (theElement.Contains("p"))//this must be a page number
                        {
                            Page_Number = theElement.Replace("p", "").Replace("g", "");
                            Page = true;
                        }
                        else if (theElement.Contains("q"))//this must be a question number
                        {
                            Question_Number = theElement.Replace("q", "");
                            Question = true;
                        }
                        else
                        {
                            Practice_Problem_Answer = theElement;
                            //_Info += "[" + Practice_Problem_Answer + "]";
                            Answer = true;
                        }
                    }
                    if ((Page == false) || (Question == false) || (Answer == false))
                    {
                        _Info += "Error: File naming convention not followed \"" + PathlessFileName + "\".  The parser could not understand the file name of the practice problem because it is ambiguous.  skipping...";
                    }
                }
                else//No symbols were added thus the order of the numbers in the file name determines their meaning
                {
                    if (PathlessFileNameParsed.Length > 0) { Page_Number = PathlessFileNameParsed[0]; }
                    if (PathlessFileNameParsed.Length > 1) { Question_Number = PathlessFileNameParsed[1]; }
                    if (PathlessFileNameParsed.Length > 2) { Practice_Problem_Answer = PathlessFileNameParsed[2]; }
                }
            }
            else if (PathlessFileNameParsed.Length == 2)//This is a solution
            {
                _Info += "Solution ";
                if (PathlessFileName.Contains("p") || PathlessFileName.Contains("q"))//If the file name contains p or q
                {
                    Boolean Page = false, Question = false;
                    foreach (String theElement in PathlessFileNameParsed)//use the p and q to denote page and question
                    {
                        if (theElement.Contains("p"))//this must be a page number
                        {
                            Page_Number = theElement.Replace("p", "").Replace("g", "");
                            Page = true;
                        }
                        else if (theElement.Contains("q"))//this must be a question number
                        {
                            Question_Number = theElement.Replace("q", "");
                            Question = true;
                        }
                        else
                        {
                            _Info += "Error: File naming convention not followed \"" + PathlessFileName + "\".  Missing one or more 'p' and or 'q' disambiguation parameters.  skipping...";
                        }
                    }
                    if ((Page == false) || (Question == false))
                    {
                        _Info += "Error: File naming convention not followed \"" + PathlessFileName + "\".  The parser could not understand the file name of the solution because it is ambiguous.  skipping...";
                    }
                }
                else//No symbols were added thus the order of the numbers in the file name determines their meaning
                {
                    if (PathlessFileNameParsed.Length > 0) { Page_Number = PathlessFileNameParsed[0]; }
                    if (PathlessFileNameParsed.Length > 1) { Question_Number = PathlessFileNameParsed[1]; }
                }
            }
            else//(PathlessFileNameParsed.Length < 2) || (PathlessFileNameParsed.Length > 3)
            {
                _Info += "Error: File naming convention not followed \"" + PathlessFileName + "\".  " + PathlessFileNameParsed.Length + "is not the right number of elements.  skipping...";
            }

            String[] PathParsed = Path.Split(new char[2] { '_', '/' });
            if (PathParsed.Length < 3)
            {
                return "Error uploading files: The path labeling convention had not been followed and as a result the path is ambiguous.  The parser cannot complete this uploaduntil the path has been corrected.  skipping...";
            }
            //Section_Title = PathParsed[PathParsed.Length - 2];
            //Chapter_Title = PathParsed[PathParsed.Length - 3];
            //Unit_Title = PathParsed[PathParsed.Length - 4];
            //Textbook_Title = PathParsed[PathParsed.Length - 5];
            if(PathParsed.Length < 4){ return "Error: The path could not be understood because it was too short.  skipping..."; }
            Textbook_Title = PathParsed[0];
            Unit_Title = PathParsed[1];
            Chapter_Title = PathParsed[2];
            Section_Title = PathParsed[3];

            _Info += Path + PathlessFileName + ".pdf ► " + Textbook_Title + " ► " + Unit_Title + " ► " + Chapter_Title + " ► " + Section_Title + " ► Page " + Page_Number + " ► Question " + Question_Number + " ► Practice Problem Answer " + Practice_Problem_Answer;

            //Search the database for this Textbook
            IQueryable<Textbook> RetrievedTextbooks = from theTextbooks in db.Textbooks
                                                      where theTextbooks.Title.Equals(Textbook_Title)
                                                      select theTextbooks;
            Textbook[] TextbookResults = RetrievedTextbooks.ToArray<Textbook>();
            if (TextbookResults.Length == 0)//The Textbook does not yet exists
            {
                //Create a new Textbook
                AnswerApp.Models.Textbook theTextbook = new AnswerApp.Models.Textbook();

                //Populate the Textbook with the properties extracted from the file name
                theTextbook.Title = Textbook_Title;

                if(theTextbook.Title.Length < 1)
                {
                    return "Warning: You have attempted to add a textbook without a title.  skipping...  ";
                }
                db.Textbooks.InsertOnSubmit(theTextbook);
                db.SubmitChanges();
            }

            //Search teh database for this Unit
            IQueryable<Unit> RetrievedUnits = from theUnits in db.Units
                                              where theUnits.Textbook_Title.Equals(Textbook_Title)
                                              && theUnits.Unit_Title.Equals(Unit_Title)
                                              select theUnits;
            Unit[] UnitResults = RetrievedUnits.ToArray<Unit>();
            if (UnitResults.Length == 0)//The Unit does not yet exists
            {
                //Create a new Unit
                AnswerApp.Models.Unit theUnit = new AnswerApp.Models.Unit();

                //Populate the Unit with the properties extracted from the file name
                theUnit.Textbook_Title = Textbook_Title;
                theUnit.Unit_Title = Unit_Title;
                //Populate the relational Id's based on previous hierarchical entries
                theUnit.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id;

                if (theUnit.Unit_Title.Length < 1)
                {
                    return "Warning: You have attempted to add a gUnit without a Unit Title.  skipping...";
                }

                db.Units.InsertOnSubmit(theUnit);
                db.SubmitChanges();
            }

            //Search the database for this Chapter
            IQueryable<Chapter> RetrievedChapters = from theChapters in db.Chapters
                                                    where theChapters.Textbook_Title.Equals(Textbook_Title)
                                                    && theChapters.Unit_Title.Equals(Unit_Title)
                                                    && theChapters.Chapter_Title.Equals(Chapter_Title)
                                                    select theChapters;
            Chapter[] ChapterResults = RetrievedChapters.ToArray<Chapter>();
            if (ChapterResults.Length == 0)//The Chapter does not yet exists
            {
                //Create a new Chapter
                AnswerApp.Models.Chapter theChapter = new AnswerApp.Models.Chapter();

                //Populate the Chapter with the properties extracted from the file name
                theChapter.Textbook_Title = Textbook_Title;
                theChapter.Unit_Title = Unit_Title;
                theChapter.Chapter_Title = Chapter_Title;
                //Populate the relational Id's based on previous hierarchical entries
                theChapter.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id;
                theChapter.Unit_Id = db.Units.Single(d => d.Unit_Title.Equals(Unit_Title)).Unit_Id;//YOU ARE HERE!!! (This needs tobe rewritten in case multiple textbooks ahve the same unit titles within them

                if (theChapter.Chapter_Title.Equals("MACOSX"))
                {
                    return "Warning: You have attempted to add a chapter titled MACOSX...  ...  ...  gAwD! O.o  ...skipping...";
                }

                db.Chapters.InsertOnSubmit(theChapter);
                db.SubmitChanges();
            }

            //Search teh database for this Section
            IQueryable<Section> RetrievedSections = from theSections in db.Sections
                                                    where theSections.Textbook_Title.Equals(Textbook_Title)
                                                    && theSections.Unit_Title.Equals(Unit_Title)
                                                    && theSections.Chapter_Title.Equals(Chapter_Title)
                                                    && theSections.Section_Title.Equals(Section_Title)
                                                    select theSections;
            Section[] SectionResults = RetrievedSections.ToArray<Section>();
            if (SectionResults.Length == 0)//The Section does not yet exists
            {
                //Create a new Section
                AnswerApp.Models.Section theSection = new AnswerApp.Models.Section();

                //Populate the Section with the properties extracted from the file name
                theSection.Textbook_Title = Textbook_Title;
                theSection.Unit_Title = Unit_Title;
                theSection.Chapter_Title = Chapter_Title;
                theSection.Section_Title = Section_Title;
                //Populate the relational Id's based on previous hierarchical entries
                theSection.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id;
                theSection.Unit_Id = db.Units.Single(d => d.Unit_Title.Equals(Unit_Title)).Unit_Id;
                theSection.Chapter_Id = db.Chapters.Single(d => d.Chapter_Title.Equals(Chapter_Title)).Chapter_Id;

                if (Section_Title.Length < 1)
                {
                    return "Warning: You have attempted to add a section that does not have a title.  skipping...";
                }

                db.Sections.InsertOnSubmit(theSection);
                db.SubmitChanges();
            }

            //Search teh database for this Page
            IQueryable<Page> RetrievedPages = from thePages in db.Pages
                                              where thePages.Textbook_Title.Equals(Textbook_Title)
                                              && thePages.Unit_Title.Equals(Unit_Title)
                                              && thePages.Chapter_Title.Equals(Chapter_Title)
                                              && thePages.Section_Title.Equals(Section_Title)
                                              && thePages.Page_Number.Equals(Page_Number)
                                              select thePages;
            Page[] PageResults = RetrievedPages.ToArray<Page>();
            int Page_Id = -1;
            if (PageResults.Length == 0)//The Page does not yet exist
            {
                //Create a new Page
                AnswerApp.Models.Page thePage = new AnswerApp.Models.Page();
                Page_Id = thePage.Page_Id;
                //Populate the Page with the properties extracted from the file name
                thePage.Textbook_Title = Textbook_Title;
                thePage.Unit_Title = Unit_Title;
                thePage.Chapter_Title = Chapter_Title;
                thePage.Section_Title = Section_Title;
                thePage.Page_Number = Page_Number;
                //Populate the relational Id's based on previous hierarchical entries
                thePage.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id;
                thePage.Unit_Id = db.Units.Single(d => d.Unit_Title.Equals(Unit_Title)).Unit_Id;
                thePage.Chapter_Id = db.Chapters.Single(d => d.Chapter_Title.Equals(Chapter_Title)).Chapter_Id;
                RetrievedSections = from theSections in db.Sections
                                    where theSections.Textbook_Title.Equals(Textbook_Title)
                                    && theSections.Unit_Title.Equals(Unit_Title)
                                    && theSections.Chapter_Title.Equals(Chapter_Title)
                                    && theSections.Section_Title.Equals(Section_Title)
                                    select theSections;
                thePage.Section_Id = RetrievedSections.First().Section_Id;// db.Sections.Single(d => d.Section_Title.Equals(Section_Title)).Section_Id;

                int test;
                if (!int.TryParse(thePage.Page_Number, out test))
                {
                    return "Error: You have attempted to add a page with a page number of '" + thePage.Page_Number + "'.  The question number must be a number.  You will have to correct this and try again.  skipping...  ";
                }

                db.Pages.InsertOnSubmit(thePage);
                db.SubmitChanges();
            }

            //Search teh database for this Question
            IQueryable<Question> retrieved = from theAnswers in db.Questions
                                             where theAnswers.Textbook_Title.Equals(Textbook_Title)
                                             && theAnswers.Unit_Title.Equals(Unit_Title)
                                             && theAnswers.Chapter_Title.Equals(Chapter_Title)
                                             && theAnswers.Section_Title.Equals(Section_Title)
                                             && theAnswers.Page_Number.Equals(Page_Number)
                                             && theAnswers.Question_Number.Equals(Question_Number)
                                             select theAnswers;
            Question[] results = retrieved.ToArray<Question>();
            if (results.Length != 0)//The Answer already exists
            {
                //Use the existing Question
                AnswerApp.Models.Question theQuestion = results.First();

                if (Practice_Problem_Answer != null)//This is a Practice Problem
                {
                    theQuestion.Practice_Problem = data;
                    theQuestion.Practice_Problem_Answer = Practice_Problem_Answer;
                }
                else//(Practice_Problem == null) This is an Answer
                {
                    theQuestion.Answer = data;
                    //theQuestion.Practice_Problem_Answer = Practice_Problem_Answer;
                }
            }
            else//(results.Length == 0) This is a new Answer
            {
                //Create a new Question
                AnswerApp.Models.Question theQuestion = new AnswerApp.Models.Question();

                //Populate the Question with the properties extracted from the file name
                theQuestion.Textbook_Title = Textbook_Title;
                theQuestion.Unit_Title = Unit_Title;
                theQuestion.Chapter_Title = Chapter_Title;
                theQuestion.Section_Title = Section_Title;
                theQuestion.Page_Number = Page_Number;
                theQuestion.Question_Number = Question_Number;
                //Populate the relational Id's based on previous hierarchical entries
                theQuestion.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id;
                theQuestion.Unit_Id = db.Units.Single(d => d.Unit_Title.Equals(Unit_Title)).Unit_Id;
                theQuestion.Chapter_Id = db.Chapters.Single(d => d.Chapter_Title.Equals(Chapter_Title)).Chapter_Id;
                //theQuestion.Section_Id = db.Sections.Single(d => d.Section_Title.Equals(Section_Title)).Section_Id;
                RetrievedSections = from theSections in db.Sections
                                    where theSections.Textbook_Title.Equals(Textbook_Title)
                                    && theSections.Unit_Title.Equals(Unit_Title)
                                    && theSections.Chapter_Title.Equals(Chapter_Title)
                                    && theSections.Section_Title.Equals(Section_Title)
                                    select theSections;
                theQuestion.Section_Id = RetrievedSections.First().Section_Id;// db.Questions.Single(d => d.Question_Title.Equals(Question_Title)).Question_Id;
                if (Page_Id != -1) { theQuestion.Page_Id = Page_Id; }
                else
                {
                    //try
                    //{
                        //theQuestion.Page_Id = db.Pages.Single(d => d.Page_Number.Equals(Page_Number)).Page_Id;
                    RetrievedPages = from thePages in db.Pages
                                                      where thePages.Textbook_Title.Equals(Textbook_Title)
                                                      //&& thePages.Unit_Title.Equals(Unit_Title)
                                                      //&& thePages.Chapter_Title.Equals(Chapter_Title)
                                                      //&& thePages.Section_Title.Equals(Section_Title)
                                                      && thePages.Page_Number.Equals(Page_Number)
                                                      select thePages;
                    theQuestion.Page_Id = RetrievedPages.First().Page_Id; //results = retrieved.ToArray<Question>();
                    /*}
                    catch
                    {
                        IQueryable<Page> OldPages = from thePages in db.Pages
                                                    where thePages.Textbook_Title.Equals(Textbook_Title)
                                                    //&& thePages.Unit_Title.Equals(Unit_Title)
                                                    //&& thePages.Chapter_Title.Equals(Chapter_Title)
                                                    //&& thePages.Section_Title.Equals(Section_Title)
                                                    //&& thePages.Page_Number.Equals(Page_Number)
                                                    select thePages;
                        Page[] theOldPages = OldPages.ToArray<Page>();
                        return "Error: The page you are attempting to add, Page " + theQuestion.Page_Number + ", already exists in a previously uploaded section with a different title.  The title of the previously uploaded section is: " + theQuestion.Section_Title + ".  The Title of the section you are presently uploading is: " + theOldPages[0].Section_Title + ".  You will have to appropriately alter the section headings of your zipped directory and try again.  skipping...";
                    }*/
                }

                int test;
                if (!int.TryParse(theQuestion.Question_Number, out test))
                {
                    return "Error: You have attempted to add a question numbered '" + theQuestion.Question_Number + "'.  The question number must be a number.  You will have to correct this and try again.  skipping...  ";
                }

                if (Practice_Problem_Answer != null)//This is a Practice Problem
                {
                    theQuestion.Practice_Problem = data;
                    theQuestion.Practice_Problem_Answer = Practice_Problem_Answer;
                }
                else//(Practice_Problem == null) This is an Answer
                {
                    theQuestion.Answer = data;
                    //theQuestion.Practice_Problem_Answer = Practice_Problem_Answer;
                }

                //Insert the new Question into the database
                db.Questions.InsertOnSubmit(theQuestion);
            }

            db.SubmitChanges();//Commit the changes to the database.*/
            return _Info;
        }
コード例 #13
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);
        }
コード例 #14
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");
        }
コード例 #15
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;
        }
コード例 #16
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);
        }
コード例 #17
0
        //When a user requests a file, this method returns the
        //file as an object in the http response rather than
        //As a file on the server file system.
        public ActionResult GetPdf(String argument)
        {
            //Extract the file properties from the file name argument
            String[] arguments = argument.Split(new char[1] { '_' });
            String user = arguments[0];
            String Textbook_Title = arguments[1];
            String Unit_Title = arguments[2];
            String Chapter_Title = arguments[3];
            String Section_Title = arguments[4];
            String Page_Number = arguments[5];
            String Question_Number = arguments[6].Split(new char[1] { '.' })[0];//Truncate ".pdf" from the end of the file name
            String Practice_Problem = null;
            if (arguments.Length > 7){Practice_Problem = arguments[7];}//An 8th argument indicates a Practice Problem
            if (Practice_Problem != null) { Practice_Problem = arguments[7].Split(new char[1] { '.' })[0]; }//Truncate ".pdf" from the end of the file name

            //If the username is not the one specified in the file name, redirect them
            if (!User.Identity.Name.Equals(user)) { return RedirectToAction("LogIn", "Account"); }

            String filename = argument;//The name of the file will be prefixed by the username of the person retrieving it

            //Generate the file name under which the answer will be stored in the database
            String FileNameInDB = "" + arguments[1] +
                                  "_" + arguments[2] +
                                  "_" + arguments[3] +
                                  "_" + arguments[4] +
                                  "_" + arguments[5] +
                                  "_" + arguments[6];

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

            //Check to see that the user is registered
            AnswerApp.Models.User thisUser = db.Users.Single(d => d.UserName.Equals(User.Identity.Name));

            //If the user is not in the database they will be redirected to the registration page
            if (thisUser == null) { RedirectToAction("Register", "Account"); }

            //If the user has previous answers then check them to see if this is one of them
            if (thisUser.Answers != null)
            {
                String[] UserAnswers = thisUser.Answers.Split(new char[2] { ',', ';' });

                //Check to see if the user already has that answer
                if (UserHasAccess(User.Identity.Name, FileNameInDB))
                {
                    //Retrieve the answer from the database
                    IQueryable<Question> retrieved = from theAnswers in db.Questions
                                                        where theAnswers.Textbook_Title.Equals(Textbook_Title)
                                                        && theAnswers.Unit_Title.Equals(Unit_Title)
                                                        && theAnswers.Chapter_Title.Equals(Chapter_Title)
                                                        && theAnswers.Section_Title.Equals(Section_Title)
                                                        && theAnswers.Page_Number.Equals(Page_Number)
                                                        && theAnswers.Question_Number.Equals(Question_Number)
                                                        select theAnswers;
                    Question[] results = retrieved.ToArray<Question>();
                    if (results.Length == 0) { return RedirectToAction("ResourceUnavailable", "Home"); }//If the answer doesn't exist in the database then redirect them
                    AnswerApp.Models.Question theQuestion = results.First();
                    byte[] pdfBytes = null;
                    if (Practice_Problem != null)//This is a Practice Problem
                    {
                        pdfBytes = theQuestion.Practice_Problem.ToArray();
                    }
                    else//(Practice_Problem == null) This is not a Practice Problem
                    {
                        pdfBytes = theQuestion.Answer.ToArray();
                    }
                    return new PdfResult(pdfBytes, false, filename);
                }//else this answer is not the answer we're loking for so continue searching
            }
            //After checking all of the users answers, if this Answer is not listed, redirect to select page
            return RedirectToAction("Pay", "Answers", new SelectModel(FileNameInDB));
        }
コード例 #18
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;
        }
コード例 #19
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;
 }
コード例 #20
0
        //This method adds entry information
        //and also file contents to the database
        //whenever new Images are added
        Boolean AddImageFromZip(byte[] data, String FileName)
        {
            AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext();

            //Disect the file name for it's file properties
            String ExtensionlessFileName = FileName.Replace(".jpg", "");
            ExtensionlessFileName = ExtensionlessFileName.Replace(".gif", "");
            String[] properties = ExtensionlessFileName.Split(new char[2] { '_', '/' });
            String Textbook_Title = null;
            String Unit_Title = null;
            String Chapter_Title = null;
            //String Section_Title = null;
            if (properties.Length > 0) { Textbook_Title = properties[0]; }
            if (properties.Length > 1) { Unit_Title = properties[1]; }
            if (properties.Length > 2) { Chapter_Title = properties[2]; }
            //if (properties.Length > 3) { Section_Title = properties[2]; }

            Boolean Textbook_Image = false;
            Boolean Unit_Image = false;
            Boolean Chapter_Image = false;
            //Boolean Section_Image = false;
            if (properties.Length == 1) { Textbook_Image = true; }
            if (properties.Length == 2) { Unit_Image = true; }
            if (properties.Length == 3) { Chapter_Image = true; }
            //if (properties.Length == 4) { SectionImage = true; }

            if (Textbook_Title != null)
            {
                //ViewData["Info"] += "(in3)";

                //Search the database for this Textbook
                IQueryable<Textbook> RetrievedTextbooks = from theTextbooks in db.Textbooks
                                                          where theTextbooks.Title.Equals(Textbook_Title)
                                                          select theTextbooks;
                Textbook[] TextbookResults = RetrievedTextbooks.ToArray<Textbook>();
                if (TextbookResults.Length == 0)//The Textbook does not yet exists
                {
                    //Create a new Textbook
                    AnswerApp.Models.Textbook theTextbook = new AnswerApp.Models.Textbook();

                    //Populate the Textbook with the properties extracted from the file name
                    theTextbook.Title = Textbook_Title;

                    if (theTextbook.Title.Length < 1)
                    {
                        return false;
                    }

                    if (Textbook_Image)
                    {
                        theTextbook.Image = data;// new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length);
                    }

                    db.Textbooks.InsertOnSubmit(theTextbook);
                }
                else if (Textbook_Image)
                {
                    //Gather a handle to the existing textbook
                    AnswerApp.Models.Textbook theTextbook = TextbookResults.First();

                    //Populate the existing Textbook with the properties extracted from the file name
                    theTextbook.Title = Textbook_Title;
                    theTextbook.Image = data;// new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length);
                }

                db.SubmitChanges();
            }

            if (Unit_Title != null)
            {
                //Search teh database for this Unit
                IQueryable<Unit> RetrievedUnits = from theUnits in db.Units
                                                  where theUnits.Textbook_Title.Equals(Textbook_Title)
                                                  && theUnits.Unit_Title.Equals(Unit_Title)
                                                  select theUnits;
                Unit[] UnitResults = RetrievedUnits.ToArray<Unit>();
                if (UnitResults.Length == 0)//The Unit does not yet exists
                {
                    //Create a new Unit
                    AnswerApp.Models.Unit theUnit = new AnswerApp.Models.Unit();

                    //Populate the Unit with the properties extracted from the file name
                    theUnit.Textbook_Title = Textbook_Title;
                    theUnit.Unit_Title = Unit_Title;
                    //Populate the relational Id's based on previous hierarchical entries
                    theUnit.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id;

                    if (theUnit.Unit_Title.Length < 1)
                    {
                        return false;// "Error: You have attempted to add a gUnit without a Unit Title.  skipping...";
                    }

                    if (Unit_Image)
                    {
                        theUnit.Image = data;// new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length);
                    }

                    db.Units.InsertOnSubmit(theUnit);
                }
                else if (Unit_Image)
                {
                    //Gather a handle to the existing Unit
                    AnswerApp.Models.Unit theUnit = UnitResults.First();

                    //Populate the existing Unit with the properties extracted from the file name
                    theUnit.Unit_Title = Unit_Title;
                    theUnit.Image = data;// new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length);
                }
                db.SubmitChanges();
            }

            if (Chapter_Title != null)
            {
                //Search the database for this Chapter
                IQueryable<Chapter> RetrievedChapters = from theChapters in db.Chapters
                                                        where theChapters.Textbook_Title.Equals(Textbook_Title)
                                                        && theChapters.Unit_Title.Equals(Unit_Title)
                                                        && theChapters.Chapter_Title.Equals(Chapter_Title)
                                                        select theChapters;
                Chapter[] ChapterResults = RetrievedChapters.ToArray<Chapter>();
                if (ChapterResults.Length == 0)//The Chapter does not yet exists
                {
                    //Create a new Chapter
                    AnswerApp.Models.Chapter theChapter = new AnswerApp.Models.Chapter();

                    //Populate the Chapter with the properties extracted from the file name
                    theChapter.Textbook_Title = Textbook_Title;
                    theChapter.Unit_Title = Unit_Title;
                    theChapter.Chapter_Title = Chapter_Title;
                    //Populate the relational Id's based on previous hierarchical entries
                    theChapter.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id;
                    theChapter.Unit_Id = db.Units.Single(d => d.Unit_Title.Equals(Unit_Title)).Unit_Id;

                    if(theChapter.Chapter_Title.Equals("MACOSX"))
                    {
                        return false;//"Error: You have attempted to add a chapter titled MACOSX...  ...  ...  gAwD! O.o  ...skipping...";
                    }

                    if (Chapter_Image)
                    {
                        theChapter.Image = data;// new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length);
                    }

                    db.Chapters.InsertOnSubmit(theChapter);
                }
                else if (Chapter_Image)
                {
                    //Gather a handle to the existing Chapter
                    AnswerApp.Models.Chapter theChapter = ChapterResults.First();

                    //Populate the existing CHapter with the properties extracted from the file name
                    theChapter.Chapter_Title = Chapter_Title;
                    theChapter.Image = data;// new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length);
                }
                db.SubmitChanges();
            }

            /*            if(Section_Title != null)
                        {
                            //Search the database for this Section
                            IQueryable<Section> RetrievedSections = from theSections in db.Sections
                                                                    where theSections.Textbook_Title.Equals(Textbook_Title)
                                                                    && theSections.Unit_Title.Equals(Unit_Title)
                                                                    && theSections.Chapter_Title.Equals(Chapter_Title)
                                                                    && theSections.Section_Title.Equals(Section_Title)
                                                                    select theSections;
                            Section[] SectionResults = RetrievedSections.ToArray<Section>();
                            if (SectionResults.Length == 0)//The Section does not yet exists
                            {
                                //Create a new Section
                                AnswerApp.Models.Section theSection = new AnswerApp.Models.Section();

                                //Populate the Section with the properties extracted from the file name
                                theSection.Textbook_Title = Textbook_Title;
                                theSection.Unit_Title = Unit_Title;
                                theSection.Chapter_Title = Chapter_Title;
                                theSection.Section_Title = Section_Title;
                                //Populate the relational Id's based on previous hierarchical entries
                                theSection.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id;
                                theSection.Unit_Id = db.Units.Single(d => d.Unit_Title.Equals(Unit_Title)).Unit_Id;
                                theSection.Chapter_Id = db.Chapters.Single(d => d.Chapter_Title.Equals(Chapter_Title)).Chapter_Id;

                                db.Sections.InsertOnSubmit(theSection);
                                db.SubmitChanges();
                            }
                        }
            */

            db.SubmitChanges();//Commit the changes to the database.
            return true;
        }
コード例 #21
0
        //This method adds entry information
        //and also file contents to the database
        //whenever new Questions are added
        Boolean AddSolution(HttpPostedFileBase hpf, String FileName, UploadModel model)
        {
            AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext();

            //Disect the file name for it's file properties
            String[] properties = FileName.Split(new char[1] { '_' });
            String Textbook_Title = properties[0];
            String Unit_Title = properties[1];
            String Chapter_Title = properties[2];
            String Section_Title = properties[3];
            String Page_Number = properties[4];
            String Question_Number = properties[5].Split(new char[1] { '.' })[0];//Truncate ".pdf" from the end of the file name
            String Practice_Problem = null;
            if (properties.Length > 6) { Practice_Problem = properties[6]; }//An 7th argument indicates a Practice Problem
            if (Practice_Problem != null) { Practice_Problem = properties[6].Split(new char[1] { '.' })[0]; }//Truncate ".pdf" from the end of the file name

            //Search teh database for this Textbook
            IQueryable<Textbook> RetrievedTextbooks = from theTextbooks in db.Textbooks
                                                      where theTextbooks.Title.Equals(Textbook_Title)
                                                      select theTextbooks;
            Textbook[] TextbookResults = RetrievedTextbooks.ToArray<Textbook>();
            if (TextbookResults.Length == 0)//The Textbook does not yet exists
            {
                //Create a new Textbook
                AnswerApp.Models.Textbook theTextbook = new AnswerApp.Models.Textbook();

                //Populate the Textbook with the properties extracted from the file name
                theTextbook.Title = Textbook_Title;

                if (theTextbook.Title.Length < 1)
                {
                    return false;
                }

                db.Textbooks.InsertOnSubmit(theTextbook);
                db.SubmitChanges();
            }

            //Search teh database for this Unit
            IQueryable<Unit> RetrievedUnits = from theUnits in db.Units
                                              where theUnits.Textbook_Title.Equals(Textbook_Title)
                                              && theUnits.Unit_Title.Equals(Unit_Title)
                                              select theUnits;
            Unit[] UnitResults = RetrievedUnits.ToArray<Unit>();
            if (UnitResults.Length == 0)//The Unit does not yet exists
            {
                //Create a new Unit
                AnswerApp.Models.Unit theUnit = new AnswerApp.Models.Unit();

                //Populate the Unit with the properties extracted from the file name
                theUnit.Textbook_Title = Textbook_Title;
                theUnit.Unit_Title = Unit_Title;
                //Populate the relational Id's based on previous hierarchical entries
                theUnit.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id;

                db.Units.InsertOnSubmit(theUnit);
                db.SubmitChanges();
            }

            //Search the database for this Chapter
            IQueryable<Chapter> RetrievedChapters = from theChapters in db.Chapters
                                                    where theChapters.Textbook_Title.Equals(Textbook_Title)
                                                    && theChapters.Unit_Title.Equals(Unit_Title)
                                                    && theChapters.Chapter_Title.Equals(Chapter_Title)
                                                    select theChapters;
            Chapter[] ChapterResults = RetrievedChapters.ToArray<Chapter>();
            if (ChapterResults.Length == 0)//The Chapter does not yet exists
            {
                //Create a new Chapter
                AnswerApp.Models.Chapter theChapter = new AnswerApp.Models.Chapter();

                //Populate the Chapter with the properties extracted from the file name
                theChapter.Textbook_Title = Textbook_Title;
                theChapter.Unit_Title = Unit_Title;
                theChapter.Chapter_Title = Chapter_Title;
                //Populate the relational Id's based on previous hierarchical entries
                theChapter.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id;
                theChapter.Unit_Id = db.Units.Single(d => d.Unit_Title.Equals(Unit_Title)).Unit_Id;

                if (theChapter.Chapter_Title.Equals("MACOSX"))
                {
                    return false;//"Error: You have attempted to add a chapter titled MACOSX...  ...  ...  gAwD! O.o  ...skipping...";
                }

                db.Chapters.InsertOnSubmit(theChapter);
                db.SubmitChanges();
            }

            //Search teh database for this Section
            IQueryable<Section> RetrievedSections = from theSections in db.Sections
                                                    where theSections.Textbook_Title.Equals(Textbook_Title)
                                                    && theSections.Unit_Title.Equals(Unit_Title)
                                                    && theSections.Chapter_Title.Equals(Chapter_Title)
                                                    && theSections.Section_Title.Equals(Section_Title)
                                                    select theSections;
            Section[] SectionResults = RetrievedSections.ToArray<Section>();
            if (SectionResults.Length == 0)//The Section does not yet exists
            {
                //Create a new Section
                AnswerApp.Models.Section theSection = new AnswerApp.Models.Section();

                //Populate the Section with the properties extracted from the file name
                theSection.Textbook_Title = Textbook_Title;
                theSection.Unit_Title = Unit_Title;
                theSection.Chapter_Title = Chapter_Title;
                theSection.Section_Title = Section_Title;
                //Populate the relational Id's based on previous hierarchical entries
                theSection.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id;
                theSection.Unit_Id = db.Units.Single(d => d.Unit_Title.Equals(Unit_Title)).Unit_Id;
                theSection.Chapter_Id = db.Chapters.Single(d => d.Chapter_Title.Equals(Chapter_Title)).Chapter_Id;

                if (theSection.Section_Title.Length < 1)
                {
                    return false;
                }

                db.Sections.InsertOnSubmit(theSection);
                db.SubmitChanges();
            }

            //Search teh database for this Page
            IQueryable<Page> RetrievedPages = from thePages in db.Pages
                                              where thePages.Textbook_Title.Equals(Textbook_Title)
                                              //&& thePages.Unit_Title.Equals(Unit_Title)
                                              //&& thePages.Chapter_Title.Equals(Chapter_Title)
                                              //&& thePages.Section_Title.Equals(Section_Title)
                                              && thePages.Page_Number.Equals(Page_Number)
                                              select thePages;
            Page[] PageResults = RetrievedPages.ToArray<Page>();
            if (PageResults.Length == 0)//The Page does not yet exists
            {
                //Create a new Page
                AnswerApp.Models.Page thePage = new AnswerApp.Models.Page();

                //Populate the Page with the properties extracted from the file name
                thePage.Textbook_Title = Textbook_Title;
                thePage.Unit_Title = Unit_Title;
                thePage.Chapter_Title = Chapter_Title;
                thePage.Section_Title = Section_Title;
                thePage.Page_Number = Page_Number;
                //Populate the relational Id's based on previous hierarchical entries
                thePage.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id;
                thePage.Unit_Id = db.Units.Single(d => d.Unit_Title.Equals(Unit_Title)).Unit_Id;
                thePage.Chapter_Id = db.Chapters.Single(d => d.Chapter_Title.Equals(Chapter_Title)).Chapter_Id;
                thePage.Section_Id = db.Sections.Single(d => d.Section_Title.Equals(Section_Title)).Section_Id;

                int test;
                if (!int.TryParse(thePage.Page_Number, out test))
                {
                    return false;
                }

                db.Pages.InsertOnSubmit(thePage);
                db.SubmitChanges();
            }

            //Search teh database for this Question
            IQueryable<Question> retrieved = from theAnswers in db.Questions
                                             where theAnswers.Textbook_Title.Equals(Textbook_Title)
                                             && theAnswers.Unit_Title.Equals(Unit_Title)
                                             && theAnswers.Chapter_Title.Equals(Chapter_Title)
                                             && theAnswers.Section_Title.Equals(Section_Title)
                                             && theAnswers.Page_Number.Equals(Page_Number)
                                             && theAnswers.Question_Number.Equals(Question_Number)
                                             select theAnswers;
            Question[] results = retrieved.ToArray<Question>();
            if (results.Length != 0)//The Answer already exists
            {
                //Use the existing Question
                AnswerApp.Models.Question theQuestion = results.First();

                if (Practice_Problem != null)//This is a Practice Problem
                {
                    theQuestion.Practice_Problem = new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length);
                    theQuestion.Practice_Problem_Answer = model.PracticeProblemAnswer;
                }
                else//(Practice_Problem == null) This is an Answer
                {
                    theQuestion.Answer = new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length);
                    theQuestion.Practice_Problem_Answer = model.PracticeProblemAnswer;
                }
            }
            else//(results.Length == 0) This is a new Answer
            {
                //Create a new Question
                AnswerApp.Models.Question theQuestion = new AnswerApp.Models.Question();

                //Populate the Question with the properties extracted from the file name
                theQuestion.Textbook_Title = Textbook_Title;
                theQuestion.Unit_Title = Unit_Title;
                theQuestion.Chapter_Title = Chapter_Title;
                theQuestion.Section_Title = Section_Title;
                theQuestion.Page_Number = Page_Number;
                theQuestion.Question_Number = Question_Number;
                //Populate the relational Id's based on previous hierarchical entries
                theQuestion.Textbook_Id = db.Textbooks.Single(d => d.Title.Equals(Textbook_Title)).Unique_Id;
                theQuestion.Unit_Id = db.Units.Single(d => d.Unit_Title.Equals(Unit_Title)).Unit_Id;
                theQuestion.Chapter_Id = db.Chapters.Single(d => d.Chapter_Title.Equals(Chapter_Title)).Chapter_Id;
                theQuestion.Section_Id = db.Sections.Single(d => d.Section_Title.Equals(Section_Title)).Section_Id;
                theQuestion.Page_Id = db.Pages.Single(d => d.Page_Number.Equals(Page_Number)).Page_Id;

                if (Practice_Problem != null)//This is a Practice Problem
                {
                    theQuestion.Practice_Problem = new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length);
                    theQuestion.Practice_Problem_Answer = model.PracticeProblemAnswer;
                }
                else//(Practice_Problem == null) This is an Answer
                {
                    theQuestion.Answer = new BinaryReader(hpf.InputStream).ReadBytes((int)hpf.InputStream.Length);
                    theQuestion.Practice_Problem_Answer = model.PracticeProblemAnswer;
                }

                int test;
                if (!int.TryParse(theQuestion.Page_Number, out test))
                {
                    return false;
                }

                //Insert the new Question into the database
                db.Questions.InsertOnSubmit(theQuestion);
            }

            db.SubmitChanges();//Commit the changes to the database.
            return true;
        }
コード例 #22
0
ファイル: AnswerModels.cs プロジェクト: aarotech/AnswerApp
        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"; }
        }
コード例 #23
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;
        }
コード例 #24
0
ファイル: AnswerModels.cs プロジェクト: aarotech/AnswerApp
 public PriceBreakdown Price(SelectModel model, User thisUser, AnswerAppDataContext db)
 {
     return new PriceBreakdown(model, thisUser, db);
 }
コード例 #25
0
        //When a user requests a file, this method returns the
        //file as an object in the http response rather than
        //As a file on the server file system.
        public ActionResult GetImage(String argument)
        {
            //Extract the file properties from the file name argument
            String extensionlessArgument = argument.Replace(".jpg", "");
            extensionlessArgument = extensionlessArgument.Replace(".gif", "");
            String[] arguments = extensionlessArgument.Split(new char[1] { '_' });
            String Textbook_Title = null;
            String Unit_Title = null;
            String Chapter_Title = null;
            //String Section_Title = null;
            if (arguments.Length > 0) { Textbook_Title = arguments[0]; }
            if (arguments.Length > 1) { Unit_Title = arguments[1]; }
            if (arguments.Length > 2) { Chapter_Title = arguments[2]; }
            //if (arguments.Length > 3) { Section_Title = arguments[3]; }

            Boolean Textbook_Image = false;
            Boolean Unit_Image = false;
            Boolean Chapter_Image = false;
            //Boolean Section_Image = false;
            if (arguments.Length == 1) { Textbook_Image = true; }
            if (arguments.Length == 2) { Unit_Image = true; }
            if (arguments.Length == 3) { Chapter_Image = true; }

            String filename = argument;//The name of the file

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

            byte[] imgBytes = null;

            //Retrieve the image from the database
            if (Textbook_Image)
            {
                IQueryable<Textbook> retrieved = from theImages in db.Textbooks
                                                 where theImages.Title.Equals(Textbook_Title)
                                                 //&& theImages.Unit_Title.Equals(Unit_Title)
                                                 //&& theImages.Chapter_Title.Equals(Chapter_Title)
                                                 //&& theImages.Section_Title.Equals(Section_Title)
                                                 select theImages;
                Textbook[] results = retrieved.ToArray<Textbook>();
                if (results.Length == 0) { return null; }//If the image doesn't exist in thedatabase show something else
                AnswerApp.Models.Textbook theTextbook = results.First();
                imgBytes = theTextbook.Image.ToArray();
            }
            else if (Unit_Image)
            {
                IQueryable<Unit> retrieved = from theImages in db.Units
                                             where theImages.Textbook_Title.Equals(Textbook_Title)
                                             && theImages.Unit_Title.Equals(Unit_Title)
                                             //&& theImages.Chapter_Title.Equals(Chapter_Title)
                                             //&& theImages.Section_Title.Equals(Section_Title)
                                             select theImages;
                Unit[] results = retrieved.ToArray<Unit>();
                if (results.Length == 0) { return null; }//If the image doesn't exist in thedatabase show something else
                AnswerApp.Models.Unit theUnit = results.First();
                imgBytes = theUnit.Image.ToArray();
            }
            else if (Chapter_Image)
            {
                IQueryable<Chapter> retrieved = from theImages in db.Chapters
                                             where theImages.Textbook_Title.Equals(Textbook_Title)
                                             && theImages.Unit_Title.Equals(Unit_Title)
                                             && theImages.Chapter_Title.Equals(Chapter_Title)
                                             //&& theImages.Section_Title.Equals(Section_Title)
                                             select theImages;
                Chapter[] results = retrieved.ToArray<Chapter>();
                if (results.Length == 0) { return null; }//If the image doesn't exist in thedatabase show something else
                AnswerApp.Models.Chapter theChapter = results.First();
                imgBytes = theChapter.Image.ToArray();
            }
            if(argument.EndsWith(".jpg"))
            {
                return new JPGResult(imgBytes, false, filename);
            }
            else if (argument.EndsWith(".gif"))
            {
                return new GIFResult(imgBytes, false, filename);
            }
            else
            {
                return new GIFResult(imgBytes, false, filename);
            }
        }
コード例 #26
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");
        }
コード例 #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;
     }
 }
コード例 #28
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");
        }
コード例 #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);
        }
コード例 #30
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);
 }