Beispiel #1
0
        public IActionResult GetCourseForAuthor(Guid authorId, Guid courseId)
        {
            var course = _courseLibraryRepository.GetCourse(authorId, courseId);

            if (course == null)
            {
                return(NotFound());
            }

            var res = _mapper.Map <CourseDto>(course);

            return(Ok(res));
        }
        public ActionResult <CourseDto> GetCoursesForAuthor(Guid authorId, Guid courseId)
        {
            if (!_courseLibraryRepository.AuthorExists(authorId))
            {
                return(NotFound());
            }

            var courseForAuthorFromRepo = _courseLibraryRepository.GetCourse(authorId, courseId);

            return(courseForAuthorFromRepo == null
                ? (ActionResult <CourseDto>)NotFound()
                : Ok(_mapper.Map <CourseDto>(courseForAuthorFromRepo)));
        }
        public ActionResult <CourseDto> GetCourseForAuthor(Guid authorId, Guid courseId)
        {
            if (!courseRepo.AuthorExists(authorId))
            {
                return(NotFound());
            }
            var course = courseRepo.GetCourse(authorId, courseId);

            if (course == null)
            {
                return(NotFound());
            }
            return(Ok(mapper.Map <CourseDto>(course)));
        }
Beispiel #4
0
        public ActionResult <IEnumerable <CourseGetDto> > GetCoursesForAuthor(Guid authorId, Guid courseId)
        {
            if (!_repo.AuthorExists(authorId))
            {
                return(NotFound());
            }
            var course = _repo.GetCourse(authorId, courseId);

            if (course == null)
            {
                return(NotFound());
            }
            return(Ok(_mapper.Map <CourseGetDto>(course)));
        }
        public CourseDto GetCourseForAuthor(Guid authId, Guid courseId)
        {
            if (!_repo.AuthorExists(authId))
            {
                return(null);
            }
            var x = _repo.GetCourse(authId, courseId);

            if (x == null)
            {
                return(null);
            }
            return(_mapper.Map <CourseDto>(x));
        }
Beispiel #6
0
        public ActionResult <CourseDto> GetCourseForAuthor(Guid authorId, Guid courseId)
        {
            if (!_courseLibraryRepository.AuthorExists(authorId))
            {
                return(NotFound());
            }
            var course = _courseLibraryRepository.GetCourse(authorId, courseId);

            if (course == null)
            {
                return(NotFound());
            }
            return(Ok(_mapper.Map <CourseDto>(course)));
        }
Beispiel #7
0
        public ActionResult <IEquatable <CourseDto> > GetCoursesByAuthor(Guid authorId, Guid courseId)
        {
            if (!_courseLibraryRepository.AuthorExists(authorId))
            {
                return(NotFound());
            }
            var coursesForAuhthorFromRepo = _courseLibraryRepository.GetCourse(authorId, courseId);

            if (coursesForAuhthorFromRepo == null)
            {
                return(NotFound());
            }
            return(Ok(_mapper.Map <CourseDto>(coursesForAuhthorFromRepo)));
        }
        public ActionResult GetCourse(Guid authorId, Guid courseId)
        {
            if (!_courseLibrary.AuthorExists(authorId))
            {
                return(BadRequest("wrong Id"));
            }

            if (courseId == null)
            {
                return(BadRequest("wrong Id"));
            }
            var course = _courseLibrary.GetCourse(authorId, courseId);

            return(Ok(_mapper.Map <CourseDTO>(course)));
        }
