예제 #1
0
        public async Task UpdateAsync(Seller obj)
        {
            /*testar se o obj já existe no banco, pq pra atualizar tem q existir,
             * "Any" é serve para falar se existi algum registro no banco com a condição que você colocar aqui. */

            bool hasAny = await _context.Seller.AnyAsync(x => x.Id == obj.Id);

            if (!hasAny)//se não existe no banco algum vendedor cujo o ID seja igual ao Id do Obj, faça:
            {
                throw new NotFoundException("Id not found");

                /*Porém quando você chama a operação de atualizar o banco, ele pode retornar uma excessão de conflito de concorrência, então vamos por
                 * a chamada dentro do try e se ocorrer o conflito vamos usar por o cath para capturar uma possível excessão de concorrencia do Bd que
                 * é DbUpdateConcurrencyException, então se vier vamos relançar em DbConcurrencyException */
            }
            try
            {
                _context.Update(obj);              //se exitir atualize
                await _context.SaveChangesAsync(); //confirme a atualização.

                /* Estamos Relançando em NIVEL DE SERVIÇO, isso é importante para segregar as camadas, a minha camada de serviço, ela NAO
                 * vai propagar uma excessão do NIVEL DE ACESSO A DADOS DbUpdateConcurrencyException, mas se uma excessão de NIVEL DE ACESSO A DADOS acontecer, minha camada
                 * de serviço vai lançar um excessão da camada dela DbConcurrencyException e ai o meu controlador "SellerController" vai ter que lidar APENAS
                 * com as execessões da camada de serviço, isso é uma forma da gente respeitar a arquitera do projeto, o controlador conversa com a camada
                 * de serviço, execessões de nivel de acesso a dados são capturadas pelo serviço e relançadas na forma de excessões de serviço para o
                 * controlador*/
            }
            catch (DbUpdateConcurrencyException e)
            {
                throw new DbConcurrencyException(e.Message);
            }
        }
