public static GameListResults FetchGameList(Guid SessionId)
        {
            GameListResults request = new GameListResults();

            try
            {
                AgileMindEntities agileDB = new AgileMindEntities();

                t_LoginSession session = (from loginSession in agileDB.t_LoginSession where loginSession.LoginSessionId == SessionId && loginSession.ValidTill > DateTime.Now select loginSession).First();
                if (session != null)
                {

                    List<t_Game> gameList = (from gameData in agileDB.t_Game select gameData).ToList();
                    request.GameList = gameList;
                    request.Success = true;

                }
                else
                {
                    request.Error = "Could not find sessionId";
                }
            }
            catch (Exception ex)
            {
                request.Error = ex.Message;
            }
            return request;
        }
        public void HasUserFilledOutQuestionsReturnsTrueIfTheUserFilledOutEvenASingleQuestion()
        {
            AgileMindEntities agileDb = new AgileMindEntities();

            LoginResult.ValidateLogin(LOGINNAME, PASSWORD, "ip");

            AgileMind.DAL.Data.Login login = (from data in agileDb.Logins where data.LoginName == LOGINNAME select data).First();
            if (login != null)
            {
                t_LoginSession session = (from data in agileDb.t_LoginSession where data.LoginId == login.LoginId && data.ValidTill > DateTime.Now select data).First();
                if (session != null)
                {
                    t_UserProfileAnswer newAnswer = new t_UserProfileAnswer();
                    newAnswer.LoginId = login.LoginId;
                    newAnswer.NoAnswer = false;
                    newAnswer.UserProfileQuestionId = 1;
                    newAnswer.Answer = "one answer";
                    newAnswer.Created = DateTime.Now;
                    agileDb.t_UserProfileAnswer.AddObject(newAnswer);
                    agileDb.SaveChanges();

                    bool userFilledOutQuestion = UserProfileQuestionsResults.HasUserFilledOutAnyQuestions(session.LoginSessionId);
                    Assert.IsTrue(userFilledOutQuestion);
                }
                else
                {
                    Assert.Fail("Could not find the session to begin testing.");
                }
            }
            else
            {
                Assert.Fail("Could not find the login to start testing");
            }
        }
