Beispiel #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));
        }
Beispiel #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()));
        }
Beispiel #3
0
 // GET /api/customers
 public IHttpActionResult GetCustomers()
 {
     return(Ok(CustomerDto.MapToCustomersDto(_db.Customers.ToList())));
 }