Exemplo n.º 1
0
        public async Task <BookDto> CreateBook(BookDto newBook)
        {
            Devon4NetLogger.Debug($"CreateBook method from service BookService with value : {newBook}");

            CheckIfAnyOfTheStringsAreNotCorrect(newBook);

            return(BookConverter.ModelToDto(await _bookRepository.Create(newBook).ConfigureAwait(false)));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get all books
        /// </summary>
        /// <returns></returns>
        public async Task <IList <BookDto> > GetAllBooks()
        {
            var bookListDto = new List <BookDto>();
            var bookList    = await _bookRepository.Get().ConfigureAwait(false);

            foreach (Book b in bookList)
            {
                bookListDto.Add(BookConverter.ModelToDto(b));
            }

            return(bookListDto);
        }
Exemplo n.º 3
0
        public async Task <BookDto> GetBookByTitle(string bookTitle)
        {
            MethodBase m = MethodBase.GetCurrentMethod();

            Devon4NetLogger.Debug($"{m.ReflectedType.Name} method from service {m.Name}");
            var book = await _bookRepository.GetBookByTitleIfItExist(bookTitle).ConfigureAwait(false);

            if (IsNotBookInTheDdbb(book))
            {
                throw new ArgumentException($"The provided book title {bookTitle} does not exists");
            }
            else
            {
                return(BookConverter.ModelToDto(book));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public async Task <BookDto> Create(BookDto bookDto)
        {
            Devon4NetLogger.Debug($"CreateAuthor method from service AuthorService with value : {bookDto.Title}, {bookDto.Summary}, {bookDto.Genere}");

            if (string.IsNullOrEmpty(bookDto.Title) || string.IsNullOrWhiteSpace(bookDto.Title))
            {
                throw new ArgumentException("The 'Title' field can not be null.");
            }

            if (string.IsNullOrEmpty(bookDto.Summary) || string.IsNullOrWhiteSpace(bookDto.Summary))
            {
                throw new ArgumentException("The 'Summary' field can not be null.");
            }

            if (string.IsNullOrEmpty(bookDto.Genere) || string.IsNullOrWhiteSpace(bookDto.Genere))
            {
                throw new ArgumentException("The 'Genere' field can not be null.");
            }

            return(BookConverter.ModelToDto(await _bookRepository.Create(bookDto).ConfigureAwait(false)));
        }
Exemplo n.º 5
0
        private async Task <BookDto> CreateBook(BookDto newBook)
        {
            // TODO: Put the correct call
            string mediaType    = MediaType.ApplicationJson;
            string endPoint     = "Books";
            var    httpResponse = await _httpClientHandler.Send(System.Net.Http.HttpMethod.Get, endPoint,
                                                                "/books", null, mediaType, true, false, null);

            var listOfBooks = GetObjectFromHttpResponse <List <BookDto> >(in httpResponse);

            string title   = "";
            string genere  = "";
            string summary = "";

            foreach (BookDto book in listOfBooks)
            {
                title   = book._title;
                genere  = book._genere;
                summary = book._summary;
            }

            return(BookConverter.ModelToDto(await _bookRepository.Create(newBook).ConfigureAwait(false)));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Get book by title
        /// </summary>
        /// <param name="title"></param>
        /// <returns></returns>
        public async Task <BookDto> GetBookByTitle(string title)
        {
            Devon4NetLogger.Debug($"GetBookByTitle method from service Bookservice with value : {title}");

            return(BookConverter.ModelToDto(await _bookRepository.GetFirstOrDefault(x => x.Title == title).ConfigureAwait(false)));
        }