예제 #3
0
        public static GameResults InsertGameResult(String UserName, String Password, GameListEnum gameType, int Score, decimal TestDuration, int Total)
        {
            GameResults results = new GameResults();
            try
            {
                LoginResult loginResult = LoginResult.ValidateLogin(UserName, Password, String.Empty);
                if (loginResult.Success)
                {
                    AgileMindEntities db = new AgileMindEntities();
                    t_GameResults gameResults = new t_GameResults();
                    gameResults.Created = DateTime.Now;
                    gameResults.GameId = (int)gameType;
                    gameResults.LoginId = loginResult.LoginInfo.LoginId;
                    gameResults.Score = Score;
                    gameResults.TestDuration = TestDuration;
                    gameResults.Total = Total;
                    db.t_GameResults.AddObject(gameResults);
                    db.SaveChanges();

                    results.Success = true;
                    results.Game = gameResults;

                }
                else
                {
                    results.Error = "Could not login.  Invalid Username/Password";
                }

            }
            catch (Exception ex)
            {
                results.Error = ex.Message;
            }
            return results;
        }
        public void HasUserFilledOutQuestionsReturnsFalseIfTheUserDidNotFillOutAnyQuestions()
        {
            AgileMindEntities agileDb = new AgileMindEntities();

            LoginResult.ValidateLogin(LOGINNAME, PASSWORD, "ip");

            AgileMind.DAL.Data.Login login = (from data in agileDb.Logins where data.LoginName == LOGINNAME select data).First();
            if (login != null)
            {
                t_LoginSession session = (from data in agileDb.t_LoginSession where data.LoginId == login.LoginId && data.ValidTill > DateTime.Now select data).First();
                if (session != null)
                {

                    bool userFilledOutQuestion = UserProfileQuestionsResults.HasUserFilledOutAnyQuestions(session.LoginSessionId);
                    Assert.IsFalse(userFilledOutQuestion);
                }
                else
                {
                    Assert.Fail("Could not find the session to begin testing.");
                }
            }
            else
            {
                Assert.Fail("Could not find the login to start testing");
            }
        }
        public static IndividualGameResults FetchResultsForGameType(Guid SessionId, int GameId)
        {
            IndividualGameResults request = new IndividualGameResults();

            try
            {
                AgileMindEntities agileDB = new AgileMindEntities();

                t_LoginSession session = (from loginSession in agileDB.t_LoginSession where loginSession.LoginSessionId == SessionId && loginSession.ValidTill > DateTime.Now select loginSession).First();
                if (session != null)
                {

                    List<t_GameResults> userResults = (from gameResultsData in agileDB.t_GameResults where gameResultsData.LoginId == session.LoginId && gameResultsData.GameId == GameId && gameResultsData.Total > 0 && gameResultsData.TestDuration > 0 orderby gameResultsData.Created select gameResultsData).ToList();
                    request.GameResultList = userResults;
                    request.Success = true;

                }
                else
                {
                    request.Error = "Could not find sessionId";
                }
            }
            catch (Exception ex)
            {
                request.Error = ex.Message;
            }
            return request;
        }
        public static UserGameResults FetchUserGameResults(Guid SessionId)
        {
            UserGameResults request = new UserGameResults();

            try
            {
                AgileMindEntities agileDB = new AgileMindEntities();

                t_LoginSession session = (from loginSession in agileDB.t_LoginSession where loginSession.LoginSessionId == SessionId && loginSession.ValidTill > DateTime.Now select loginSession).First();
                if (session != null)
                {

                    List<t_GameResults> userResults = (from gameResultsData in agileDB.t_GameResults where gameResultsData.LoginId == session.LoginId && gameResultsData.Total > 0 && gameResultsData.TestDuration > 0 orderby gameResultsData.GameId select gameResultsData).ToList();
                    List<t_Game> gameList = (from gameData in agileDB.t_Game select gameData).ToList();
                    foreach (t_Game game in gameList)
                    {
                        List<t_GameResults> gameResultsList = userResults.FindAll(delegate(t_GameResults findResults) { return findResults.GameId == game.GameId; });
                        if (gameResultsList.Count > 0)
                        {
                            decimal gameScoreTotal = 0;
                            foreach (t_GameResults gameResult in gameResultsList)
                            {
                                gameScoreTotal += ((decimal)gameResult.Score / (decimal)gameResult.Total) * 100 / gameResult.TestDuration.Value;

                            }
                            UserMeanGameScore newGameScore = new UserMeanGameScore();
                            newGameScore.Game = game.Game;
                            newGameScore.GameDeviation = (decimal)game.stdev;
                            newGameScore.GameId = game.GameId;
                            newGameScore.GameMean = (decimal)game.Mean;
                            newGameScore.UserMean = gameScoreTotal / gameResultsList.Count;
                            newGameScore.MeanDiff = newGameScore.UserMean - newGameScore.GameMean;
                            newGameScore.UserDeflection = newGameScore.MeanDiff / newGameScore.GameDeviation;

                            request.MeanGameScores.Add(newGameScore);

                        }

                    }

                    decimal userDeflectionTotal = 0;
                    foreach (UserMeanGameScore mgs in request.MeanGameScores)
                    {
                        userDeflectionTotal += mgs.UserDeflection;
                    }
                    request.UserScore = userDeflectionTotal / request.MeanGameScores.Count;

                    request.Success = true;
                }
                else
                {
                    request.Error = "Could not find sessionId";
                }
            }
            catch (Exception ex)
            {
                request.Error = ex.Message;
            }
            return request;
        }
        public static UserProfileQuestionsResults FetchUserProfileQuestions(Guid SessionId)
        {
            UserProfileQuestionsResults questionResults = new UserProfileQuestionsResults();
            try
            {

                AgileMindEntities agileDB = new AgileMindEntities();

                t_LoginSession session = (from loginSession in agileDB.t_LoginSession where loginSession.LoginSessionId == SessionId && loginSession.ValidTill > DateTime.Now select loginSession).First();
                if (session != null)
                {
                    questionResults.QuestionList = agileDB.FetchQuestionAnswer_ByLoginId(session.LoginId).ToList();
                    questionResults.Success = true;
                }
                else
                {
                    questionResults.Error = "Could not find sessionId";
                }

            }
            catch (Exception ex)
            {
                questionResults.Error = ex.Message;
            }

            return questionResults;
        }
        public static bool HasUserFilledOutAnyQuestions(Guid SessionId)
        {
            AgileMindEntities agileDb = new AgileMindEntities();
            t_LoginSession loginSession = (from data in agileDb.t_LoginSession where data.LoginSessionId == SessionId && data.ValidTill > DateTime.Now select data).First();
            if (loginSession != null)
            {

                List<t_UserProfileAnswer> userAnswers = (from data in agileDb.t_UserProfileAnswer where data.LoginId == loginSession.LoginId && data.NoAnswer == false select data).ToList();
                if (userAnswers.Count > 0)
                    return true;

            }

            return false;
        }
        public static ProfileQuizQuestionRequest FetchRandomQuizQuestions(Guid SessionId, int QuestionCount)
        {
            ProfileQuizQuestionRequest request = new ProfileQuizQuestionRequest();

            try
            {
                AgileMindEntities agileDB = new AgileMindEntities();

                t_LoginSession session = (from loginSession in agileDB.t_LoginSession where loginSession.LoginSessionId == SessionId && loginSession.ValidTill > DateTime.Now select loginSession).First();
                if (session != null)
                {
                    List<vwQuestionAnswer> questionList = agileDB.FetchQuestionAnswer_ByLoginId(session.LoginId).ToList();

                    //Make sure we only get active and ones with an actual answer.
                    questionList = questionList.FindAll(delegate(vwQuestionAnswer findQA)
                    {
                        return findQA.Active && !string.IsNullOrEmpty(findQA.Answer);
                    });

                    Random rand = new Random();
                    for (int count = 0; count < QuestionCount; count++)
                    {
                        ProfileQuizQuestion newQA = new ProfileQuizQuestion();

                        int index = rand.Next(questionList.Count);
                        vwQuestionAnswer foundA = questionList[index];
                        newQA.Answer = foundA.Answer;
                        newQA.Question = foundA.Question;

                        request.QuestionList.Add(newQA);
                    }

                    request.Success = true;
                }
                else
                {
                    request.Error = "Could not find sessionId";
                }
            }
            catch (Exception ex)
            {
                request.Error = ex.Message;
            }
            return request;
        }
