public IActionResult PostLessonRating([Required, FromBody] LessonRatingDTO lessonRatingDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_lessonService.IsLessonExists(lessonRatingDTO.LessonId)) { return(NotFound()); } var currentUserId = User.GetUserId().Value; Lesson lesson = _lessonService.GetById(lessonRatingDTO.LessonId); if (lesson.StudentId == currentUserId) { _lessonService.RateLessonCoach(lessonRatingDTO); _userService.CalculateCoachRating(lesson.CoachLesson.CoachId); // Aktualizacja pola CoachRating po nowej opinii return(Ok()); } else if (lesson.CoachLesson.CoachId == currentUserId) { _lessonService.RateLessonStudent(lessonRatingDTO); return(Ok()); } return(Forbid()); }
public void RateLessonCoach(LessonRatingDTO lessonRatingDTO) { var lesson = _lessonRepository.GetById(lessonRatingDTO.LessonId); lesson.RatingOfCoach = (byte)lessonRatingDTO.Rating; lesson.OpinionOfCoach = lessonRatingDTO.Opinion; _lessonRepository.Update(lesson); }