public CourseBO Get(int id)
        {
            using (var uow = _facade.UnitOfWork) {
                CourseBO course       = null;
                var      courseFromDb = uow.CourseRepo.Get(id);
                if (courseFromDb != null)
                {
                    var convCat = _catConv.Convert(courseFromDb.Category);

                    var creatorConverted = _userConv.Convert(courseFromDb.Creator);

                    //var convSecs = courseFromDb.Sections?.Select(s => _secConverter.Convert(s)).ToList();
                    course          = ConvertCourseWithSectionsAndLessons(courseFromDb);
                    course.Category = convCat;
                    course.Creator  = creatorConverted;

                    // we cant use orderby in query via entity framework since we get lessons via include
                    // so we gotta sort after the query is done
                    foreach (var section in course.Sections)
                    {
                        var sortedLessons = section.Lessons.OrderBy(l => l.ListIndex).ToList();
                        section.Lessons = sortedLessons;
                    }
                    var sortedUndistributedLessons = course.Lessons.OrderBy(l => l.ListIndex).ToList();
                    course.Lessons = sortedUndistributedLessons;
                }
                return(course);
            }
        }
        private Course ConvertCourseWithSectionsAndLessons(CourseBO course)
        {
            var materialConverted     = course.Lessons?.Select(l => _lesConv.Convert(l)).ToList();
            var listSectionsConverted = new List <Section>();

            if (course.Sections != null)
            {
                foreach (var section in course.Sections)
                {
                    //sections
                    if (section.Lessons != null)
                    {
                        var listLessonsConverted = new List <Lesson>();
                        foreach (var lesson in section.Lessons)
                        {
                            //lessons
                            var lessonConverted = _lesConv.Convert(lesson);
                            listLessonsConverted.Add(lessonConverted);
                        }
                        var convertedSection = _secConverter.Convert(section);
                        convertedSection.Lessons = listLessonsConverted;
                        listSectionsConverted.Add(convertedSection);
                    }
                }
            }
            var courseEntity = _crsConv.Convert(course);

            courseEntity.Sections = listSectionsConverted;
            courseEntity.Lessons  = materialConverted;
            return(courseEntity);
        }
 public CourseBO Create(CourseBO course)
 {
     using (var uow = _facade.UnitOfWork)
     {
         var fullyConvertedCourse = ConvertCourseWithSectionsAndLessons(course);
         var courseCreated        = uow.CourseRepo.Create(fullyConvertedCourse);
         uow.Complete();
         return(_crsConv.Convert(courseCreated));
     }
 }
Exemple #4
0
        public ActionResult DeleteEduCourse(int?Id)
        {
            var result = new CourseBO().DeleteEduCourse(new Course {
                Id = Id.Value
            });

            var list = new CourseBO().GetList();

            return(View("CourseList", list));
        }
Exemple #5
0
        public RedirectToRouteResult SaveCourse(Course course)
        {
            course.CourseDescription = course.CourseName;
            course.CreatedBy         = USER_ID;
            course.CreatedOn         = UTILITY.SINGAPORETIME;
            course.ModifiedBy        = USER_ID;
            course.ModifiedOn        = UTILITY.SINGAPORETIME;
            course.AvailableSeats    = 0;
            var result = new CourseBO().SaveCouse(course);

            return(RedirectToAction("CourseList"));
        }
        public ActionResult <CourseBO> Put(int id, [FromBody] CourseBO course)
        {
            if (course == null)
            {
                return(BadRequest());
            }
            int idFromJwt = new JwtHelper().GetUserIdFromToken(Request);

            if (idFromJwt != course.CreatorId)
            {
                return(BadRequest());
            }
            course.Id = id;
            return(Ok(_courseService.Update(course)));
        }
Exemple #7
0
 public Course Convert(CourseBO course)
 {
     if (course == null)
     {
         return(null);
     }
     return(new Course()
     {
         Id = course.Id,
         Name = course.Name,
         CategoryId = course.CategoryId,
         CreatorId = course.CreatorId,
         Users = course.UserIds?.Select(sId => new UserCourse()
         {
             CourseId = course.Id,
             UserID = sId
         }).ToList(),
         Description = course.Description,
         Published = course.Published,
     });
 }
