partial void DeleteCustomer(Customer instance);
partial void InsertCustomer(Customer instance);
partial void UpdateCustomer(Customer instance);
public AjaxFormResult SaveCustomer(string id, FormCollection values) { AjaxFormResult response = new AjaxFormResult(); try { //for example if (string.IsNullOrEmpty(values["CompanyName"])) { response.Success = false; response.Errors.Add(new FieldError("CompanyName", "The CompanyName field is required")); return response; } bool isNew = false; Customer customer; if(string.IsNullOrEmpty(id)) { if (string.IsNullOrEmpty(values["CustomerID"])) { response.Success = false; response.Errors.Add(new FieldError("CustomerID", "The CustomerID field is required")); return response; } customer = new Customer(); customer.CustomerID = values["CustomerID"]; isNew = true; } else { customer = (from c in this.DBContext.Customers where c.CustomerID == id select c).First(); } customer.CompanyName = values["CompanyName"]; customer.Address = values["Address"]; customer.City = values["City"]; customer.ContactName = values["ContactName"]; customer.ContactTitle = values["ContactTitle"]; customer.Country = values["Country"]; customer.Fax = values["Fax"]; customer.Phone = values["Phone"]; customer.PostalCode = values["PostalCode"]; customer.Region = values["Region"]; if(isNew) { this.DBContext.Customers.InsertOnSubmit(customer); } this.DBContext.SubmitChanges(); response.ExtraParams["newID"] = customer.CustomerID.ToString(); } catch (Exception e) { response.Success = false; response.ExtraParams["msg"] = e.ToString(); } return response; }