Esempio n. 1
0
        public IHttpActionResult CreateCustomer(CustomerDTo customerDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var customer = Mapper.Map <CustomerDTo, customer>(customerDto);

            _context.Customer.Add(customer);
            _context.SaveChanges();

            customerDto.id = customer.id;
            return(Created(new Uri(Request.RequestUri + "/" + customer.id), customerDto));
        }
Esempio n. 2
0
        public IHttpActionResult UpdateCustomer(int id, CustomerDTo customerDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var customerInDb = _context.Customer.SingleOrDefault(c => c.id == id);

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

            Mapper.Map(customerDto, customerInDb);

            _context.SaveChanges();

            return(Ok());
        }