public CustomerDetail Create(CustomerCreate create) { Customer customer = new Customer { Name = create.Name, Gold = create.Gold ?? false, Joined = DateTime.Now }; customer = _context.Customers.Add(customer); _context.SaveChanges(); return Detail(customer); }
/// <summary> /// Create a customer /// </summary> /// <param name="customer"></param> /// <returns>CustomerDetail</returns> public async System.Threading.Tasks.Task<CustomerDetail> CreateCustomerAsync (CustomerCreate customer) { var path_ = "/customers"; var pathParams = new Dictionary<String, String>(); var queryParams = new Dictionary<String, String>(); var headerParams = new Dictionary<String, String>(); var formParams = new Dictionary<String, String>(); var fileParams = new Dictionary<String, FileParameter>(); String postBody = null; // to determine the Accept header String[] http_header_accepts = new String[] { "application/json" }; String http_header_accept = ApiClient.SelectHeaderAccept(http_header_accepts); if (http_header_accept != null) headerParams.Add("Accept", ApiClient.SelectHeaderAccept(http_header_accepts)); // set "format" to json by default // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json pathParams.Add("format", "json"); postBody = ApiClient.Serialize(customer); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { }; // make the HTTP request IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path_, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings); if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling CreateCustomer: " + response.Content, response.Content); return (CustomerDetail) ApiClient.Deserialize(response, typeof(CustomerDetail)); }