public void InsertOrUpdate(ClientSupplier entity) { if (entity.ClientID == default(int)) { _context.SetAdd(entity); } else { _context.SetModified(entity); } }
public async Task <ActionResult> Delete(int id) { if (id < 1) { return(BadRequest()); } ClientSupplier clientSupplier = await context.ClientSuppliers.FindAsync(id); if (clientSupplier == null) { return(NotFound()); } context.ClientSuppliers.Remove(clientSupplier); await context.SaveChangesAsync(); return(Ok("Registro removido com sucesso")); }
public async Task <ActionResult <ClientSupplier> > Post(ClientSupplierDto clientSupplierdto) { if (clientSupplierdto == null) { return(BadRequest()); } var clientSupplier = new ClientSupplier(); var client = from c in context.Clients where c.Cpf == clientSupplierdto.ClientCpf select new ClientDto { Id = c.Id, Name = c.Name, Cpf = c.Cpf, Cep = c.Cep, CreationDate = c.CreationDate }; clientSupplier.ClientId = client.First().Id; var supplier = from s in context.Suppliers where s.Cnpj == clientSupplierdto.SupplierCnpj select new SupplierDto { Id = s.Id, Name = s.Name, Cnpj = s.Cnpj, Cep = s.Cep, CreationDate = s.CreationDate }; clientSupplier.SupplierId = supplier.First().Id; context.ClientSuppliers.Add(clientSupplier); await context.SaveChangesAsync(); return(CreatedAtAction("Get", new { id = clientSupplier.Id }, clientSupplier)); }