Пример #1
0
        public async Task RemovePhysical(T obj)
        {
            try
            {
                using (DbContext = new LojaContext())
                {
                    DbContext.Configuration.AutoDetectChangesEnabled = false;

                    DbContext.Entry(obj).State = EntityState.Deleted;
                    await DbContext.SaveChangesAsync();

                    DbContext.Configuration.AutoDetectChangesEnabled = true;
                }
            }
            catch (Exception ex)
            {
                if (ex.Message == "An error occurred while updating the entries. See the inner exception for details.")
                {
                    throw new Exception("Não é possivel excluir Existem Cadastro Relacionados");
                }
                else
                {
                    throw new Exception(ex.Message);
                }
            }
        }
Пример #2
0
        public async Task <IActionResult> PutConsultor([FromRoute] int id, [FromBody] Consultor consultor)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != consultor.Id)
            {
                return(BadRequest());
            }

            _context.Entry(consultor).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ConsultorExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #3
0
        public IHttpActionResult PutCategoriaPg(int id, CategoriaPg categoriaPg)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != categoriaPg.Id)
            {
                return(BadRequest());
            }

            db.Entry(categoriaPg).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategoriaPgExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #4
0
        public void Alterar(Cliente cliente)
        {
            LojaContext context = new LojaContext();

            context.Entry(cliente).State = System.Data.Entity.EntityState.Modified;

            context.SaveChanges();
        }
Пример #5
0
        public ActionResult Edit(Produto produto)
        {
            try
            {
                // TODO: Add update logic here
                if (ModelState.IsValid)
                {
                    db.Entry(produto).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Пример #6
0
        public async Task <IActionResult> PutCliente([FromRoute] int id, [FromBody] Cliente cliente)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != cliente.Id)
            {
                return(BadRequest());
            }

            _context.Entry(cliente).State = EntityState.Modified;

            foreach (var telefone in cliente.Telefones)
            {
                if (telefone.Id > 0)
                {
                    _context.Entry(telefone).State = EntityState.Modified;
                }
                else
                {
                    _context.Entry(telefone).State = EntityState.Added;
                }
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ClienteExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #7
0
        public void Excluir(int id)
        {
            LojaContext context = new LojaContext();

            Cliente cliente = context.Cliente.Find(id);

            context.Entry(cliente).State = System.Data.Entity.EntityState.Deleted;

            context.SaveChanges();
        }
Пример #8
0
 public ActionResult Edit([Bind(Include = "ID,DDD,Numero")] Telefone telefone)
 {
     if (ModelState.IsValid)
     {
         db.Entry(telefone).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(telefone));
 }
 public ActionResult Edit([Bind(Include = "Id,Nome")] Consultor consultor)
 {
     if (ModelState.IsValid)
     {
         db.Entry(consultor).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(consultor));
 }
Пример #10
0
        public void Alterar(Marca marca)
        {
            //criar classe de contexto
            LojaContext context = new LojaContext();

            context.Entry(marca).State = System.Data.Entity.EntityState.Modified;

            //salvar a alteração
            context.SaveChanges();
        }
Пример #11
0
 public ActionResult Edit([Bind(Include = "ID,CodCli,Cliente,Data,Total")] Vendas vendas)
 {
     if (ModelState.IsValid)
     {
         db.Entry(vendas).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(vendas));
 }
Пример #12
0
 public ActionResult Edit([Bind(Include = "Id,Descricao")] CategoriaPg categoriaPg)
 {
     if (ModelState.IsValid)
     {
         db.Entry(categoriaPg).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(categoriaPg));
 }
Пример #13
0
 public ActionResult Edit([Bind(Include = "Id,Pedido,Produto,QuantProd,ValUnit")] VendasItens vendasItens)
 {
     if (ModelState.IsValid)
     {
         db.Entry(vendasItens).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(vendasItens));
 }
Пример #14
0
 public ActionResult Edit([Bind(Include = "ID,Nome,Email,TelefoneId")] Cliente cliente)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cliente).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(cliente));
 }
