public async Task <IActionResult> Get(Guid id) { AuthorMapping author = await AuthorService.GetById(id); if (author == null) { return(NotFound()); } return(Ok(author)); }
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)); } }
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)); } }
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); }
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); } }
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); }
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(); }