コード例 #1
0
 public ActionResult Edit([Bind(Include = "Id,Nome,CPF,DataNascimento,Genero,Telefones")] Cliente cliente)
 {
     if (ModelState.IsValid)
     {
         if (cliente.Telefones != null)
         {
             foreach (var telefone in cliente.Telefones)
             {
                 telefone.IdCliente = cliente.Id;
                 if (telefone.DDD != null || telefone.Numero != null)
                 {
                     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"));
     }
     return(View(cliente));
 }
コード例 #2
0
        //[Authorize(Roles = "admin,vendedor")]

        public async Task <IActionResult> PutProduct(int id, Product product)
        {
            if (id != product.id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #3
0
        public async Task <IActionResult> PutEndereco(int id, Endereco endereco)
        {
            if (id != endereco.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #4
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;

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

            return(NoContent());
        }
        public async Task <IActionResult> PutCliente(long id, Cliente cliente)
        {
            var header = Request.Headers["X-Debug"];

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

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

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

            if (header.ToString() == "true")
            {
                AddHttpHeaders(Response);
                printLog();
            }

            return(NoContent());
        }
コード例 #6
0
        //[Authorize(Roles = "admin,vendedor")]
        public async Task <IActionResult> PutCustomers(int id, Customers customers)
        {
            if (id != customers.id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #7
0
 public async Task UpdateAsync(TEntity entity)
 {
     _context.Attach(entity);
     _context.Update <TEntity>(entity);
     _context.Entry(entity).State = EntityState.Modified;
     await _context.SaveChangesAsync();
 }
コード例 #8
0
        //[Authorize(Roles = "admin")]

        public async Task <IActionResult> PutNaturalPerson(int id, NaturalPerson naturalPerson)
        {
            if (id != naturalPerson.id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #9
0
        public TEntity Atualizar(TEntity entidade)
        {
            var entry = Db.Entry(entidade);

            DbSet.Attach(entidade);
            entry.State = EntityState.Modified;
            return(entidade);
        }
コード例 #10
0
 public int Editar(Conta conta)
 {
     using (var context = new ClienteContext())
     {
         context.Contas.Attach(conta);
         context.Entry(conta).State = EntityState.Modified;
         return(context.SaveChanges());
     }
 }
コード例 #11
0
        public void Update(TEntity entity)
        {
            var entityDB = DbSet.Find(entity.Id);

            entity.Usuario       = _variables.UserName;
            entity.DataAlteracao = DateTime.Now;
            _context.Entry(entityDB).CurrentValues.SetValues(entity);
            DbSet.Update(entityDB);
        }
 public ActionResult Edit([Bind(Include = "Id,Nome,DataCadastro")] Cliente cliente)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cliente).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(cliente));
 }
コード例 #13
0
 public ActionResult Edit([Bind(Include = "Id,Nome,Endereco,Telefone,Email,DataNascimento,Ativo")] Cliente cliente)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cliente).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(cliente));
 }
コード例 #14
0
        public async Task <IActionResult> PutClienteItem(int id, ClienteItem item)
        {
            if (id != item.Id)
            {
                return(BadRequest());
            }
            _context.Entry(item).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
コード例 #15
0
 public ActionResult Edit(Cliente cliente)
 {
     if (ModelState.IsValid)
     {
         cliente.DataAlteracao   = DateTime.Now;
         db.Entry(cliente).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(cliente));
 }
コード例 #16
0
        public async Task <IActionResult> PutConductorItem(string identificacion, ConductorItem item)
        {
            if (identificacion != item.Identificacion)
            {
                return(BadRequest());
            }

            _context.Entry(item).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
コード例 #17
0
        public async Task <IActionResult> PutVehiculoItem(string placa, VehiculoItem item)
        {
            if (placa != item.Placa)
            {
                return(BadRequest());
            }

            _context.Entry(item).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
コード例 #18
0
        public async Task <Models.Cliente> Atualizar(Models.Cliente cliente)
        {
            using (var context = new ClienteContext())
            {
                context.Entry(await context.Clientes.FirstOrDefaultAsync(f => f.Id == cliente.Id)).CurrentValues.SetValues(cliente);

                if ((await context.SaveChangesAsync()) > 0)
                {
                    return(cliente);
                }

                return(null);
            }
        }
コード例 #19
0
        public IHttpActionResult DeleteTelefone(int idCliente, int idTelefone)
        {
            var cliente = db.Clientes.Find(idCliente);

            if (cliente == null)
            {
                return(NotFound());
            }

            var telefone = cliente.Telefones.FirstOrDefault(t => t.Id == idTelefone);

            if (telefone == null)
            {
                return(NotFound());
            }

            db.Entry(telefone).State = EntityState.Deleted;

            db.SaveChanges();

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #20
0
        public IHttpActionResult PutCliente(int id, Cliente cliente)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != cliente.Id)
            {
                return(BadRequest("O id informado na URL é diferente do id informado no corpo da requisição"));
            }

            if (db.Clientes.Count(c => c.Id == id) == 0)
            {
                return(NotFound());
            }

            db.Entry(cliente).State = EntityState.Modified;
            db.SaveChanges();

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #21
0
 public async Task <IActionResult> Update(long id, Cliente clientes)
 {
     if (id != clientes.Id)
     {
         return(BadRequest());
     }
     _context.Entry(clientes).State = EntityState.Modified;
     try
     {
         await _context.SaveChangesAsync();
     }
     catch (DbUpdateConcurrencyException)
     {
         if (!ClienteExiste(id))
         {
             return(NotFound());
         }
         else
         {
             throw;
         }
     }
     return(NoContent());
 }
コード例 #22
0
        public async Task <IActionResult> PutClienteModel(ClienteModel ClienteModel)
        {
            try
            {
                var cliente = _context.Find <ClienteModel>(ClienteModel.Id);

                if (cliente == null)
                {
                    return(NotFound());
                }

                _context.Entry(cliente).State = EntityState.Detached;
                cliente = ClienteModel;
                _context.Update(cliente);
                await _context.SaveChangesAsync();

                return(NoContent());
            }
            catch (Exception ex)
            {
                var exception = ex;
                return(BadRequest());
            }
        }
コード例 #23
0
        } //Search

        public virtual void Update(T entity)
        {
            _context.Entry(entity).State = EntityState.Modified;
            _context.SaveChanges();
        } //Update
コード例 #24
0
ファイル: EFRepository.cs プロジェクト: murilomm/SGC_API
 public virtual void Atualizar(TEntity entity)
 {
     _dbContext.Entry(entity).State = EntityState.Modified;
     _dbContext.SaveChanges();
 }
コード例 #25
0
 public virtual void Atualizar(TEntity entity)
 {
     _dbContext.Entry(entity).State = EntityState.Modified; // entrei no contexto... para o estado de modificação
     _dbContext.SaveChanges();
 }
コード例 #26
0
 public Cliente Alterar(Cliente cliente)
 {
     db.Entry(cliente).State = EntityState.Modified;
     db.SaveChanges();
     return(cliente);
 }
コード例 #27
0
 public void Atualizar(Models.Cliente cliente)
 {
     _context.Entry(cliente).State = System.Data.Entity.EntityState.Modified;
 }
コード例 #28
0
 public void Atualizar(TEntity entity)
 {
     _dbContext.Entry(entity).State = EntityState.Modified;
 }
コード例 #29
0
 public void Atualizar(Endereco endereco)
 {
     _context.Entry(endereco).State = System.Data.Entity.EntityState.Modified;
 }