Пример #15
0
        public void Alterar(Mercado mercado)
        {
            //criar a classe de contexto
            LojaContext context = new LojaContext();

            //informar ao context que um objeto foi alterado
            context.Entry(mercado).State = System.Data.Entity.EntityState.Modified;

            //salvar as alterações
            context.SaveChanges();
        }
 public ActionResult Edit([Bind(Include = "Id,Nome,Preco,DataCadastro,IdCategoria,Ativo")] Produto produto)
 {
     if (ModelState.IsValid)
     {
         db.Entry(produto).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.IdCategoria = new SelectList(db.Categoria, "Id", "Nome", produto.IdCategoria);
     return(View(produto));
 }
Пример #17
0
        public async Task RemoveLogic(int id, T obj)
        {
            using (DbContext = new LojaContext())
            {
                DbContext.Configuration.AutoDetectChangesEnabled = false;
                DbContext.Entry(obj).State = EntityState.Modified;
                await DbContext.SaveChangesAsync();

                DbContext.Configuration.AutoDetectChangesEnabled = true;
            }
        }
Пример #18
0
        public void Atualizar(Cliente cliente)
        {
            var local = _context.Clientes.Local.FirstOrDefault(c => c.ClienteId == cliente.ClienteId);

            if (local != null)
            {
                _context.Entry(local).State = EntityState.Detached;
            }

            _context.Clientes.Update(cliente);
        }
Пример #19
0
        public void Alterar(Produto produto)
        {
            //instanciando a classe de contexto
            LojaContext context = new LojaContext();

            //Informando a classe de contexo o status do produto MODIFIED
            context.Entry(produto).State = System.Data.Entity.EntityState.Modified;

            //salvando as alterações
            context.SaveChanges();
        }
 public void Insert(Fornecedor fornecedor)
 {
     if (fornecedor.Id > 0)
     {
         lojaContext.Entry(fornecedor).State = EntityState.Modified;
     }
     else
     {
         lojaContext.Fornecedores.Add(fornecedor);
     }
     lojaContext.SaveChanges();
 }
Пример #21
0
 public void Inserir(Produto produto)
 {
     if (produto.Id > 0)
     {
         lojaContext.Entry(produto).State = EntityState.Modified;
     }
     else
     {
         lojaContext.Produtos.Add(produto);
     }
     lojaContext.SaveChanges();
 }
 public void Insert(Usuario usuario)
 {
     if (usuario.Id > 0)
     {
         lojaContext.Entry(usuario).State = EntityState.Modified;
     }
     else
     {
         lojaContext.Usuarios.Add(usuario);
     }
     lojaContext.SaveChanges();
 }
 public ActionResult Edit([Bind(Include = "Id,Nome,Email,IdConsultor,Telefones")] Cliente cliente)
 {
     if (ModelState.IsValid)
     {
         foreach (var telefone in cliente.Telefones)
         {
             if (telefone.Id > 0)
             {
                 db.Entry(telefone).State = EntityState.Modified;
             }
             else
             {
                 db.Entry(telefone).State = EntityState.Added;
             }
         }
         db.Entry(cliente).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.IdConsultor = new SelectList(db.Consultores, "Id", "Nome", cliente.IdConsultor);
     return(View(cliente));
 }
Пример #24
0
        public void Excluir(int id)
        {
            //Instanciando a classe contexto
            LojaContext context = new LojaContext();

            //Efetuando busca por um ID
            Produto produto = context.Produto.Find(id);

            //Informa ao contexto que um objeto foi deletado
            context.Entry(produto).State = System.Data.Entity.EntityState.Deleted;

            context.SaveChanges();
        }
Пример #25
0
        public void Excluir(int Id)
        {
            //criar classe de contexto
            LojaContext context = new LojaContext();

            //recuperar o objeto por ID
            Marca marca = context.Marca.Find(Id);

            context.Entry(marca).State = System.Data.Entity.EntityState.Deleted;

            //informa ao contexto que houve alteração
            context.SaveChanges();
        }
Пример #26
0
        public void Atualizar(Produto produto)
        {
            //Pesquisar o produto que está gerenciado
            var local = _context.Produtos.Local.FirstOrDefault(p => p.ProdutoId == produto.ProdutoId);

            //Remover o produto do gerenciamento
            if (local != null)
            {
                _context.Entry(local).State = EntityState.Detached;
            }

            _context.Produtos.Update(produto);
        }
Пример #27
0
        public async Task Update(T obj)
        {
            new Util <T>().SetUpdateObject(ref obj);


            using (DbContext = new LojaContext())
            {
                DbContext.Configuration.AutoDetectChangesEnabled = false;
                DbContext.Entry(obj).State = EntityState.Modified;
                await DbContext.SaveChangesAsync();

                DbContext.Configuration.AutoDetectChangesEnabled = true;
            }
        }
        public Cliente Salvar(Cliente cliente)
        {
            //verificar se é para Add ou Update
            var estado = cliente.Id == 0 ? EntityState.Added : EntityState.Modified;

            //salvar esse estado no contexto
            _context.Entry(cliente).State = estado;

            //persistir esses dados - salvá-los
            _context.SaveChanges();

            //retorna o objeto
            return(cliente);
        }
Пример #29
0
 public ActionResult Atualiza(int id, Produto produto)
 {
     try
     {
         // TODO: Add update logic here
         contexto.Entry(produto).State = EntityState.Modified;
         contexto.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
        public Produto Salvar(Produto produto)
        {
            //verificar se é para Add ou Update
            var estado = produto.Id == 0 ? EntityState.Added : EntityState.Modified;

            //salvar esse estado no contexto
            _context.Entry(produto).State = estado;

            //persistir esses dados - salvá-los
            _context.SaveChanges();

            //retorna o objeto
            return(produto);
        }