Beispiel #9
0
        public ActionResult <IEnumerable <CourseDto> > GetCourseForAuthor(Guid authorId, Guid courseId) // IActionResult renvoi le résultat d'une méthode d'action
        {
            if (!_courseLibraryRepository.AuthorExists(authorId))
            {
                return(NotFound());
            }

            var courseForAuthorFromRepo = _courseLibraryRepository.GetCourse(authorId, courseId);

            if (courseForAuthorFromRepo == null)
            {
                return(NotFound());
            }

            return(Ok(_mapper.Map <CourseDto>(courseForAuthorFromRepo)));
        }
        public ActionResult <CoursesDto> GetCourseForAuthor(Guid authorId, Guid courseId)
        {
            if (!_courseLibraryRepository.AuthorExists(authorId))
            {
                return(NotFound());
                //return Ok(_mapper.Map<IEnumerable<CoursesDto>>(getCouseFromRepo));
            }

            var courseForAuthorFromRepo = _courseLibraryRepository.GetCourse(authorId, courseId);

            if (courseForAuthorFromRepo == null)
            {
                return(NotFound());
            }
            return(Ok(_mapper.Map <CoursesDto>(courseForAuthorFromRepo)));
        }
        public ActionResult <CourseDto> GetCourseForAuthor(Guid authorId, Guid courseId)
        {
            if (!repository.AuthorExists(authorId))
            {
                return(NotFound());
            }

            var courseForAuthorFromRepo = repository.GetCourse(authorId, courseId);

            if (courseForAuthorFromRepo == null)
            {
                return(NotFound());
            }

            return(Ok(mapper.Map <CourseDto>(courseForAuthorFromRepo)));
        }
Beispiel #12
0
        public ActionResult <CourseDTO> GetCourseForAuthor(Guid authorId, Guid courseId)
        {   //check if author is not null
            if (!_courseLibraryRepository.AuthorExists(authorId))
            {
                return(NotFound());
            }
            //check if course is not null
            var courseForAuthorFromRepo = _courseLibraryRepository.GetCourse(authorId, courseId);

            if (courseForAuthorFromRepo == null)
            {
                return(NotFound());
            }

            return(Ok(_mapper.Map <CourseDTO>(courseForAuthorFromRepo)));
        }
        public async Task <ActionResult <CourseDto> > getCourseForAuthor(Guid authorId, Guid courseId)
        {
            if (!_courseLibaryService.AuthorExists(authorId))
            {
                return(NotFound());
            }

            var course = await _courseLibaryService.GetCourse(authorId, courseId);

            if (course == null)
            {
                return(NotFound());
            }


            return(Ok(_mapper.Map <CourseDto>(course)));
        }
Beispiel #14
0
 public ActionResult <IEnumerable <CourseDto> > GetCourseForAuthor(Guid authorId, Guid courseId)
 {
     try
     {
         if (!_courseLibraryRepository.AuthorExists(authorId))
         {
             return(NotFound());
         }
         var courseByAuthor = _courseLibraryRepository.GetCourse(authorId, courseId);
         return(Ok(_mapper.Map <CourseDto>(courseByAuthor)));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, $"{ex.Message}");
         return(StatusCode(500, "Internal server error, try again later."));
     }
 }
Beispiel #15
0
        public ActionResult <CoursesDto> GetAuthorCourse(Guid authorId, Guid courseId)
        {
            //Check if author exists
            if (!_courseLibraryRepository.AuthorExists(authorId))
            {
                return(NotFound());
            }

            var authorCourse = _courseLibraryRepository.GetCourse(authorId, courseId);

            if (authorCourse == null)
            {
                return(NotFound());
            }

            return(Ok(_mapper.Map <CoursesDto>(authorCourse)));
        }
