/// <summary> /// Create a new customer /// </summary> /// <param name="model"></param> public HttpResponseMessage Post(CustomerDetailModel model) { var customer = this.DataContext.Customers.Add(new Customer { Id = model.Id, Name = model.Name, Contact = new Contact { Name = model.ContactName, Title = model.ContactTitle, }, Address = model.Address, City = model.City, Region = model.Region, PostalCode = model.PostalCode, Country = model.Country, Phone = model.Phone, Fax = model.Fax, }); this.DataContext.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, customer); response.Headers.Location = new Uri(Url.Link("Api", new { controller = "Customers", id = customer.Id })); return response; }
/// <summary> /// Create a new customer /// </summary> /// <param name="model"></param> public HttpResponseMessage Put(CustomerDetailModel model) { var customer = this.DataContext.Customers.Find(model.Id); if (customer == null) { return Request.CreateResponse(HttpStatusCode.NotFound); } customer.Name = model.Name; customer.Contact = new Contact { Name = model.ContactName, Title = model.ContactTitle, }; customer.Address = model.Address; customer.City = model.City; customer.Region = model.Region; customer.PostalCode = model.PostalCode; customer.Country = model.Country; customer.Phone = model.Phone; customer.Fax = model.Fax; this.DataContext.SaveChanges(); return Request.CreateResponse(HttpStatusCode.OK, model); }