private Autor TabAutorParaAutor(TabAutor tabAutor)
 {
     return(new Autor(
                tabAutor.AutorId,
                new TNomePessoa(tabAutor.Nome, tabAutor.Sobrenome),
                new TEmail(tabAutor.Email)
                ));
 }
Exemplo n.º 2
0
        public int Salvar(Autor autor)
        {
            TabAutor cadastro = this.GetCadastro(autor.AutorId);

            if (cadastro != null)
            {
                cadastro.Nome = autor.Nome;
                return(db.SaveChanges());
            }
            cadastro = new TabAutor
            {
                Nome = autor.Nome
            };
            db.Autores.Add(cadastro);
            return(db.SaveChanges());
        }
Exemplo n.º 3
0
        public AoInserirEmRepositorioAutor Inserir(Autor autor)
        {
            var retorno = new AoInserirEmRepositorioAutor();

            try
            {
                var tabAutor = TabAutor.Fabricar(autor);
                db.Autores.Add(tabAutor);
                db.SaveChanges();
                retorno.AutorId = tabAutor.AutorId;
            }
            catch (Exception ex)
            {
                retorno.Mensagem = $"Não foi possível inserir o autor '{autor.Nome} {autor.Sobrenome}'.";
                retorno.Problemas.Add($"Falha ao {nameof(Inserir)} em {nameof(RepositorioAutor)}: {ex.Message}");
            }

            return(retorno);
        }
        public AoInserirEmRepositorioAutor Inserir(Autor autor)
        {
            var retorno = new AoInserirEmRepositorioAutor();

            try
            {
                var tabAutor = new TabAutor();
                tabAutor.AutorId   = autor.AutorId;
                tabAutor.Nome      = autor.Nome.Nome;
                tabAutor.Sobrenome = autor.Nome.Sobrenome;
                tabAutor.Email     = autor.Email.Endereco;
                db.Autores.Add(tabAutor);
                db.SaveChanges();
                retorno.AutorId = autor.AutorId;
            }
            catch (Exception ex)
            {
                retorno.Mensagem = $"Não foi possível inserir o autor {autor.AutorId}.";
                retorno.Problemas.Add($"Falha ao {nameof(Inserir)} em {nameof(RepositorioAutor)}: {ex.Message}");
            }

            return(retorno);
        }