Esempio n. 1
0
        public static bool UpdateLesson(Model.Lesson lesson, string courseId)
        {
            try
            {
                ObjectId id = new ObjectId(courseId);

                var dataProvider = new MongoDataProvider();
                var db           = dataProvider.GetDatabase();
                var collection   = db.GetCollection <Course>("Course");

                var filter = Builders <Course> .Filter.And(
                    Builders <Course> .Filter.Where(c => c._id == id),
                    Builders <Course> .Filter.ElemMatch(c => c.Lessons, l => l.Name == lesson.Name));

                var update = Builders <Course> .Update.Set(c => c.Lessons[-1], lesson);

                var result = collection.UpdateOne(filter, update);
                if (result.ModifiedCount == 1)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 2
0
        public static string CreateCourse(Course newCourse)
        {
            IDataProvider data = new MongoDataProvider();

            newCourse = data.Create(newCourse);
            return(newCourse._id.ToString());
        }
Esempio n. 3
0
        public static bool SubscribeUser(string email, string courseId)
        {
            try
            {
                ObjectId id = new ObjectId(courseId);

                var dataProvider = new MongoDataProvider();
                var db           = dataProvider.GetDatabase();
                var collection   = db.GetCollection <Course>("Course");

                var filter = Builders <Course> .Filter.Where(x => x._id == id);

                var update = Builders <Course> .Update.AddToSet(x => x.Subscribed, email);

                var result = collection.UpdateOne(filter, update);
                if (result.ModifiedCount == 1)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 4
0
 public bool Create()
 {
     try
     {
         var dataProvider = new MongoDataProvider();
         var db           = dataProvider.GetDatabase();
         var collection   = db.GetCollection <Session>("Session");
         _id = ObjectId.GenerateNewId();
         Id  = _id.ToString();
         collection.InsertOne(this);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Esempio n. 5
0
        public static Model.QnA GetQnA(string courseId, string lessonName, string username, int orderNo)
        {
            try
            {
                var data       = new MongoDataProvider();
                var db         = data.GetDatabase();
                var collection = db.GetCollection <Model.QnA>("QnA");

                var wanted = collection.Find(q => q.CourseId == courseId &&
                                             q.LessonName == lessonName &&
                                             q.Username == username &&
                                             q.OrderNo == orderNo).First();
                return(wanted);
            }
            catch (Exception)
            {
                return(null);
            }
        }