Beispiel #16
0
        public ActionResult <CourseDTO> GetCourseForAuthor(Guid authorId, Guid courseId)
        {
            if (!_clRepo.AuthorExists(authorId))
            {
                return(NotFound());
            }

            var course = _clRepo.GetCourse(authorId, courseId);

            if (course == null)
            {
                return(NotFound());
            }

            var result = _mapper.Map <CourseDTO>(course);

            return(Ok(result));
        }
        public async Task <ActionResult <CourseForReturn> > GetCourse(Guid authorId, Guid courseId)
        {
            if (!await _repository.AuthorExists(authorId))
            {
                return(NotFound("Author Not Found"));
            }

            var courseFromRepo = await _repository.GetCourse(authorId, courseId);

            if (courseFromRepo == null)
            {
                return(NotFound("this Course Not Found"));
            }

            var course = _mapper.Map <CourseForReturn>(courseFromRepo);

            return(Ok(course));
        }
        public ActionResult <CoursesDTO> GetCourseForAuthor(int authorId, int courseId)
        {
            try
            {
                var AuthorExist = _courseLibrary.AuthorExists(authorId);
                if (!AuthorExist)
                {
                    return(NotFound(new JsonResponse <string>()
                    {
                        Success = false,
                        ErrorMessage = "AuthorId is Invalid."
                    }));
                }
                var AuthorsCourse = _courseLibrary.GetCourse(authorId, courseId);
                if (AuthorsCourse == null)
                {
                    return(NotFound(new JsonResponse <string>()
                    {
                        Success = false,
                        ErrorMessage = "CourseId is Invalid."
                    }));
                }


                var CourseforAuthor = _mapper.Map <CoursesDTO>(AuthorsCourse);

                // return body format for the Api with right statusCode
                return(Ok(new JsonResponses <CoursesDTO>()
                {
                    Success = true,
                    Result = new List <CoursesDTO>()
                    {
                        CourseforAuthor
                    }
                }));
            }

            catch (Exception ex)
            {
                //log ex
                return(StatusCode(500, "Something went wrong, pls try again later"));
            }
        }
        public ActionResult <CourseDto> CourseForAuthor(Guid authorId, Guid courseId)
        {
            var courseForAuthor = courseLibraryRepository.GetCourse(authorId, courseId);

            if (courseForAuthor == null)
            {
                return(NotFound());
            }
            return(Ok(mapper.Map <CourseDto>(courseForAuthor)));
        }
        public ActionResult <CourseDto> GetSpasifcCousre(Guid authorId, Guid CourseId)
        {
            if (!_repo.AuthorExists(authorId))
            {
                return(NotFound());
            }
            var spasifcCouse = _repo.GetCourse(authorId, CourseId);

            if (spasifcCouse == null)
            {
                return(NotFound());
            }
            return(Ok(_map.Map <CourseDto>(spasifcCouse)));
        }
Beispiel #21
0
        public ActionResult <CourseDto> GetCourseForDto(Guid authorId, Guid courseId)
        {
            if (!_courseLibraryRepository.AuthorExists(authorId))
            {
                return(NotFound());
            }

            var courseForAuthorFromRepo = _courseLibraryRepository.GetCourse(authorId, courseId);

            if (courseForAuthorFromRepo == null)
            {
                return(NotFound());
            }
        }
Beispiel #22
0
        public ActionResult <CourseDto> GetCourseForAuthor(Guid authorId, Guid courseId)
        {
            try
            {
                //Validate {authorId}
                if (!_courseLibraryRepository.AuthorExists(authorId))
                {
                    return(NotFound());
                }
                //Validate {courseId}
                var resultCourseAuthor = _courseLibraryRepository.GetCourse(authorId, courseId);
                if (resultCourseAuthor == null)
                {
                    return(NotFound());
                }

                return(Ok(_mapper.Map <CourseDto>(resultCourseAuthor)));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Database Failure __"));
            }
        }
        public IActionResult GetCourseForAuthor(
            [FromRoute] Guid authorId,
            [FromRoute] Guid courseId,
            [FromQuery] string fields)
        {
            if (!AuthorExists(authorId))
            {
                return(NotFound());
            }

            if (!_propertyCheckerService.TypeHasProperties <CourseDto>(fields))
            {
                return(BadRequest());
            }

            var courseFromRepo = _courseLibraryRepository.GetCourse(authorId, courseId);

            if (courseFromRepo == null)
            {
                return(NotFound());
            }

            return(Ok(_mapper.Map <CourseDto>(courseFromRepo).ShapeData(fields)));
        }
Beispiel #24
0
        public ActionResult <CourseDto> GetCourse(int authorId, int courseId)
        {
            throw new Exception();

            var author = _courseLibraryRepository.GetAuthor(authorId);

            if (author == null)
            {
                return(NotFound());
            }

            var courseFromRepo = _courseLibraryRepository.GetCourse(authorId, courseId);

            if (courseFromRepo == null)
            {
                return(NotFound());
            }

            return(Ok(_mapper.Map <CourseDto>(courseFromRepo)));
        }