예제 #1
0
        public IHttpActionResult PutCustomer(int id, Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != customer.CustId)
            {
                return(BadRequest());
            }

            db.Entry(customer).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #2
0
        public Customer Add(Customer customer)
        {
            var addCustomer = _context.Add(customer);

            _context.SaveChanges();
            customer.Id = addCustomer.Entity.Id;
            return(customer);
        }
예제 #3
0
 public Customer CreateCustomer(Customer customerToCreate)
 {
     _context.Attach(customerToCreate).State = EntityState.Added;
     _context.SaveChanges();
     return(customerToCreate);
 }