예제 #10
0
        public static GameResults InsertGameResultLoginId(String UserName, GameListEnum gameType, int Score, decimal TestDuration, int Total)
        {
            GameResults results = new GameResults();
            try
            {

                AgileMindEntities db = new AgileMindEntities();
                vwLoginInfo login = (from data in db.vwLoginInfoes where data.LoginName == UserName select data).Single();

                if (login != null)
                {
                    t_GameResults gameResults = new t_GameResults();
                    gameResults.Created = DateTime.Now;
                    gameResults.GameId = (int)gameType;
                    gameResults.LoginId = login.LoginId;
                    gameResults.Score = Score;
                    gameResults.TestDuration = TestDuration;
                    gameResults.Total = Total;
                    db.t_GameResults.AddObject(gameResults);
                    db.SaveChanges();

                    results.Success = true;
                    results.Game = gameResults;

                }
                else
                {
                    results.Error = "Could not login.  Invalid Username/Password";
                }

            }
            catch (Exception ex)
            {
                results.Error = ex.Message;
            }
            return results;
        }
        public static IdentifyResults FetchQuestionList(Guid SessionId)
        {
            IdentifyResults request = new IdentifyResults();

            try
            {
                AgileMindEntities agileDB = new AgileMindEntities();

                t_LoginSession session = (from loginSession in agileDB.t_LoginSession where loginSession.LoginSessionId == SessionId && loginSession.ValidTill > DateTime.Now select loginSession).First();
                if (session != null)
                {

                    List<t_Object> objectList = (from objects in agileDB.t_Object select objects).ToList();
                    List<t_ObjectImage> objectImageList = (from objectImage in agileDB.t_ObjectImage select objectImage).ToList();

                    Random randObj = new Random();
                    for (int i = 0; i < 10; i++)
                    {

                        t_Object chosenObject = objectList[randObj.Next(objectList.Count)];
                        List<t_ObjectImage> availableImages = objectImageList.FindAll(delegate(t_ObjectImage findImage) { return findImage.ObjectId == chosenObject.ObjectId; });
                        t_ObjectImage chosenImage = availableImages[randObj.Next(availableImages.Count)];
                        List<t_Object> availableAnswers = objectList.FindAll(delegate(t_Object findObject) { return findObject.ObjectId != chosenObject.ObjectId; });

                        IdentifyQuestion newQuestion = new IdentifyQuestion();
                        newQuestion.Object = chosenObject.Object;
                        newQuestion.ObjectURL = chosenImage.ImageURL;

                        IdentifyAnswer newAnswer = new IdentifyAnswer();
                        newAnswer.Answer = chosenObject.Object;
                        newAnswer.IsCorrect = true;
                        newQuestion.AnswerList.Add(newAnswer);

                        for (int addAnswers = 0; addAnswers < 3; addAnswers++)
                        {
                            newAnswer = new IdentifyAnswer();
                            t_Object randomAnswer = availableAnswers[randObj.Next(availableAnswers.Count)];
                            availableAnswers.Remove(randomAnswer);
                            newAnswer.Answer = randomAnswer.Object;
                            newQuestion.AnswerList.Add(newAnswer);
                        }
                        newQuestion.AnswerList.Shuffle();
                        newQuestion.AnswerList.Shuffle();

                        request.QuestionList.Add(newQuestion);

                    }

                    request.Success = true;
                }
                else
                {
                    request.Error = "Could not find sessionId";
                }
            }
            catch (Exception ex)
            {
                request.Error = ex.Message;
            }
            return request;
        }
        public void SaveAnswersWillUpdateTheAnswerWithSaveInformation()
        {
            AgileMindEntities agileDb = new AgileMindEntities();

            LoginResult.ValidateLogin(LOGINNAME, PASSWORD, "ip");
            AgileMind.DAL.Data.Login login = (from data in agileDb.Logins where data.LoginName == LOGINNAME select data).First();
            if (login != null)
            {
                t_LoginSession session = (from data in agileDb.t_LoginSession where data.LoginId == login.LoginId && data.ValidTill > DateTime.Now select data).First();
                if (session != null)
                {
                    UserProfileQuestionsResults results = UserProfileQuestionsResults.FetchUserProfileQuestions(session.LoginSessionId);
                    Assert.IsNotNull(results);
                    Assert.IsTrue(results.Success);
                    Assert.Greater(results.QuestionList.Count(), 0);

                    results.QuestionList[0].Answer = "12345";
                    List<vwQuestionAnswer> questionList = new List<vwQuestionAnswer>();
                    questionList.Add(results.QuestionList[0]);
                    Result saveResult = UserProfileQuestionsResults.SaveUserQuestions(questionList, session.LoginSessionId);
                    Assert.IsTrue(saveResult.Success);

                    int userProfileQuestionId = results.QuestionList[0].UserProfileQuestionId;
                    t_UserProfileAnswer savedAnswer = (from data in agileDb.t_UserProfileAnswer where data.LoginId == login.LoginId && data.UserProfileQuestionId == userProfileQuestionId select data).First();
                    Assert.IsNotNull(savedAnswer);
                    Assert.AreEqual(savedAnswer.Answer, "12345");

                    results = UserProfileQuestionsResults.FetchUserProfileQuestions(session.LoginSessionId);
                    Assert.IsTrue(results.Success);
                    vwQuestionAnswer foundView = results.QuestionList.Find(delegate(vwQuestionAnswer findView)
                    {
                        return findView.UserProfileQuestionId == userProfileQuestionId;
                    });
                    if (foundView != null)
                    {
                        if (foundView.UserProfileAnswerId != null && foundView.UserProfileAnswerId != 0)
                        {
                            questionList = new List<vwQuestionAnswer>();
                            questionList.Add(foundView);
                            foundView.Answer = "54321";

                            saveResult = UserProfileQuestionsResults.SaveUserQuestions(questionList, session.LoginSessionId);
                            Assert.IsTrue(saveResult.Success);

                            int userProfileAnswerId = foundView.UserProfileAnswerId.Value;
                            agileDb.Dispose();
                            agileDb = new AgileMindEntities();

                            savedAnswer = (from data in agileDb.t_UserProfileAnswer where data.UserProfileAnswerId == userProfileAnswerId select data).First();
                            Assert.IsNotNull(savedAnswer);
                            Assert.AreEqual(savedAnswer.Answer, "54321");

                        }
                        else
                        {
                            Assert.Fail("Did nto save with the userprofile Id");
                        }
                    }
                    else
                    {
                        Assert.Fail("Could not find the question returned back.  seriously ");
                    }

                    agileDb.DeleteObject(savedAnswer);
                    agileDb.SaveChanges();

                }
                else
                {
                    Assert.Fail("Could not find the session to begin testing.");
                }
            }
            else
            {
                Assert.Fail("Could not find the login to start testing");
            }
        }
        public void SaveAnswersWillTakeTheViewAndSaveTheInformation()
        {
            AgileMindEntities agileDb = new AgileMindEntities();

            LoginResult.ValidateLogin(LOGINNAME, PASSWORD, "ip");
            AgileMind.DAL.Data.Login login = (from data in agileDb.Logins where data.LoginName == LOGINNAME select data).First();
            if (login != null)
            {
                t_LoginSession session = (from data in agileDb.t_LoginSession where data.LoginId == login.LoginId && data.ValidTill > DateTime.Now select data).First();
                if (session != null)
                {
                    UserProfileQuestionsResults results = UserProfileQuestionsResults.FetchUserProfileQuestions(session.LoginSessionId);
                    Assert.IsNotNull(results);
                    Assert.IsTrue(results.Success);
                    Assert.Greater(results.QuestionList.Count(), 0);

                    results.QuestionList[0].Answer = "12345";
                    List<vwQuestionAnswer> questionList = new List<vwQuestionAnswer>();
                    questionList.Add(results.QuestionList[0]);
                    Result saveResult = UserProfileQuestionsResults.SaveUserQuestions(questionList, session.LoginSessionId);
                    Assert.IsTrue(saveResult.Success);

                    int userProfileQuestionId = results.QuestionList[0].UserProfileQuestionId;
                    t_UserProfileAnswer savedAnswer = (from data in agileDb.t_UserProfileAnswer where data.LoginId == login.LoginId && data.UserProfileQuestionId == userProfileQuestionId select data).First();
                    Assert.IsNotNull(savedAnswer);
                    Assert.AreEqual(savedAnswer.Answer, "12345");

                    agileDb.DeleteObject(savedAnswer);
                    agileDb.SaveChanges();

                }
                else
                {
                    Assert.Fail("Could not find the session to begin testing.");
                }
            }
            else
            {
                Assert.Fail("Could not find the login to start testing");
            }
        }
        public void LoadQuestionsReturnsAListOfQuestionsFromTheDatabase()
        {
            AgileMindEntities agileDb = new AgileMindEntities();

            LoginResult.ValidateLogin(LOGINNAME, PASSWORD, "ip");
            AgileMind.DAL.Data.Login login = (from data in agileDb.Logins where data.LoginName == LOGINNAME select data).First();
            if (login != null)
            {
                t_LoginSession session = (from data in agileDb.t_LoginSession where data.LoginId == login.LoginId && data.ValidTill > DateTime.Now select data).First();
                if (session != null)
                {
                    UserProfileQuestionsResults results = UserProfileQuestionsResults.FetchUserProfileQuestions(session.LoginSessionId);
                    Assert.IsNotNull(results);
                    Assert.IsTrue(results.Success);
                    Assert.Greater(results.QuestionList.Count(), 0);
                }
                else
                {
                    Assert.Fail("Could not find the session to begin testing.");
                }
            }
            else
            {
                Assert.Fail("Could not find the login to start testing");
            }
        }
        public static Result SaveUserQuestions(List<vwQuestionAnswer> QuestionAnswerList, Guid SessionId)
        {
            Result saveResults = new Result();

            AgileMindEntities agileDB = new AgileMindEntities();

            t_LoginSession session = (from loginSession in agileDB.t_LoginSession where loginSession.LoginSessionId == SessionId && loginSession.ValidTill > DateTime.Now select loginSession).First();
            if (session != null)
            {
                List<t_UserProfileAnswer> answerList = (from data in agileDB.t_UserProfileAnswer where data.LoginId == session.LoginId select data).ToList();

                foreach (vwQuestionAnswer questionAnswer in QuestionAnswerList)
                {
                    if (questionAnswer.UserProfileAnswerId == null || questionAnswer.UserProfileAnswerId == 0)
                    {
                        t_UserProfileAnswer newAnswer = new t_UserProfileAnswer();
                        newAnswer.Answer = questionAnswer.Answer;
                        newAnswer.Created = DateTime.Now;
                        newAnswer.LoginId = session.LoginId;
                        newAnswer.UserProfileQuestionId = questionAnswer.UserProfileQuestionId;
                        if (questionAnswer.NoAnswer.HasValue)
                        {
                            newAnswer.NoAnswer = questionAnswer.NoAnswer.Value;
                        }
                        else
                        {
                            newAnswer.NoAnswer = false;
                        }
                        agileDB.t_UserProfileAnswer.AddObject(newAnswer);
                    }
                    else
                    {
                        t_UserProfileAnswer foundAnswer = (from data in agileDB.t_UserProfileAnswer where data.UserProfileAnswerId == questionAnswer.UserProfileAnswerId select data).First();

                        if (foundAnswer != null)
                        {
                            foundAnswer.Answer = questionAnswer.Answer;

                            if (questionAnswer.NoAnswer.HasValue)
                            {
                                foundAnswer.NoAnswer = questionAnswer.NoAnswer.Value;
                            }
                            else
                            {
                                foundAnswer.NoAnswer = false;
                            }

                        }
                    }
                }

                agileDB.SaveChanges();

                saveResults.Success = true;
            }
            else
            {
                saveResults.Error = "Could not find session";
            }

            return saveResults;
        }