Esempio n. 1
0
        public async Task <UserLesson> InsertUserLesson(UserLesson userLesson)
        {
            context.UserLessons.Add(userLesson);
            await context.SaveChangesAsync();

            return(userLesson);
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,UserId,LessonId")] UserLesson userLesson)
        {
            if (id != userLesson.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(userLesson);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserLessonExists(userLesson.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LessonId"] = new SelectList(_context.Lessons, "Id", "Id", userLesson.LessonId);
            ViewData["UserId"]   = new SelectList(_context.Users, "Id", "Password", userLesson.UserId);
            return(View(userLesson));
        }
        public async Task <UserLesson> InsertUserLesson(UserLesson userLesson)
        {
            userLesson = await courseRepo.InsertUserLesson(userLesson);
            await HandleLessonAchievements(userLesson);

            return(userLesson);
        }
        public async Task <IActionResult> PutUserLesson(int id, UserLesson userLesson)
        {
            if (id != userLesson.Id)
            {
                return(BadRequest());
            }

            _context.Entry(userLesson).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserLessonExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <int> > PostLesson([FromBody] PostLessonVM postLessonVM)
        {
            try
            {
                var userId = GetUserIdFromToken();

                var userLessonToAdd = new UserLesson()
                {
                    LessonId       = postLessonVM.LessonId,
                    StartDate      = postLessonVM.StartDate,
                    CompletionDate = postLessonVM.CompletionDate,
                    UserId         = userId
                };

                UserLesson userLesson = await lessonService.InsertUserLesson(userLessonToAdd);

                userLesson.Lesson = null;

                return(StatusCode(StatusCodes.Status201Created, userLesson));
            }
            catch (Exception e)
            {
                logger.LogError(e, errorMessage);
                return(StatusCode(StatusCodes.Status500InternalServerError, errorMessage));
            }
        }
Esempio n. 6
0
        public async Task <UserLesson> PostUserLesson(UserLesson lesson)
        {
            var updated = _store.UserLessons.Update(lesson);
            var saved   = await _store.SaveChangesAsync();

            return(updated.Entity);
        }
Esempio n. 7
0
        public void RemoveUserMissLesson()
        {
            var userId     = Request.Form.GetValues("userId")[0];
            var lessonId   = Request.Form.GetValues("lessonId")[0];
            var userLesson = new UserLesson(lessonId, userId);

            this.lessonRepository.RemoveUserMissLesson(userLesson);
        }
Esempio n. 8
0
        public async Task <IHttpActionResult> Post([FromBody] UserLesson userLesson)
        {
            userLesson.EventDateTime = DateTime.Now;
            var r = await userLessonSv.AddTask(userLesson);

            return(Ok(r > 0));
            //throw new NotImplementedException();
        }
        public async Task <ActionResult <UserLesson> > PostUserLesson(UserLesson userLesson)
        {
            _context.UserLesson.Add(userLesson);
            await _context.SaveChangesAsync();

            //return CreatedAtAction("GetUserLesson", new { id = userLesson.Id }, userLesson);
            return(CreatedAtAction(nameof(GetUserLesson), new { id = userLesson.Id }, userLesson));
        }
        private Result <List <UserAchievementDto> > UpdateAlreadyCompletedLesson(UserLesson completedLesson, CompleteLessonCommand command)
        {
            completedLesson.LastStartedOn  = command.StartTime.Value;
            completedLesson.LastFinishedOn = command.EndTime.Value;
            completedLesson.NoOfCompletions++;

            dbContext.SaveChanges();
            return(Result.Ok(new List <UserAchievementDto>()));
        }
Esempio n. 11
0
        public async Task AddUserToLesson(int lessonId, int userId)
        {
            var userLesson = new UserLesson
            {
                LessonId = lessonId,
                UserId   = userId
            };

            ctx.UserLessons.Add(userLesson);
            await ctx.SaveChangesAsync();
        }
Esempio n. 12
0
        public async Task <IActionResult> Create([Bind("Id,UserId,LessonId")] UserLesson userLesson)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userLesson);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LessonId"] = new SelectList(_context.Lessons, "Id", "Id", userLesson.LessonId);
            ViewData["UserId"]   = new SelectList(_context.Users, "Id", "Password", userLesson.UserId);
            return(View(userLesson));
        }
Esempio n. 13
0
        public void RemoveUserMissLesson(UserLesson userLesson)
        {
            Lesson lessonDbentry = this.context.Lessons.FirstOrDefault(_ => _.LessonId == userLesson.LessonId);

            if (lessonDbentry != null)
            {
                AppUser userDbentry = lessonDbentry.AppUsers.FirstOrDefault(_ => _.UserId == userLesson.UserId);
                if (userDbentry != null)
                {
                    lessonDbentry.AppUsers.Remove(userDbentry);
                    this.context.SaveChanges();
                }
            }
        }
Esempio n. 14
0
        public async Task CreateUserLesson(string userId, string lessonId)
        {
            if (!this.usersLessonsRepository.All().Any(x => x.LessonId == lessonId && x.UserId == userId))
            {
                var userLesson = new UserLesson
                {
                    UserId   = userId,
                    LessonId = lessonId,
                };
                await this.usersLessonsRepository.AddAsync(userLesson);

                await this.usersLessonsRepository.SaveChangesAsync();
            }
        }
Esempio n. 15
0
        public ActionResult Add(User model, int[] lessonsIDs)
        {
            if (ModelState.IsValid)
            {
                using (QuestionBankDbContext Db = new QuestionBankDbContext())
                {
                    if (Db.User.ToList().SingleOrDefault(x => x.Mail.Equals(model.Mail)) == null)
                    {
                        if (Db.User.ToList().SingleOrDefault(x => x.UserName.Equals(model.UserName)) == null)
                        {
                            Db.Entry(model).State = System.Data.Entity.EntityState.Added;

                            foreach (int item in lessonsIDs)
                            {
                                UserLesson UserLes = new UserLesson {
                                    LessonID = item, UserID = model.ID
                                };
                                Db.Entry(UserLes).State = System.Data.Entity.EntityState.Added;
                            }

                            Db.SaveChanges();
                            ViewBag.Message = $"<div class='alert alert-success'><strong>Başarılı!</strong> Kullanıcı Başarıyla Eklendi... </div>";
                            ModelState.Clear();
                        }

                        else
                        {
                            ViewBag.Message = $"<div class='alert alert-danger'><strong>Hata!</strong> Bu kullanıcı adı  zaten kullanılıyor... </div>";
                        }
                    }
                    else
                    {
                        ViewBag.Message = $"<div class='alert alert-danger'><strong>Hata!</strong> Bu mail zaten kullanılıyor... </div>";
                    }
                }
                using (QuestionBankDbContext Db = new QuestionBankDbContext())
                {
                    ViewBag.Lessons = Db.Lesson.ToList();
                }
            }
            return(View());
        }
Esempio n. 16
0
        private async Task HandleLessonAchievements(UserLesson userLesson)
        {
            int userId = userLesson.UserId;
            List <Achievement> achievementsForUser = await achievementService.GetAchievementsForUser(userId);

            List <Lesson> lessonsForUser = await courseRepo.GetCompletedLessonsForUserDistinct(userId);

            // Handling LESSON achievement
            Achievement achievementForLessonCount = await achievementService.GetAchievementForLessonCount(lessonsForUser.Count);

            if (achievementForLessonCount != null && !achievementsForUser.Contains(achievementForLessonCount))
            {
                await achievementService.InsertUserAchievement(userId, achievementForLessonCount.AchievementId);
            }

            // Handling CHAPTER achievement
            Lesson lesson = await courseRepo.GetLesson(userLesson.LessonId);

            Chapter chapter = await courseRepo.GetChapter(lesson.ChapterId);

            bool didUserCompleteTheChapter = await DidUserCompleteTheChapter(userId, chapter);

            if (didUserCompleteTheChapter)
            {
                await HandleChapterAchievement(userId, achievementsForUser, chapter);
            }

            // Handling COURSE achievement
            Course course = await courseRepo.GetCourse(chapter.CourseId);

            bool didUserCompleteTheCourse = await DidUserCompleteTheCourse(userId, course);

            if (didUserCompleteTheChapter && didUserCompleteTheCourse)
            {
                await HandleCourseAchievement(userId, achievementsForUser, course);
            }
        }
        public async Task <HttpResponseMessage> PostLessonCompleted([FromBody] UserLessonDto userLessonDto)
        {
            UserLesson userLesson = new UserLesson
            {
                LessonId  = userLessonDto.LessonId,
                UserId    = userLessonDto.UserId,
                EndTime   = userLessonDto.EndTime,
                StartTime = userLessonDto.StartTime
            };

            await _mimoDbContext.UserLessons.AddAsync(userLesson);

            UpdateAchievementProgressDto updateAchievementProgressDto = new UpdateAchievementProgressDto
            {
                UserId   = userLessonDto.UserId,
                LessonId = userLessonDto.LessonId
            };

            await _mimoDbContext.SaveChangesAsync();

            await _achievementsService.UpdateAchievementProgress(updateAchievementProgressDto);

            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
Esempio n. 18
0
 public UserBuilder AddCompletedLesson(UserLesson lesson)
 {
     ObjectToBuild.CompletedLessons.Add(lesson);
     return(this);
 }
Esempio n. 19
0
        public ActionResult Edit(User model, int[] lessonsIDs)
        {
            ModelState.Remove("Name");
            ModelState.Remove("SurName");
            ModelState.Remove("Password");


            if (ModelState.IsValid && lessonsIDs != null)
            {
                using (QuestionBankDbContext Db = new QuestionBankDbContext())
                {
                    List <User> lst = Db.User.ToList();

                    if (lst.SingleOrDefault(x => x.Mail.Equals(model.Mail) && x.ID != model.ID) == null)
                    {
                        if (lst.SingleOrDefault(x => x.UserName.Equals(model.UserName) && x.ID != model.ID) == null)
                        {
                            User user = lst.SingleOrDefault(x => x.ID.Equals(model.ID));
                            user.UserName = model.UserName;
                            //user.Name = model.Name;
                            //user.SurName = model.SurName;
                            //user.Password = model.Password;
                            user.Mail      = model.Mail;
                            user.IsItAdmin = model.IsItAdmin;
                            foreach (int item in lessonsIDs)
                            {
                                UserLesson userLesson = Db.UserLesson.SingleOrDefault(x => x.LessonID.Equals(item) && x.UserID.Equals(model.ID));
                                if (userLesson == null)
                                {
                                    Db.UserLesson.Add(new UserLesson()
                                    {
                                        LessonID = item, UserID = model.ID
                                    });
                                }
                            }
                            List <UserLesson> silinecekler = Db.UserLesson.Where(x => x.UserID.Equals(model.ID) && !lessonsIDs.Contains(x.LessonID)).ToList();

                            Db.UserLesson.RemoveRange(silinecekler);

                            Db.SaveChanges();
                            ViewBag.Message = $"<div class='alert alert-success'><strong>Başarılı!</strong> Kullanıcı Başarıyla Güncellendi... </div>";
                            ModelState.Clear();
                        }
                        else
                        {
                            ViewBag.Message = $"<div class='alert alert-danger'><strong>Hata!</strong> Bu kullanıcı adı zaten kullanılıyor... </div>";
                        }
                    }
                    else
                    {
                        ViewBag.Message = $"<div class='alert alert-danger'><strong>Hata!</strong> Bu mail zaten kullanılıyor... </div>";
                    }
                }
            }
            else
            {
                ViewBag.Message = $"<div class='alert alert-danger'><strong>Hata!</strong> Kullanıcının en az bir dersi olmalı... </div>";
            }
            using (QuestionBankDbContext Db = new QuestionBankDbContext())
            {
                User user = Db.User.SingleOrDefault(x => x.ID.Equals(model.ID));

                ViewBag.UserLessons = user.UserLesson.Select(x => x.LessonID).ToList <int>();
                ViewBag.Lessons     = Db.Lesson.ToList();
            }
            //ViewBag.message = $"<div class='alert alert-danger'><strong>Başarısız!</strong> Kullanıcının en az bir dersi olmalı... </div>";
            return(View(model));
        }