public async Task <CourseStudent> AddCourseEnrollAsync(CourseEnrollRequest request) { Guid id = Guid.NewGuid(); var studentId = _unitOfWork.StudentRepository.GetAAsync(x => x.RollNo == request.studentRollNo).Result .StudentId; var courseId = _unitOfWork.CourseRepository.GetAAsync(x => x.Code == request.CourseCode).Result.CourseId; var courseStudentEnroll = await _unitOfWork.CourseStudentEnrollRepository.GetAAsync(x => x.CourseId == courseId && x.StudentId == studentId); if (courseStudentEnroll != null) { throw new MyAppException("Student Already enroll in this course"); } var courseStudent = new CourseStudent { CourseStudentId = id.ToString(), StudentId = studentId, CourseId = courseId }; await _unitOfWork.CourseStudentEnrollRepository.createAsync(courseStudent); if (await _unitOfWork.ApplicationSaveChangesAsync()) { return(courseStudent); } throw new MyAppException("Something went wrong"); }
public async Task <ActionResult> EnrollCourse(CourseEnrollRequest aCourseEnrollRequest) { return(Ok(await _courseEnrollService.AddCourseEnrollAsync(aCourseEnrollRequest))); }