Пример #1
0
        public async Task <IHttpActionResult> PostCustomer(Customer c)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var customer = new GOLD.CustomerDomain.DataAccess.Customer {
                ID = c.ID, DOB = c.DOB, FirstName = c.FirstName, Gender = c.Gender, LastName = c.LastName, NINO = c.NINO, Title = c.Title
            };

            db.Customers.Add(customer);

            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = c.ID }, c));
        }
Пример #2
0
        public async Task <IHttpActionResult> PutCustomer(int id, Customer c)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != c.ID)
            {
                return(BadRequest());
            }

            var customer = new GOLD.CustomerDomain.DataAccess.Customer {
                ID = c.ID, DOB = c.DOB, FirstName = c.FirstName, Gender = c.Gender, LastName = c.LastName, NINO = c.NINO, Title = c.Title
            };

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }