Exemplo n.º 1
0
        /// <summary>
        /// Get All Authors
        /// </summary>
        /// <returns></returns>
        public async Task <IList <AuthorDto> > GetAllAuthors()
        {
            Devon4NetLogger.Debug($"GetAllAuthors method from service Authorservice");

            var authorListDto = new List <AuthorDto>();
            var authorList    = await _authorRepository.Get();

            foreach (Author a in authorList)
            {
                authorListDto.Add(AuthorConverter.ModelToDto(a));
            }

            return(authorListDto);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates the Author
        /// </summadry>
        /// <param name="name"></param>
        /// <param name="surname"></param>
        /// <param name="email"></param>
        /// <param name="phone"></param>
        /// <returns></returns>
        public async Task <AuthorDto> CreateAuthor(AuthorDto authorDto)
        {
            Devon4NetLogger.Debug($"CreateAuthor method from service AuthorService with value : {authorDto.Name}, {authorDto.Surname}, {authorDto.Email}, {authorDto.Phone}");

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

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

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

            var result = await _authorRepository.Create(authorDto).ConfigureAwait(false);

            return(AuthorConverter.ModelToDto(result));
        }
Exemplo n.º 3
0
 /// <summary>
 /// CreateAuthor
 /// </summary>
 /// <param name="newAuthor"></param>
 /// <returns></returns>
 public async Task <AuthorDto> CreateAuthor(AuthorDto newAuthor)
 {
     Devon4NetLogger.Debug($"CreateAuthor method from service BookService with value : {newAuthor}");
     return(AuthorConverter.ModelToDto(await _authorRepository.Create(newAuthor).ConfigureAwait(false)));
 }