示例#1
0
 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"));
     }
 }
示例#2
0
 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"));
     }
 }
示例#3
0
 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"));
     }
 }
示例#4
0
 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"));
     }
 }