예제 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Curso,URL,Id,Name,Sobrenome,Email,DataNasc")] Planilha planilha)
        {
            if (id != planilha.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(planilha);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PlanilhaExists(planilha.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(planilha));
        }
예제 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Date,Amount,Status")] SalesRecord salesRecord)
        {
            if (id != salesRecord.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(salesRecord);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SalesRecordExists(salesRecord.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(salesRecord));
        }
예제 #4
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,PaymentStatus,DeliveryStatus,Price,Instalment,Quantity")] Order order)
        {
            if (id != order.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(order);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OrderExists(order.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(order));
        }
예제 #5
0
        public async Task <IActionResult> Edit(int id, [Bind("SubMenu,Url,Titulo,MenuUlId,Id,Ativo,DataCadastro,UltimaAtualizacao,Deletado,DeletadoData")] MenuLi menuLi)
        {
            if (id != menuLi.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(menuLi);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MenuLiExists(menuLi.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MenuUlId"] = new SelectList(_context.MenuUl.OrderBy(x => x.Menu), "Id", "Menu", menuLi.MenuUlId);
            return(View(menuLi));
        }
예제 #6
0
        public async Task UpdateAsync(Seller obj)
        {
            //Any pergunta se existe algum registro no bd
            bool hasAny = await _context.Seller.AnyAsync(x => x.Id == obj.Id);

            if (!hasAny)
            {
                throw new NotFoundException("Id not found");
            }

            /*Essa estrutura é para agregar essa exceção na camada de Serviço,
             * desta forma dividimos bem as camadas e responsabilidades. Assim as
             * O controlador conversa com a camada de serviço e exceções do nível
             * de acesso a dados são capturados pelo serviço e relançadas em forma
             * de exceções de serviço para o controlador*/
            try
            {
            }
            catch (DbUpdateConcurrencyException e)
            {
                throw new DbConcurrencyException(e.Message);
            }
            _context.Update(obj);
            await _context.SaveChangesAsync();
        }
예제 #7
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Ativo,DataCadastro,UltimaAtualizacao,Deletado,DeletadoData,Descricao,EmpresaId," +
                                                             "PessoaCliente," +
                                                             "PessoaFornecedor," +
                                                             "PessoaFisica," +
                                                             "PessoaJuridica," +
                                                             "PessoaUsuario")] Pessoa pessoa)
        {
            if (id != pessoa.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(pessoa);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PessoaExists(pessoa.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(pessoa));
        }
예제 #8
0
 public void Update(Seller obj)
 {
     if (!_context.Seller.Any(s => s.Id == obj.Id))
     {
         throw new NotFoundException("Seller´s Id not Found");
     }
     try
     {
         _context.Update(obj);
         _context.SaveChanges();
     }
     catch (DbUpdateConcurrencyException ex)
     {
         throw new DbConcurrencyException(ex.Message);
     }
 }
예제 #9
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] Department department)
        {
            if (id != department.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(department);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DepartmentExists(department.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(department));
        }
예제 #10
0
        public async Task UpdateAsync(Product obj)
        {
            bool hasAny = await _context.Product.AnyAsync(x => x.Id == obj.Id);

            if (!hasAny)
            {
                throw new NotFoundException("Id not found");
            }

            try
            {
                _context.Update(obj);
                await _context.SaveChangesAsync();
            }
            //Possivel exceção de concorrencia do banco de dados
            catch (DbUpdateConcurrencyException e)
            {
                /*
                 * --Importante para segregar as camadas--
                 * Interceptando uma exceção do nivel de acesso a dados e relançando essa mesma exceção
                 * só que em nível de serviço.
                 * A minha camada de serviço, não irá propagar uma exceção de acesso a dados, pois caso aconteça
                 * ela lançara uma exceção da camada dela mesmo.
                 * Sendo assim, o controlador apenas irá lidar com a exceção da camada de serviço.
                 */
                throw new DbConcurrencyException(e.Message);
            }
        }
예제 #11
0
        public async Task <IActionResult> Edit(int id, [Bind("Menu,Url,Id,Ativo,DataCadastro,UltimaAtualizacao,Deletado,DeletadoData")] MenuUl menuUl)
        {
            if (id != menuUl.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(menuUl);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MenuUlExists(menuUl.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(menuUl));
        }
예제 #12
0
        public void Update(Seller obj)
        {
            if (!_context.Seller.Any(x => x.Id == obj.Id)) //verificando se existe algum vendedor x cujo o id seja igual o id do objeto
            {                                              //se não existir
                throw new NotFoundException("Não existe esse Id");
            }
            _context.Update(obj);

            try
            {
                _context.Update(obj);
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException e)
            {
                throw new DbConcurrencyException(e.Message);
            }
        }
예제 #13
0
        public void Update(Seller seller)
        {
            //any retorna true se existe no banco de dados o que vc colocar entre parenteses
            if (!_context.Seller.Any(x => x.Id == seller.Id))
            {
                throw new NotFoundException("Id not found");
            }

            try
            {
                _context.Update(seller);
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException e)
            {
                throw new DbConcurrencyException(e.Message);
            }
        }
 public async Task UpdateDepartment(Department department)
 {
     try {
         _context.Update(department);
         await _context.SaveChangesAsync();
     }
     catch (DbConcurrencyException ex)
     {
         throw new DbConcurrencyException(ex.Message);
     }
 }
        public async Task UpdateAsync(Seller obj)
        {
            bool hasAny = await _context.Seller.AnyAsync(x => x.Id == obj.Id);

            if (!hasAny)
            {
                throw new NotFoundException("Id not found");
            }
            _context.Update(obj);
            _context.SaveChanges();

            try
            {
                _context.Update(obj);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException e)
            {
                throw new DbConcurrencyException(e.Message);
            }
        }
예제 #16
0
 public void Update(Seller obj)
 {
     if (!_context.Seller.Any(x => x.Id == obj.Id))
     {
         throw new NotFoundException("Cód não localizado!");
     }
     try
     {
         _context.Update(obj);
         _context.SaveChanges();
     } catch (DbConcurrencyException e)
     {
         throw new DbConcurrencyException(e.Message);
     }
 }
예제 #17
0
        public async Task UpdateAsync(Seller seller)
        {
            bool hasAny = await _context.Seller.AnyAsync(item => item.Id == seller.Id);

            if (!hasAny)
            {
                throw new NotFoundException("Id not found");
            }
            try {
                _context.Update(seller);
                _context.SaveChanges();
            } catch (DbUpdateConcurrencyException e)
            {
                throw new DbConcurrencyException(e.Message);
            }
        }
예제 #18
0
 public void Update(Seller seller)
 {
     if (!_context.Seller.Any(s => s.Id == seller.Id))
     {
         throw new NotFoundException("ID not found!");
     }
     try
     {
         _context.Update(seller);
         _context.SaveChanges();
     }
     catch (DbConcurrencyException e)
     {
         throw new DbConcurrencyException(e.Message);
     }
 }
예제 #19
0
 public async Task UpddateAsync(Seller seller)
 {
     if (!await _context.Seller.AnyAsync(s => s.Id == seller.Id))
     {
         throw new NotFoundException("Vendedor não encontrado!");
     }
     try
     {
         _context.Update(seller);
         await _context.SaveChangesAsync();
     }
     catch (DbUpdateConcurrencyException e)
     {
         throw new DbConcurrencyException(e.Message);
     }
 }
예제 #20
0
        public async Task UpdateAsync(Seller seller)
        {
            if (!await _context.Seller.AnyAsync(x => x.Id == seller.Id))
            {
                throw new NotFoundException("Id not found");
            }

            try
            {
                _context.Update(seller);
                await _context.SaveChangesAsync();
            }catch (DbUpdateConcurrencyException e) // captura a exceção de banco e traduz ela para exceção a nível de serviço
            {
                throw new DbConcurrencyException(e.Message);
            }
        }
예제 #21
0
 public async Task UpdateAsync(SalesRecord obj)
 {
     if (!await _context.SalesRecord.AnyAsync(x => x.Id == obj.Id))
     {
         throw new NotFoundException("I");
     }
     try
     {
         _context.Update(obj);
         await _context.SaveChangesAsync();
     }
     catch (DbUpdateConcurrencyException e)
     {
         throw new DbConcurrencyException(e.Message);
     }
 }
예제 #22
0
 public void Update(Seller obj)
 {
     if (!_context.Seller.Any(x => x.Id == obj.Id)) //Testando se o objeto a receber o Update existe no banco, caso não, retorna um Erro.
     {
         throw new NotFoundException("ID not found");
     }
     try
     {
         _context.Update(obj);
         _context.SaveChanges();
     }
     catch (DbUpdateConcurrencyException e)
     {
         throw new DbConcurrencyException(e.Message);
     }
 }
예제 #23
0
 public void Update(Vendedor obj)
 {
     if (!_context.vendedors.Any(x => x.Id == obj.Id))
     {
         throw new NotFoundException("Id not found");
     }
     try
     {
         _context.Update(obj);
         _context.SaveChanges();
     }
     catch (DbUpdateConcurrencyException e)
     {
         throw new DbConcurrencyException(e.Message);
     }
 }
예제 #24
0
 public void Update(Seller vendedor)
 {
     if (!_context.Seller.Any(obj => obj.Id == vendedor.Id))
     {
         throw new NotFoundException("Id not found");
     }
     try
     {
         _context.Update(vendedor);
         _context.SaveChanges();
     }
     catch (DbUpdateConcurrencyException e)
     {
         throw new DbConcurrencyException(e.Message);
     }
 }
예제 #25
0
 public async Task UpdateAsync(Seller seller)
 {
     if (!await _context.Seller.AnyAsync(x => x.Id == seller.Id))
     {
         throw new NotFoundException("Id not Found");
     }
     try
     {
         _context.Update(seller);
         await _context.SaveChangesAsync();
     }
     catch (DbUpdateConcurrencyException ex)
     {
         throw new DbConcurrenyException(ex.Message);
     }
 }
예제 #26
0
 public void Update(Seller obj)
 {
     if (!_context.Seller.Any(x => x.Id == obj.Id))
     {
         throw new NotFoundException("Não Existe nenhum funcionario com esse IID");
     }
     try
     {
         _context.Update(obj);
         _context.SaveChanges();
     }
     catch (DbUpdateConcurrencyException e)
     {
         throw new DbConcurrencyException(e.Message);
     }
 }
예제 #27
0
 public async Task UpdateAsync(Seller obj)
 {
     if (!await _context.Seller.AnyAsync(selObj => selObj.Id == obj.Id))
     {
         throw new NotFoundException("Id not found");
     }
     try
     {
         _context.Update(obj);
         await _context.SaveChangesAsync();
     }
     catch (DbUpdateConcurrencyException e)
     {
         throw new DbConcurrencyException(e.Message);
     }
 }
예제 #28
0
        public async Task UpdateAsync(Seller obj)
        {
            bool hasAny = await _context.Seller.AnyAsync(x => x.Id == obj.Id);

            if (!hasAny)
            {
                throw new NotFoundException("Id not fount");
            }
            try
            {
                _context.Update(obj);
                await _context.SaveChangesAsync();
            }catch (DbUpdateConcurrencyException e)          //Interceptando uma excessão de nível de acesso a dados e transformando em excessão de nível de serviço
            {
                throw new DbConcurrencyException(e.Message); //Excessão a nível de serviço
            }
        }
예제 #29
0
 public void Update(Seller obj)
 {
     if (!_context.Seller.Any(x => x.Id == obj.Id))
     {
         throw new NotFoundException("Id not found");
     }
     try
     {
         _context.Update(obj);
         _context.SaveChanges();
     }
     catch (DbConcurrencyException e)
     {
         throw new DbConcurrencyException(e.Message);
     }
     // With this try catch method the application layered structure is maintained (segregated) - the service layer will not propagate an error that does not belong to services(access data layer error). This way the Controller only has to deal with exceptions from the service layer
 }
        public void Update(Seller obj)
        {
            if (!_context.Seller.Any(x => x.id == obj.id))
            {
                throw new NotFoundException("Id não Encontrado");
            }

            try
            {
                _context.Update(obj);
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException e)
            {
                throw new DbConcurrencyExeption(e.Message);
            }
        }