Exemple #1
0
        public IHttpActionResult CreateCustomer(CUstomerDto customerDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

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

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

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

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

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

            Mapper.Map(customerDto, customerInDb);
            _context.SaveChanges();

            return(Ok());
        }