public static ApiCustomerPhone GetCustomerPhone(int id) { var customerPhone = db.Customer_Phone.Find(id); var customerPhoneApi = new ApiCustomerPhone(); PropertyCopier <Customer_Phone, ApiCustomerPhone> .Copy(customerPhone, customerPhoneApi, true); return(customerPhoneApi); }
public static void PutCustomerPhone(int id, ApiCustomerPhone acp) { // Create a new car Customer_Phone cp = db.Customer_Phone.Find(id); // Copy car if (acp.CustomerPhoneId == id) { PropertyCopier <ApiCustomerPhone, Customer_Phone> .Copy(acp, cp, true); db.Entry(cp).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } }
public static void PostCustomerPhone(ApiCustomerPhone pc) { // Create a new EF Customer. Customer_Phone p = new Customer_Phone(); // Copy the Simplified customer to the EF customer using the tool I provided. PropertyCopier <ApiCustomerPhone, Customer_Phone> .Copy(pc, p, true); // Tell EF we want to add the customer. db.Customer_Phone.Add(p); //Save changes db.SaveChanges(); }
public HttpResponseMessage PostCustomerPhones([FromBody] ApiCustomerPhone cp) { try { DBAccess.PostCustomerPhone(cp); } catch (Exception e) { // ERROR return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Cannot create record.")); } // All OK return(Request.CreateResponse(HttpStatusCode.OK)); }
public HttpResponseMessage PutCustomerPhone(int id, [FromBody] ApiCustomerPhone acp) { try { // Persist our change. DBAccess.PutCustomerPhone(id, acp); } catch (Exception e) { // ERROR return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Cannot update record: " + e)); } // All OK return(Request.CreateResponse(HttpStatusCode.OK)); }