Пример #1
0
 /// <summary>
 /// Retrieves all notes from DB for a single course
 /// </summary>
 /// <param name="courseId">Id of course</param>
 /// <returns>Notes for course</returns>
 private static IEnumerable <Note> GetCourseNotesFromDb(int courseId)
 {
     using (var db = new NotifyLocalDBEntities())
     {
         return(db.Notes.Where(notes => notes.courseId.Equals(courseId)).ToList());
     }
 }
Пример #2
0
 /// <summary>
 /// Get the course name of a course from its ID
 /// </summary>
 /// <param name="courseId">id of course to get its name</param>
 /// <returns>Name of id's course</returns>
 private static string GetCourseNameById(int courseId)
 {
     using (var db = new NotifyLocalDBEntities())
     {
         return((
                    from data in db.Courses
                    where data.courseId.Equals(courseId)
                    select data.courseName).FirstOrDefault());
     }
 }
Пример #3
0
 public void WriteNoteDataToDb()
 {
     using (var db = new NotifyLocalDBEntities())
     {
         db.Notes.Add(new Note
         {
             portalNoteId   = CourseId,
             courseId       = CourseId,
             noteName       = new Random().Next().ToString() + DateTime.Now,
             dateDownloaded = DateTime.Now,
             //complete it later
         });
     }
 }
Пример #4
0
        public void WriteCourseDataToDb()
        {
            using (var db = new NotifyLocalDBEntities())
            {
                var cours = new Cours
                {
                    courseName     = Name,
                    portalCourseId = Id,
                    dateAdded      = DateTime.Now,
                    userId         = UserId
                };
                db.Courses.Add(cours);

                db.SaveChanges();
            }
        }
Пример #5
0
        private static void AddCourseToDb(CourseCreator courseData)
        {
            #region WRITE COURSE DATA TO DB

            using (var db = new NotifyLocalDBEntities())
            {
                var newCourse = new Models.Cours()
                {
                    courseName     = courseData.Name,
                    portalCourseId = courseData.Id,
                    userId         = Properties.Settings.Default.UserId
                };

                db.Courses.Add(newCourse);
                db.SaveChanges();
            }

            #endregion WRITE COURSE DATA TO DB
        }
Пример #6
0
        private void AddNoteToDb(CourseCreator courseData, string noteName, string downloadLink)
        {
            using (var db = new NotifyLocalDBEntities())
            {
                #region WRITE NOTE DATA TO DB

                var newCourseNote = new Models.Note
                {
                    courseId       = courseData.Id,
                    noteCustomPath = noteName,
                    dateDownloaded = DateTime.Now,
                    portalNoteId   = Convert.ToInt32(downloadLink.Split('=')[1])
                };

                newCourseNote.noteName = _parser.GetHtmlOfTagContainingKeyword("a", newCourseNote.portalNoteId.ToString()).FirstOrDefault();

                db.Notes.Add(newCourseNote);

                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    #region LOGGING

                    foreach (var eve in ex.EntityValidationErrors)
                    {
                        Trace.WriteLine($"Entity of type \"{eve.Entry.Entity.GetType().Name}\" in state \"{eve.Entry.State}\" has the following validation errors:");

                        foreach (var ve in eve.ValidationErrors)
                        {
                            Trace.WriteLine($"- Property: \"{ve.PropertyName}\", Error: \"{ve.ErrorMessage}\"");
                        }
                    }

                    #endregion LOGGING
                }

                #endregion WRITE NOTE DATA TO DB
            }
        }