Exemple #8
0
        public ViewResult CourseDetail(int id)
        {
            CourseDetail  courseDetail = null;
            List <Course> courseData   = new List <Course>();

            if (id == -1)
            {
                courseDetail = new CourseDetail
                {
                    Id        = id,
                    StartDate = DateTime.Now,
                    EndDate   = DateTime.Now,
                    Course    = -1
                }
            }
            ;
            else
            {
                courseDetail = new CourseDetailBO()
                               .GetCourseDetail(new CourseDetail {
                    Id = id
                });

                courseData = new CourseBO().GetCoursesByProduct(courseDetail.Product);
            }

            var courseDetailVm = new CourseDetailVm {
                courseDetail   = courseDetail,
                countryList    = new CountryBO().GetList(),
                MonthData      = GetMonthData(),
                EduProductData = new EduProductBO().GetList(),
                CourseData     = courseData
            };

            return(View("CourseDetail", courseDetailVm));
        }
        public CourseBO Update(CourseBO course)
        {
            using (var uow = _facade.UnitOfWork)
            {
                List <SectionBO> sections = new List <SectionBO>(course.Sections);
                var courseFromDb          = uow.CourseRepo.Get(course.Id);
                if (courseFromDb == null)
                {
                    return(null);
                }
                var courseConverted = ConvertCourseWithSectionsAndLessons(course);

                courseFromDb.Name        = courseConverted.Name;
                courseFromDb.CategoryId  = courseConverted.CategoryId;
                courseFromDb.Description = courseConverted.Description;

                //1. Remove All, except the "old" ids we
                //      wanna keep (Avoid attached issues)
                courseFromDb.Sections.RemoveAll(
                    sDb => !courseConverted.Sections.Exists(
                        s => s.Id == sDb.Id));

                //2. Remove All ids already in database
                //      from customerUpdated
                courseConverted.Sections.RemoveAll(
                    s => courseFromDb.Sections.Exists(
                        sDb => s.Id == sDb.Id));

                //3. Add All new CustomerAddresses not
                //      yet seen in the DB
                foreach (var item in courseConverted.Sections)
                {
                    item.Lessons.Clear();
                }
                courseFromDb.Sections.AddRange(courseConverted.Sections);
                // got error when -> upload new video -> create new section -> place new video in new section -> save changes
                // dirty solution
                uow.Complete();

                List <Section> sectionsConverted = ConvertSections(sections);
                for (int i = 0; i < courseFromDb.Sections.Count(); i++)// var sectionDirty in courseFromDb.Sections) {
                {
                    //1.
                    courseFromDb.Sections[i].Lessons.RemoveAll(
                        lD => !sectionsConverted[i].Lessons.Exists(
                            l => l.Id == lD.Id));

                    //2.
                    //remove all unmoved lessosn
                    sectionsConverted[i].Lessons.RemoveAll(
                        l => courseFromDb.Sections[i].Lessons.Exists(
                            l2 => l.Id == l2.Id));
                    //3.
                    //update all moved lessons section id individually
                    foreach (var item in sectionsConverted[i].Lessons)
                    {
                        var lessonFromDb = uow.LessonRepo.Get(item.Id);
                        lessonFromDb.CourseId  = null;
                        lessonFromDb.SectionId = courseFromDb.Sections[i].Id;
                    }
                }
                //1. Remove All, except the "old" ids we
                //      wanna keep (Avoid attached issues)
                courseFromDb.Lessons.RemoveAll(
                    lDb => !courseConverted.Lessons.Exists(
                        l => l.Id == lDb.Id));

                //2. Remove All ids already in database
                //      from customerUpdated
                courseConverted.Lessons.RemoveAll(
                    l => courseFromDb.Lessons.Exists(
                        lDb => l.Id == lDb.Id));

                //3. Add All new CustomerAddresses not
                //      yet seen in the DB
                foreach (var item in courseConverted.Lessons)
                {
                    var lessonFromDb = uow.LessonRepo.Get(item.Id);
                    lessonFromDb.CourseId = null;
                    lessonFromDb.CourseId = courseFromDb.Id;
                }
                uow.Complete();
                // here the ListIndex of all lessons is set on the updated course
                var updatedCourseFromDb = uow.CourseRepo.Get(course.Id);
                for (int i = 0; i < updatedCourseFromDb.Sections.Count(); i++)
                {
                    var section = updatedCourseFromDb.Sections[i];
                    for (int j = 0; j < section.Lessons.Count(); j++)
                    {
                        var lessonFromDb = section.Lessons[j];
                        var lesson       = course.Sections[i].Lessons.FirstOrDefault(l => l.Id == lessonFromDb.Id);
                        lessonFromDb.ListIndex = lesson.ListIndex;
                    }
                }

                for (int i = 0; i < updatedCourseFromDb.Lessons.Count(); i++)
                {
                    var lessonFromDb = updatedCourseFromDb.Lessons[i];
                    var lesson       = course.Lessons.FirstOrDefault(l => l.Id == lessonFromDb.Id);
                    lessonFromDb.ListIndex = lesson.ListIndex;
                }
                uow.Complete();
                return(_crsConv.Convert(courseFromDb));
            }
        }
Exemple #10
0
        public JsonResult GetCoursesByProduct(int Id)
        {
            var courseList = new CourseBO().GetCoursesByProduct(Id);

            return(Json(courseList, JsonRequestBehavior.AllowGet));
        }
Exemple #11
0
        public ViewResult CourseList()
        {
            var list = new CourseBO().GetList().AsEnumerable();

            return(View("CourseList", list));
        }
