Ejemplo n.º 1
0
        // GET /api/customers/1
        public IHttpActionResult GetCustomer(int id)
        {
            var customer = _db.Customers.SingleOrDefault(c => c.Id == id);

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

            var customerDto = CustomerDto.MapToCustomersDto(new List <Customer>()
            {
                (customer)
            }).Single();

            return(Ok(customerDto));
        }
Ejemplo n.º 2
0
        public IHttpActionResult PutCustomer(CustomerDto customerDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var dbCustomer = _db.Customers.SingleOrDefault(c => c.Id == customerDto.Id);

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

            dbCustomer = CustomerDto.MapFromCustomerDto(customerDto, dbCustomer);
            _db.SaveChanges();

            return(Ok(CustomerDto.MapToCustomersDto(new List <Customer>()
            {
                _db.Customers.SingleOrDefault(c => c.Id == dbCustomer.Id)
            }).Single()));
        }
Ejemplo n.º 3
0
 // GET /api/customers
 public IHttpActionResult GetCustomers()
 {
     return(Ok(CustomerDto.MapToCustomersDto(_db.Customers.ToList())));
 }