Beispiel #1
0
        public static List <Model.QnA> GenerateQnA(string quizId, string courseId, string lessonName, string username)
        {
            var result = new List <Model.QnA>();

            try
            {
                IDataProvider data   = new MongoDataProvider();
                var           course = data.Get <DAL.Course>("_id", courseId);

                var quiz = data.Get <DAL.Quiz>("_id", quizId);

                Model.QnA source = null;
                if (quiz.Type == "Upisivanje")
                {
                    source = new Model.QnAUpisivanje();
                }
                else if (quiz.Type == "Izbor")
                {
                    source = new Model.QnAIzbor();
                }
                else if (quiz.Type == "VišestrukiIzbor")
                {
                    source = new Model.QnAVisestruki();
                }
                else
                {
                    result = null;
                }
                return(source.GenerateQnA(course, username, lessonName, quiz));
            }
            catch (Exception)
            {
                return(null);
            }
        }
Beispiel #2
0
        public static string CheckToken(string token)
        {
            IDataProvider data = new MongoDataProvider();
            // Fetch session from DB
            var session = data.Get <Session>("Id", token);

            // if there is any, check TTE
            if (session != null && session.Id != "")
            {
                // if TTE is alright, return email of the current user
                if (session.TTE > DateTime.Now)
                {
                    return(session.Email);
                }
                else
                {
                    DeleteToken(token);
                    return("");
                }
            }
            else
            {
                return("");
            }
        }
Beispiel #3
0
        public void GetDALUser()
        {
            IDataProvider data = new MongoDataProvider();

            Model.User ModelUser = data.Get <DAL.User>("Email", "*****@*****.**");
            Assert.AreEqual(ModelUser.Email, "*****@*****.**");
        }
Beispiel #4
0
    public async Task GetShouldRetrieveAllQuestions()
    {
        await SetupTestQuestions();

        var result = await _provider.Get(-1, 0, null);

        Assert.AreEqual(4, result.Count);
    }
Beispiel #5
0
 public static Course GetCourse(string id)
 {
     try
     {
         var           course = new Course();
         IDataProvider data   = new MongoDataProvider();
         course.ModelCourse = data.Get <DAL.Course>("_id", id);
         return(course);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Beispiel #6
0
 public static Word GetWord(string wordId)
 {
     try
     {
         IDataProvider data = new MongoDataProvider();
         var           word = new Word();
         word.ModelWord = data.Get <DAL.Word>("_id", wordId);
         return(word);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Beispiel #7
0
 public static User Get(string email)
 {
     try
     {
         IDataProvider data = new MongoDataProvider();
         var           user = new User();
         user.ModelUser = data.Get <DAL.User>("Email", email);
         return(user);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Beispiel #8
0
        public static bool SubscribeUserToCourse(string userMail, string courseId)
        {
            try
            {
                var           course = new Course();
                IDataProvider data   = new MongoDataProvider();
                course.ModelCourse = data.Get <DAL.Course>("_id", courseId);

                // Obrati pozornost na to da ne želiš da ti se korisnik može subscribeat 2x
                if (course.ModelCourse.Subscribed.Contains(userMail))
                {
                    return(true);
                }
                return(DAL.Course.SubscribeUser(userMail, courseId));
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #9
0
        public static bool UnsubscribeUserFromCourse(string userMail, string courseId)
        {
            try
            {
                var           course = new Course();
                IDataProvider data   = new MongoDataProvider();
                course.ModelCourse = data.Get <DAL.Course>("_id", courseId);

                // Ne bi trebao biti slučaj, ali ako korisnik nije subscribean onda je sve ok
                if (!course.ModelCourse.Subscribed.Contains(userMail))
                {
                    return(true);
                }
                return(DAL.Course.UnsubscribeUser(userMail, courseId));
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #10
0
        public string Login()
        {
            IDataProvider data = new MongoDataProvider();
            // Get the user info
            var user = data.Get <DAL.User>("Email", Email);

            // Now hashing the given password and compare hashes
            string hash = Hasher.GetHash(Password, user.Basil);

            // Correct - setup token
            if (user.Password == hash)
            {
                string sessionToken = GetToken(user.Email);
                return(sessionToken);
            }
            // False - return error
            else
            {
                return("");
            }
        }
Beispiel #11
0
        public static bool AddLessonToCourse(string courseId, Model.Lesson lesson)
        {
            try
            {
                var           course = new Course();
                IDataProvider data   = new MongoDataProvider();
                course.ModelCourse = data.Get <DAL.Course>("_id", courseId);

                // ne smiju biti 2 lekcije istog imena
                foreach (var courseLesson in course.ModelCourse.Lessons)
                {
                    if (courseLesson.Name == lesson.Name)
                    {
                        throw new Exception("AlreadyExists");
                    }
                }

                return(DAL.Course.AddLesson(lesson, courseId));
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #12
0
 public void NotNullCollections()
 {
     var provider = MongoDataProvider.Get("MessageBoard");
     var test     = provider.GetCollection("MessageBoard");
 }
Beispiel #13
0
 public void TestMethod1()
 {
     Assert.IsNotNull(MongoDataProvider.Get("MessageBoard"));
 }