public async Task <ApiSuccessResponse> InsertAsync(CourseAssignInsertViewModel request)
        {
            var isStudentAlreadyEntroll = await _unitOfWork.CourseStudentRepository.FindSingleAsync(x =>
                                                                                                    x.CourseId == request.CourseId &&
                                                                                                    x.StudentId == request.StudentId);

            if (isStudentAlreadyEntroll != null)
            {
                throw new ApplicationValidationException("this student already enroll this course");
            }

            var courseStudent = new CourseStudent()
            {
                CourseId  = request.CourseId,
                StudentId = request.StudentId
            };

            await _unitOfWork.CourseStudentRepository.CreateAsync(courseStudent);

            if (await _unitOfWork.SaveCompletedAsync())
            {
                return(new ApiSuccessResponse()
                {
                    StatusCode = 200,
                    Message = "student enroll successfully"
                });
            }
            throw new ApplicationValidationException("something wrong for enrollment");
        }
Beispiel #2
0
 public async Task <IActionResult> Insert(CourseAssignInsertViewModel request)
 {
     return(Ok(await _courseStudentService.InsetAsync(request)));
 }