Example #1
0
        // gets admin email
        /* 
        internal static string GetUserMail(string userName)
        {
            var loggedInUserMail =
                (from User user in Database
                 where user.userName == userName
                 select user.Email).FirstOrDefault();
            return loggedInUserMail;
        }*/

        /// <summary>
        /// Creates some test data
        /// </summary>
        /// <param name="dbFileName"></param>
        public static void LoadTestData(string dbFileName)
        {
            var questionnaire1 = new Questionnaire("Q1", "Test questionnaire");
            
            var choiceOpt1 = new TextChoice("Yes", 1);
            var choiceOpt2 = new TextChoice("No", 2);
            var choiceOpt3 = new TextChoice("Maybe", 3);
            var choiceList1 = new List<Choice>();
            choiceList1.Add(choiceOpt1);
            choiceList1.Add(choiceOpt2);
            choiceList1.Add(choiceOpt3);

            var question1 = new ChoiceQuestion("Is this a test?", choiceList1);
            question1.QuestionId = Guid.NewGuid();
            
            questionnaire1.Questions.Add(question1);

            var choiceOpt4 = new NumberChoice(1, 1);
            var choiceOpt5 = new NumberChoice(2, 2);
            var choiceOpt6 = new NumberChoice(100, 3);

            var choiceList2 = new List<Choice>();
            choiceList2.Add(choiceOpt4);
            choiceList2.Add(choiceOpt5);
            choiceList2.Add(choiceOpt6);

            var question2 = new ChoiceQuestion("How many tests are there in this application?", choiceList2);
            question2.QuestionId = Guid.NewGuid();
            questionnaire1.Questions.Add(question2);

            var questionnaire2 = new Questionnaire("Q2", "Public opinion on Statis testing");

            var question3 = new TextQuestion("What do you think about testing?");
            question3.QuestionId = Guid.NewGuid();
            questionnaire2.Questions.Add(question3);

            var question4 = new TextQuestion("Do you think Statis should have a logo?");
            question4.QuestionId = Guid.NewGuid();
            questionnaire2.Questions.Add(question4);

            var img = new object();
            img = null;
            
            var choiceOpt7 = new TextChoice("Yes, why not", 1);
            var choiceOpt8 = new TextChoice("I don't care", 2);
            var choiceOpt9 = new TextChoice("No, it looks ugly", 3);

            var choiceList3 = new List<Choice>();
            choiceList3.Add(choiceOpt7);
            choiceList3.Add(choiceOpt8);
            choiceList3.Add(choiceOpt9);

            var question5 = new ImgChoiceQuestion("Should it be this logo?", img, choiceList3);
            question5.QuestionId = Guid.NewGuid();

            questionnaire2.Questions.Add(question5);

            var filledQuestionnaire1 = new FilledQuestionnaire(questionnaire1);
            var answer1 = new SingleChoiceAnswer
                              {
                                  Choice = 1
                              };
            var answer2 = new SingleChoiceAnswer
                              {
                                  Choice = 3
                              };
            filledQuestionnaire1.Answers.Add(answer1);
            filledQuestionnaire1.Answers.Add(answer2);

            var filledQuestionnaire2 = new FilledQuestionnaire(questionnaire2);
            var answer3 = new TextAnswer("I love testing");
            var answer4 = new TextAnswer("Definitely");
            var answer5 = new SingleChoiceAnswer
                              {
                                  Choice = 3
                              };

            filledQuestionnaire2.Answers.Add(answer3);
            filledQuestionnaire2.Answers.Add(answer4);
            filledQuestionnaire2.Answers.Add(answer5);

            var admin = new Administrator("jb", "Jānis", "Bērziņš", "*****@*****.**", "go");
            var questionnaires = new List<Questionnaire>();
            questionnaires.Add(questionnaire1);
            questionnaires.Add(questionnaire2);
            admin.Questionnaires = questionnaires;


            var user2 = new Analyst("SysAnal", "A", "B", "*****@*****.**", "go");

            admin.TrustedAnalysts = new List<Analyst>();
            admin.TrustedAnalysts.Add(user2);

            admin.Respondents = new List<User>();
            
            var db = GetDb(dbFileName);
            db.Store(admin);
            db.Store(user2);
            //db.Store(questionnaire1);
            //db.Store(questionnaire2);
            //db.Store(filledQuestionnaire1);
            //db.Store(filledQuestionnaire2);
            db.Close();
        }
Example #2
0
 public bool RegisterUser(string userName, string password, string firstName, string lastName, string email)
 {
     var user = new Analyst(userName, firstName, lastName, email, password);
     return HandleDb4o.RegisterAnalyst(user);
 }
Example #3
0
        public static bool RegisterAnalyst(Analyst analyst)
        {
            var alreadyRegisteredUser =
            (from Analyst user in Database
             where user.UserName == analyst.UserName
             select user).FirstOrDefault();

            if (alreadyRegisteredUser == null)
            {
                Database.Store(analyst);
                return true;
            }

            return false;
        }