Example #1
0
        public IQueryable <Achievement> GetAllAchievements()
        {
            var ctx = new MimoDbContext();

            using var transaction = ctx.Database.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted);
            return(ctx.Achievements);
        }
Example #2
0
        public IQueryable <UserLesson> GetUserLessonsByUserGuid(string userGuid)
        {
            var ctx = new MimoDbContext();

            using var transaction = ctx.Database.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted);
            return(ctx.UserLessons.Include(x => x.Lesson).ThenInclude(x => x.Chapter).ThenInclude(x => x.Course).Include(x => x.User).Where(x => x.User.UserGuid == userGuid));
        }
Example #3
0
        public User GetUserByGuid(string userGuid)
        {
            var ctx = new MimoDbContext();

            using var transaction = ctx.Database.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted);
            return(ctx.Users.FirstOrDefault(x => x.UserGuid == userGuid));
        }
Example #4
0
        public IQueryable <Chapter> GetChapters()
        {
            var ctx = new MimoDbContext();

            using var transaction = ctx.Database.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted);
            return(ctx.Chapters.Include(x => x.Lessons));
        }
Example #5
0
        public Course GetCorseById(int?id)
        {
            var ctx = new MimoDbContext();

            using var transaction = ctx.Database.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted);
            return(ctx.Courses.Include(x => x.Chapters).FirstOrDefault(x => x.Id == id));
        }
Example #6
0
        public static void Seed()
        {
            var ctx = new MimoDbContext();

            if (!ctx.Database.EnsureCreated())
            {
                return;
            }
            try

            {
                //Achievements
                for (int i = 0; i < AchievementList.Count; i++)
                {
                    ctx.Add(AchievementList[i]);
                }
                var result = ctx.SaveChanges();
                if (result <= 0)
                {
                    throw new Exception();
                }

                //Courses
                for (int CourseIndex = 0; CourseIndex < CourseName.Count; CourseIndex++)
                {
                    var Course = new Course {
                        Name = CourseName[CourseIndex]
                    };
                    ctx.Add(Course);
                    result = ctx.SaveChanges();
                    if (result <= 0)
                    {
                        throw new Exception();
                    }
                    for (int chapterIndex = 0; chapterIndex < ChapterName.Count; chapterIndex++)
                    {
                        var chapter = new Chapter
                        {
                            CourseId = Course.Id,
                            Name     = ChapterName[chapterIndex],
                            Order    = chapterIndex + 1
                        };
                        ctx.Add(chapter);
                        result = ctx.SaveChanges();
                        if (result <= 0)
                        {
                            throw new Exception();
                        }
                        for (int lessonIndex = 0; lessonIndex < ChapterName.Count; lessonIndex++)
                        {
                            var lesson = new Lesson
                            {
                                ChapterId = chapter.Id,
                                Text      = RandomString(),
                                Order     = lessonIndex + 1,
                            };
                            ctx.Add(lesson);
                        }
                    }
                }
                result = ctx.SaveChanges();
                if (result <= 0)
                {
                    throw new Exception();
                }

                //Results
                for (int i = 0; i < UserGuid.Count; i++)
                {
                    ctx.Add(new User {
                        UserGuid = UserGuid[i]
                    });
                }
                result = ctx.SaveChanges();
                if (result <= 0)
                {
                    throw new Exception();
                }

                for (int userId = 0; userId < UserGuid.Count; userId++)
                {
                    //random.Next(1, 60) take random lessons quantity
                    for (int countLessons = 0; countLessons < random.Next(1, 60); countLessons++)
                    {
                        var userLesson = GetRandomUserLesson(userId);
                        ctx.Add(userLesson);

                        //take random number of one lesson starting
                        for (int countSameLessons = 0; countSameLessons < random.Next(1, 50); countSameLessons++)
                        {
                            ctx.Add(GetRandomUserLesson(userId, userLesson.LessonId));
                        }
                    }
                }
                result = ctx.SaveChanges();
                if (result <= 0)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }