public async Task <dynamic> Get(string companyName) { if (CheckClientSecret()) { using (HttpClient client = new HttpClient()) using (Entities db = new Entities()) { if (db.StoreCustomDatas.Any(x => x.StoreName == companyName) && db.StoreCustomDatas.FirstOrDefault(x => x.StoreName == companyName).ShopifyID != null) { StoreCustomData store = db.StoreCustomDatas.FirstOrDefault(x => x.StoreName == companyName); ShopifyCredential credentials = db .ShopifyCredentials .Where(x => x.ID == store.ShopifyID) .FirstOrDefault(); client.DefaultRequestHeaders.Add("X-Shopify-Access-Token", credentials.Password); string shopifyAPIVersion = ConfigDictionary.Config()["ShopifyAdminAPIVersion"]; DateTimeOffset thisMonth = new DateTimeOffset(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 1, 0, 0, 0, TimeSpan.Zero); DateTimeOffset lastMonth = thisMonth.AddMonths(-1); DateTimeOffset monthBeforeLast = thisMonth.AddMonths(-2); try { int?ordersThisMonth = await OrdersMethods.OrdersCount(client, credentials.HostName, shopifyAPIVersion, thisMonth.ToString("yyyy-MM-ddTHH:mm:ss zzz")); int?ordersLastMonth = await OrdersMethods.OrdersCount(client, credentials.HostName, shopifyAPIVersion, lastMonth.ToString("yyyy-MM-ddTHH:mm:ss zzz")); int?ordersMonthBeforeLast = await OrdersMethods.OrdersCount(client, credentials.HostName, shopifyAPIVersion, monthBeforeLast.ToString("yyyy-MM-ddTHH:mm:ss zzz")); return(new OrdersCountDTO(ordersThisMonth, ordersLastMonth, ordersMonthBeforeLast)); } catch (Exception ex) { return(ex); } } else { return(new ArgumentException($"No store was found with the name {companyName}")); } } } else { return(new HttpResponseMessage(System.Net.HttpStatusCode.Forbidden)); } }