public ActionResult <CourseDto> CreateCourseForAuthor( Guid authorId, [FromBody] CourseCreationDto courseCreationDto) { if (!_repository.AuthorExists(authorId)) { return(NotFound()); } var course = _mapper.Map <Course>(courseCreationDto); _repository.AddCourse(authorId, course); var isSaved = _repository.Save(); if (!isSaved) { throw new InvalidOperationException("Error occurred: Unable to create course"); } var courseDto = _mapper.Map <CourseDto>(course); return(CreatedAtAction( "GetCourseForAuthor", new { authorId, courseId = courseDto.Id }, courseDto)); }
public ActionResult <IEnumerable <CourseDto> > GetAllCourses(Guid authorid) { if (!_repo.AuthorExists(authorid)) { return(NotFound()); } var courses = _repo.GetCourses(authorid); return(Ok(_map.Map <IEnumerable <CourseDto> >(courses))); }
public ActionResult <IEnumerable <CourseDto> > GetCoursesForAuthor(Guid authorId) { if (!_courseLibraryRepository.AuthorExists(authorId)) { return(NotFound()); } var courses = _courseLibraryRepository.GetCourses(authorId); return(Ok(_mapper.Map <IEnumerable <CourseDto> >(courses))); }
public ActionResult <IEnumerable <CourseDto> > GetCoursesForAuthor(Guid authorId) // IActionResult renvoi le résultat d'une méthode d'action { if (!_courseLibraryRepository.AuthorExists(authorId)) { return(NotFound()); } var coursesForAuthorFromRepo = _courseLibraryRepository.GetCourses(authorId); return(Ok(_mapper.Map <IEnumerable <CourseDto> >(coursesForAuthorFromRepo))); }
public ActionResult <IEnumerable <CourseDto> > GetCoursesForAuthor(Guid authorId) { if (!_repo.AuthorExists(authorId)) { return(NotFound()); } var coursesForAuthorFromRepo = _repo.GetCourses(authorId); return(Ok(_mapper.Map <IEnumerable <CourseDto> >(coursesForAuthorFromRepo))); }
public async Task <ActionResult <IEnumerable <CourseDto> > > GetCoursesForAuthorAsync(Guid authorId) { if (!_courseLibraryRepository.AuthorExists(authorId)) { return(NotFound()); } var coursesFromRepo = await _courseLibraryRepository.GetCoursesAsync(authorId); return(Ok(_mapper.Map <IEnumerable <CourseDto> >(coursesFromRepo))); }
public ActionResult <IEnumerable <CourseDto> > GetCoursesForAuthor(Guid authorId) { //throw new Exception("Terrible error occurred"); if (!_courseLibraryRepository.AuthorExists(authorId)) { return(NotFound()); } var coursesForAuthorFromRepo = _courseLibraryRepository.GetCourses(authorId); return(Ok(_mapper.Map <IEnumerable <CourseDto> >(coursesForAuthorFromRepo))); }
public ActionResult <IEnumerable <CourseDTO> > GetCourses(Guid authorId) { if (!_courseLibrary.AuthorExists(authorId)) { return(NotFound()); } var courses = _courseLibrary.GetCourses(authorId); if (courses is null) { return(NotFound()); } return(Ok(_mapper.Map <IEnumerable <CourseDTO> >(courses))); }
public IActionResult GetAuthorById(Guid authorId) { if (!_courseLibraryRepository.AuthorExists(authorId)) { return(NotFound()); } var authorById = _courseLibraryRepository.GetAuthor(authorId); return(Ok(authorById)); }
public IActionResult GetAuthor(Guid authorId) { if (_courseLibraryRepository.AuthorExists(authorId)) { var authorFromRepo = _courseLibraryRepository.GetAuthor(authorId); return(Ok(_mapper.Map <authorDto>(authorFromRepo))); } return(NotFound()); }
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 <IEnumerable <CourseDto> > GetCoursesForAuthor(Guid authorId) { if (!_repos.AuthorExists(authorId)) { return(NotFound()); } var courseEntities = this._repos.GetCourses(authorId); var coursesDtos = this._mapper.Map <IEnumerable <CourseDto> >(courseEntities); return(Ok(coursesDtos)); }
public ActionResult DeleteAuthor(Guid authorId) { if (!_CourseLibraryRepository.AuthorExists(authorId)) { return(NotFound()); } var AuthorToDelete = _CourseLibraryRepository.GetAuthor(authorId); _CourseLibraryRepository.DeleteAuthor(AuthorToDelete); _CourseLibraryRepository.Save(); return(NoContent()); }
public ActionResult <IEnumerable <CoursesDto> > GetCourseForAuthors(Guid authorId) { if (_courseLibraryRepository.AuthorExists(authorId)) { var getCouseFromRepo = _courseLibraryRepository.GetCourses(authorId); return(Ok(_mapper.Map <IEnumerable <CoursesDto> >(getCouseFromRepo))); } return(NotFound()); }
public IEnumerable <CourseDto> GetCoursesForAuthor(Guid authId) { if (!_repo.AuthorExists(authId)) { return(null); } var x = _repo.GetCourses(authId); return(_mapper.Map <IEnumerable <CourseDto> >(x)); }
public IActionResult GetCourses(Guid authorId) { if (!_courseLibraryRepository.AuthorExists(authorId)) { return(NotFound()); } var courses = _courseLibraryRepository.GetCourses(authorId); return(Ok(_mapper.Map <CourseDto>(courses))); }
public IActionResult UpdateAuthor(Guid id, [FromBody] Author author) { if (!ModelState.IsValid || !_repository.AuthorExists(id)) { return(BadRequest()); } var model = _repository.GetAuthor(id); model.FirstName = author.FirstName; model.LastName = author.LastName; model.MainCategory = author.MainCategory; model.DateOfBirth = author.DateOfBirth; return(CreatedAtRoute("GetAuthor", new { model.Id }, model)); }
public ActionResult <IEnumerable <CourseDTO> > GetCoursesFromAuthor(Guid authorId) { if (!_clRepo.AuthorExists(authorId)) { return(NotFound()); } var courses = _clRepo.GetCourses(authorId); var result = _mapper.Map <IEnumerable <CourseDTO> >(courses); return(Ok(result)); }
public ActionResult <IEnumerable <CoursesDto> > GetAuthorCourses(Guid authorId) { //Check if author exists if (!_courseLibraryRepository.AuthorExists(authorId)) { return(NotFound()); } var authorCourses = _courseLibraryRepository.GetCourses(authorId); return(Ok(_mapper.Map <IEnumerable <CoursesDto> >(authorCourses))); }
public ActionResult <CourseDto> CreateCourseForAuthor( Guid authorId, CourseForCreationDto course) { if (!_courseLibraryRepository.AuthorExists(authorId)) { return(NotFound()); } var courseEntity = _mapper.Map <Course>(course); _courseLibraryRepository.AddCourse(authorId, courseEntity); _courseLibraryRepository.Save(); var courseToReturn = _mapper.Map <CourseDto>(courseEntity); return(CreatedAtRoute("GetCourseForAuthor", new { authorId = authorId, courseId = courseToReturn.Id }, courseToReturn)); }
public async Task <ActionResult <IEnumerable <CourseDto> > > getCoursesForAuthor(Guid authorId) { if (!_courseLibaryService.AuthorExists(authorId)) { return(NotFound()); } var courses = await _courseLibaryService.GetCourses(authorId); var CourseResult = _mapper.Map <IEnumerable <CourseDto> >(courses); return(Ok(CourseResult)); }
public ActionResult <IEnumerable <CourseDTO> > GetCoursesForAuthors(Guid createrId) { if (!courseLibraryRepository.AuthorExists(createrId)) { return(NotFound()); } var courseForAuthorsFromRepo = courseLibraryRepository.GetCourses(createrId); return(Ok(_mapper.Map <IEnumerable <CourseDTO> >(courseForAuthorsFromRepo))); }
public ActionResult DeleteAuthor(Guid authorId) { if (!_courseLibraryRepository.AuthorExists(authorId)) { return(NotFound()); } var authorFromRepo = _courseLibraryRepository.GetAuthor(authorId); if (authorFromRepo == null) { return(NotFound()); } _courseLibraryRepository.DeleteAuthor(authorFromRepo); _courseLibraryRepository.Save(); return(NoContent()); }
public IActionResult GetAuthor(Guid authorId, string fields) { if (!_courseLibraryRepository.AuthorExists(authorId)) { return(NotFound()); } var authorFromRepo = _courseLibraryRepository.GetAuthor(authorId); if (!_propertyCheckerService.TypeHasProperties <AuthorDto>(fields)) { return(BadRequest()); } var links = CreateLinksForAuthor(authorId, fields); var linkedResourceToReturn = _mapper.Map <AuthorDto>(authorFromRepo).ShapeData(fields) as IDictionary <string, object>; linkedResourceToReturn.Add("links", links); return(Ok(linkedResourceToReturn)); }
public ActionResult <IEnumerable <CourseDto> > GetCoursesForAuthor(Guid authorId) { try { if (!_courseLibraryRepository.AuthorExists(authorId)) { return(NotFound()); } return(Ok(_courseLibraryRepository.GetCourses(authorId))); } catch (Exception ex) { _logger.LogError(ex, $"{ex.Message}"); return(StatusCode(500, "Internal server error, try again later.")); } }
public async Task <ActionResult <IEnumerable <CourseForReturn> > > GetCourses(Guid authorId) { if (!await _repository.AuthorExists(authorId)) { return(NotFound("Author Not Found")); } var coursesFromRepo = await _repository.GetCourses(authorId); if (coursesFromRepo == null) { return(NotFound("this author has no courses")); } var courses = _mapper.Map <IEnumerable <CourseForReturn> >(coursesFromRepo); return(Ok(courses)); }
public ActionResult DeleteAuthor(Guid authorId) { if (!_courseLibraryRepository.AuthorExists(authorId)) { return(NotFound("Author does not exist")); } var auth = _courseLibraryRepository.GetAuthor(authorId); if (auth == null) { return(NotFound("Author cannot be found")); } _courseLibraryRepository.DeleteAuthor(auth); var result = _courseLibraryRepository.Save(); if (result) { return(Ok("Author has been deleted Successfully")); } return(BadRequest("Unable to delete author")); }
public ActionResult <IEnumerable <CourseDto> > GetCoursesForAuthor(Guid authorId) { try { if (!_courseLibraryRepository.AuthorExists(authorId)) { return(NotFound()); } var CoursesFromRepo = _courseLibraryRepository.GetCourses(authorId); return(Ok(_mapper.Map <IEnumerable <CourseDto> >(CoursesFromRepo))); } catch (Exception) { return(StatusCode(500, "Internal server error")); } }
public ActionResult <IEnumerable <CourseDto> > GetCoursesForAuthor(Guid authorId) { try { //Validate {authorId} if (!_courseLibraryRepository.AuthorExists(authorId)) { return(NotFound()); } var GetCourses = _courseLibraryRepository.GetCourses(authorId); return(Ok(_mapper.Map <IEnumerable <CourseDto> >(GetCourses))); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Database Failure __")); } }
private bool AuthorExists(Guid authorId) => _courseLibraryRepository.AuthorExists(authorId);