public async Task <ApiSuccessResponse> CreateAsync(CourseAssignCreateViewModel request) { var isStudentAlreadyEntroll = await _unitOfWork.CourseStudentRepository.Exists(x => x.CourseId == request.CourseId && x.StudentId == request.StudentId); if (isStudentAlreadyEntroll) { 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.SaveAsync()) { return(new ApiSuccessResponse() { StatusCode = 200, Message = "student enroll successfully" }); } throw new ApplicationValidationException("something wrong for enrollment"); }
public async Task <IActionResult> Create(CourseAssignCreateViewModel request) { return(Ok(await _courseStudentService.CreateAsync(request))); }