public async Task <bool> SyncCustomer(string shopname, string token, string serverurl) { bool response = true; try { string shopifyurl = $"https://{shopname}.myshopify.com/"; CustomerDetailModel cdm = new CustomerDetailModel(); cdm.token = token; cdm.shopifyurl = shopifyurl; List <Customer> customersList = await GetAllCustomers(cdm); List <CustomerReturnModel> customerReturns = await GetCustomerReturnModel(customersList, shopname); var client = new HttpClient(); string json = JsonConvert.SerializeObject(customerReturns); string apiUrl2 = $"{serverurl}/api/AddShopifyCustomers"; var response2 = client.PostAsJsonAsync(apiUrl2, customerReturns).Result; response2.EnsureSuccessStatusCode(); string responseBody1 = await response2.Content.ReadAsStringAsync(); var readString = JObject.Parse(responseBody1)["status"]; response = Convert.ToBoolean(readString.ToString()); } catch (Exception) { throw; } return(response); }
public async Task <List <Customer> > GetAllCustomers(CustomerDetailModel model) { string msg; List <Customer> Customers = new List <Customer>(); try { var allCustomers = new List <Customer>(); var service = new CustomerService(model.shopifyurl, model.token); var page = await service.ListAsync(new CustomerListFilter { Limit = 250, }); while (true) { allCustomers.AddRange(page.Items); if (!page.HasNextPage) { break; } page = await service.ListAsync(page.GetNextPageFilter()); } Customers = allCustomers; } catch (Exception ex) { msg = ex.Message.ToString(); } return(Customers); }