Exemple #1
0
        public async Task <IActionResult> Get(Guid id)
        {
            AuthorMapping author = await AuthorService.GetById(id);

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

            return(Ok(author));
        }
Exemple #2
0
        public Author Get(int cod)
        {
            string query = "Select CodAu, Nome from Autor where CodAu = @cod";

            using (var conn = new SqlConnection(_connectionString))
            {
                var author = conn.QueryFirstOrDefault <dynamic>(query, new
                {
                    cod
                });

                return(AuthorMapping.Map(author));
            }
        }
Exemple #3
0
        public Author GetByName(string name)
        {
            string query = "Select CodAu, Nome from Autor where Nome = @name";

            using (var conn = new SqlConnection(_connectionString))
            {
                var author = conn.QueryFirstOrDefault <dynamic>(query, new
                {
                    name
                });

                return(AuthorMapping.Map(author));
            }
        }
Exemple #4
0
        public async Task <AuthorMapping> GetById(Guid id)
        {
            Author author = await AuthorRepository.GetById(id);

            if (author == null)
            {
                return(null);
            }
            List <AuthorBook> books = await AuthorBookRepository.GetAllBooksFromAuthor(author);

            author.Books = books;
            AuthorMapping authorMapping = Helpers.ConvertAuthorToAuthorResponse(author);

            return(authorMapping);
        }
Exemple #5
0
        public List <Author> GetAll()
        {
            string query = "Select CodAu, Nome from Autor order by 2";

            using (var conn = new SqlConnection(_connectionString))
            {
                var result = conn.Query <dynamic>(query)
                             .ToList();

                List <Author> authorList = new List <Author>();

                result.ForEach(x =>
                               authorList.Add(AuthorMapping.Map(x)));

                return(authorList);
            }
        }
Exemple #6
0
        public static AuthorMapping ConvertAuthorToAuthorResponse(Author author)
        {
            AuthorMapping authorMapped = new AuthorMapping {
                Id       = author.Id,
                Name     = author.Name,
                Lastname = author.Lastname,
                Email    = author.Email,
                Birthday = author.Birthday,
                Books    = new List <Guid>()
            };

            foreach (AuthorBook item in author.Books)
            {
                authorMapped.Books.Add(item.BookId);
            }

            return(authorMapped);
        }
Exemple #7
0
        public List <Author> GetAllByBookCod(int bookCod)
        {
            string query = @"Select a.CodAu, a.Nome
                                from Autor a
                                inner join Livro_Autor la on la.Autor_CodAu = a.CodAu
                                inner join Livro l on l.Codl = la.Livro_Codl
                                where l.Codl = @bookCod
                                order by 2";

            using (var conn = new SqlConnection(_connectionString))
            {
                var result = conn.Query <dynamic>(query, new
                {
                    bookCod
                }).ToList();

                List <Author> authorList = new List <Author>();

                result.ForEach(x =>
                               authorList.Add(AuthorMapping.Map(x)));

                return(authorList);
            }
        }
 public override void Given()
 {
     this.mapping = new AuthorMapping();
 }