internal static Livro TabLivroParaLivro(TabLivro tabLivro) { var editora = RepositorioEditora.TabEditoraParaEditora(tabLivro.Editora); var autores = new List <Autor>(); foreach (var tabAutor in tabLivro.Autores) { autores.Add(RepositorioAutor.TabAutorParaAutor(tabAutor)); } return(new Livro( tabLivro.LivroId, tabLivro.Titulo, tabLivro.Estante, tabLivro.AnoPublicacao, editora, autores )); }
public AoListarDeRepositorioAutor Listar() { var retorno = new AoListarDeRepositorioAutor(); try { var autores = new List <Autor>(); var tabAutores = db.Autores.ToList(); foreach (var tabAutor in tabAutores) { autores.Add(RepositorioAutor.TabAutorParaAutor(tabAutor)); } retorno.Autores = autores; } catch (Exception ex) { retorno.Mensagem = "Não foi possível listar os autores."; retorno.Problemas.Add($"Falha ao {nameof(Listar)} em {nameof(RepositorioAutor)}: {ex.Message}"); } return(retorno); }
public RetornoBase <ICollection <Autor> > ListarAutoresDisponiveis(int livroId) { var retorno = new RetornoBase <ICollection <Autor> >(); try { var autores = new List <Autor>(); List <TabAutor> tabAutores = null; if (livroId > 0) { tabAutores = db.Database.SqlQuery <TabAutor>($"select * from Autor where AutorId not in (select AutorId from LivroAutoria where LivroId = {livroId})").ToList(); } else { tabAutores = db.Autores.ToList(); } if (tabAutores != null) { foreach (var tabAutor in tabAutores) { autores.Add(RepositorioAutor.TabAutorParaAutor(tabAutor)); } } retorno.Valor = autores; } catch (Exception ex) { retorno.Mensagem = "Não foi possível listar os autores."; retorno.Problemas.Add($"Falha ao {nameof(ListarAutoresDisponiveis)} em {nameof(RepositorioLivro)}: {ex.Message}"); } return(retorno); }
public AoLocalizarEmRepositorioAutor Localizar(int autorId) { var retorno = new AoLocalizarEmRepositorioAutor(); try { var tbAutor = db.Autores.FirstOrDefault(x => x.AutorId == autorId); if (tbAutor != null) { retorno.Autor = RepositorioAutor.TabAutorParaAutor(tbAutor); } else { retorno.Mensagem = $"Autor não localizado para ID {autorId}."; } } catch (Exception ex) { retorno.Mensagem = $"Não foi possível localizar o autor {autorId}."; retorno.Problemas.Add($"Falha ao {nameof(Localizar)} em {nameof(RepositorioAutor)}: {ex.Message}"); } return(retorno); }