public HttpResponseMessage GetClienteById(int id) { using (var context = new TexteContext()) { var cliente = context.Cliente.FirstOrDefault(u => u.Id == id); ClienteDTO clienteDTO = Mapper.Map <ClienteEntity, ClienteDTO>(cliente); return(Request.CreateResponse(HttpStatusCode.OK, cliente, "application/json")); } }
public HttpResponseMessage GetClientes() { using (var context = new TexteContext()) { var clientesEntity = context.Cliente.ToList(); List <ClienteDTO> clientes = Mapper.Map <List <ClienteEntity>, List <ClienteDTO> >(clientesEntity); return(Request.CreateResponse(HttpStatusCode.OK, clientes, "application/json")); } }
public HttpResponseMessage Delete(int id) { using (var context = new TexteContext()) { var cliente = context.Cliente.FirstOrDefault(u => u.Id == id); context.Entry <ClienteEntity>(cliente).State = EntityState.Deleted; context.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, cliente, "application/json")); } }
public HttpResponseMessage Update([FromBody] ClienteDTO cliente) { using (var context = new TexteContext()) { ClienteEntity clienteEntity = Mapper.Map <ClienteDTO, ClienteEntity>(cliente); var clientes = context.Entry(clienteEntity).State = EntityState.Modified; context.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, cliente, "application/json")); } }