Exemple #12
0
        public void SeedData()
        {
            #region User creation
            var user = new UserRegisterDto()
            {
                Username = "******",
                Password = "******"
            };
            var userCreated = _authService.Register(user);

            var educator = new UserRegisterDto()
            {
                Username = "******",
                Password = "******"
            };

            var educatorCreated = _authService.Register(educator);

            _userService.Promote(educatorCreated.Id);

            var admin = new UserRegisterDto()
            {
                Username = "******",
                Password = "******"
            };

            _userService.Promote(_userService.Promote(_userService.Promote(_authService.Register(admin).Id).Id).Id);
            List <int> userIds = new List <int>();
            userIds.Add(userCreated.Id);

            var category = new CategoryBO()
            {
                Name = "Math"
            };
            #endregion

            var favCategory = _catService.Create(category);

            #region Building course
            var lessons = new List <LessonBO>();
            for (int i = 0; i < 20; i++)
            {
                var lesson = new LessonBO()
                {
                    Title   = "Hello" + i,
                    VideoId = "dogs.mp4"
                };
                lessons.Add(lesson);
            }
            var section = new SectionBO()
            {
                Title   = "Everyone likes dogs",
                Lessons = lessons
            };

            var lesson1ForSection2 = new LessonBO()
            {
                Title   = "Lesson 2 title",
                VideoId = "long.mp4"
            };
            var otherlessons = new List <LessonBO>();
            otherlessons.Add(lesson1ForSection2);
            var section2 = new SectionBO()
            {
                Title   = "Long video",
                Lessons = otherlessons
            };

            var lesson1ForSection3 = new LessonBO()
            {
                Title   = "Lesson 1 title",
                VideoId = "dogs.mp4"
            };
            var section3Lessons = new List <LessonBO>();
            section3Lessons.Add(lesson1ForSection3);
            var section3 = new SectionBO()
            {
                Title   = "Section 3",
                Lessons = section3Lessons
            };

            var sections = new List <SectionBO>();
            sections.Add(section);
            sections.Add(section2);
            //sections.Add(section3);

            var material = new List <LessonBO>();
            material.Add(new LessonBO()
            {
                VideoId = "dogs.mp4",
                Title   = "Dogs"
            });
            material.Add(new LessonBO()
            {
                VideoId = "long.mp4",
                Title   = "Long"
            });


            var course = new CourseBO()
            {
                Name        = " Building Course",
                UserIds     = userIds,
                CategoryId  = favCategory.Id,
                Sections    = sections,
                CreatorId   = educatorCreated.Id,
                Published   = true,
                Description = "Your body can’t digest corn. So if you ate literally nothing but corn every day you’d reach the point where you’re s******g out pure corn and then you’ve got an infinite food source.",
                Lessons     = material
            };
            _courseService.Create(course);
            #endregion

            #region filler courses
            for (int i = 0; i < 50; i++)
            {
                bool published = true;
                if (i % 10 == 0)
                {
                    published = false;
                    // crsUserIds.Add(userCreated.Id);
                }

                List <int> crsUserIds = new List <int>();
                if ((i + 1) % 2 == 0)
                {
                    crsUserIds.Add(userCreated.Id);
                }
                if ((i + 1) % 13 == 0)
                {
                    crsUserIds.Add(educatorCreated.Id);
                }
                string flower = "flower";
                if (i > 1 || i < 1)
                {
                    flower += "s";
                }
                var crs = new CourseBO()
                {
                    Name = " Course" + i,

                    CreatorId   = educatorCreated.Id,
                    UserIds     = crsUserIds,
                    CategoryId  = favCategory.Id,
                    Description = i + " " + flower + " in the garden",
                    Published   = published
                };

                _courseService.Create(crs);
            }
            #endregion

            #region categories

            var cat_1 = new CategoryBO()
            {
                Name = "Electronics"
            };
            var cat_2 = new CategoryBO()
            {
                Name = "Business "
            };
            var cat_3 = new CategoryBO()
            {
                Name = "Robotics"
            };
            var cat_4 = new CategoryBO()
            {
                Name = "Graphic Design"
            };
            var cat_5 = new CategoryBO()
            {
                Name = "Information Technology"
            };
            var cat_6 = new CategoryBO()
            {
                Name = "English"
            };
            var cat_7 = new CategoryBO()
            {
                Name = "Spanish"
            };
            var cat_8 = new CategoryBO()
            {
                Name = "Visual Arts"
            };
            var cat_9 = new CategoryBO()
            {
                Name = "Marketing"
            };
            var cat_10 = new CategoryBO()
            {
                Name = "Productivity"
            };
            var cat_11 = new CategoryBO()
            {
                Name = "Leadership"
            };

            var cat1  = _catService.Create(cat_1);
            var cat2  = _catService.Create(cat_2);
            var cat3  = _catService.Create(cat_3);
            var cat4  = _catService.Create(cat_4);
            var cat5  = _catService.Create(cat_5);
            var cat6  = _catService.Create(cat_6);
            var cat7  = _catService.Create(cat_7);
            var cat8  = _catService.Create(cat_8);
            var cat9  = _catService.Create(cat_9);
            var cat10 = _catService.Create(cat_10);
            var cat11 = _catService.Create(cat_11);

            #endregion
        }