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));
            }
        }
Example #2
0
        string OrdersCommand(string message, string[] json)
        {
            Orders data = null;;

            if (json != null)
            {
                data = JsonConvert.DeserializeObject <Orders>(json[0]);
            }
            string outMessage = null;

            switch (message)
            {
            case "AddItem":
                OrdersMethods.AddItem(data);
                outMessage = "Добавленно";
                break;

            case "AddItems":
                List <Orders> list = new List <Orders>();
                int           i    = 0;
                foreach (var x in json)
                {
                    Orders u = JsonConvert.DeserializeObject <Orders>(json[i]);
                    list.Add(u);
                }
                OrdersMethods.AddItems(list);
                outMessage = "Добавленно";
                break;

            case "ChangeItem":
                if (OrdersMethods.ChangeItem(data) == true)
                {
                    outMessage = "Найден";
                }
                else
                {
                    outMessage = "Не найден";
                }
                break;

            case "DeleteItem":
                OrdersMethods.DeleteItem(Convert.ToInt32(json[0]));
                outMessage = "Удален";
                break;

            case "GetItem":
                string s = JsonConvert.SerializeObject(OrdersMethods.GetItem(Convert.ToInt32(json[0])));
                outMessage = s;
                break;

            case "Outpoot":
                string        outs        = null;
                List <Orders> unitWeights = OrdersMethods.Outpoot().ToList();
                foreach (var x in unitWeights)
                {
                    outs = $"{outs}!{JsonConvert.SerializeObject(x)}";
                }
                outMessage = outs;
                break;

            default:
                outMessage = "Orders connect";
                break;
            }
            return(outMessage);
        }