示例#1
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();
            }
        }
示例#2
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
        }
示例#3
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
            }
        }