当前位置: 首页>>代码示例>>C#>>正文


C# JsonData.OrEmpty方法代码示例

本文整理汇总了C#中JsonData.OrEmpty方法的典型用法代码示例。如果您正苦于以下问题:C# JsonData.OrEmpty方法的具体用法?C# JsonData.OrEmpty怎么用?C# JsonData.OrEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonData的用法示例。


在下文中一共展示了JsonData.OrEmpty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HView

        public static NitroBolt.Wui.HtmlResult<HElement> HView(MainState state, JsonData[] jsons, HttpRequestMessage request)
        {

            foreach (var json in jsons.OrEmpty())
            {
                switch (json.JPath("data", "command")?.ToString())
                {
                    case "new-order":
                        {
                            var name = json.JPath("data", "name")?.ToString() ?? "C";
                            var isDelivery = json.JPath("data", "is-delivery")?.ToString() == "True";
                            var toTime = ToTime(json.JPath("data", "to-time")?.ToString());
                            var status = toTime == null ? ProductStatus.New : ProductStatus.InQueue;
                            var products = name == "B" ? new[] { new Product("K", status) } : new[] { new Product("M", status), new Product("P", status) };
                            state = state.With(orders: state.Orders.Add(new Order(name: name, isDelivery: isDelivery, status: toTime == null ? OrderStatus.New : OrderStatus.InQueue, products: ImmutableArray.Create(products), toTime: toTime)));
                        }
                        break;
                    case "product-prepare":
                        {
                            var orderId = ConvertHlp.ToGuid(json.JPath("data", "order"));
                            var productId = ConvertHlp.ToGuid(json.JPath("data", "product"));
                            var order = state.Orders.FirstOrDefault(_order => _order.Id == orderId);
                            var product = order?.Products.OrEmpty().FirstOrDefault(_product => _product.Id == productId);
                            if (product != null && product.Status != ProductStatus.New)
                                product = null;
                            if (product != null)
                            {
                                state = state.With(orders: state.Orders.Replace(order, order.With(products: order.Products.Replace(product, product.With(status: ProductStatus.Prepare)))));
                            }
                        }
                        break;
                    case "product-ready":
                        {
                            var orderId = ConvertHlp.ToGuid(json.JPath("data", "order"));
                            var productId = ConvertHlp.ToGuid(json.JPath("data", "product"));
                            var order = state.Orders.FirstOrDefault(_order => _order.Id == orderId);
                            var product = order?.Products.OrEmpty().FirstOrDefault(_product => _product.Id == productId);
                            if (product != null && product.Status != ProductStatus.Prepare)
                                product = null;
                            if (product != null)
                            {
                                state = state.With(orders: state.Orders.Replace(order, order.With(products: order.Products.Replace(product, product.With(status: ProductStatus.Ready)))));
                            }
                        }
                        break;
                    case "order-build":
                        {
                            var orderId = ConvertHlp.ToGuid(json.JPath("data", "order"));
                            var order = state.Orders.FirstOrDefault(_order => _order.Id == orderId);
                            if (order != null && order.Status != OrderStatus.Prepare && !order.IsReady)
                                order = null;
                            if (order != null)
                            {
                                state = state.With(orders: state.Orders.Replace(order, order.With(status: OrderStatus.Ready)));
                            }
                        }
                        break;
                    case "courier":
                        {
                            var orderId = ConvertHlp.ToGuid(json.JPath("data", "order"));
                            var courier = json.JPath("data", "courier")?.ToString();
                            var order = state.Orders.FirstOrDefault(_order => _order.Id == orderId);
                            if (order != null && order.Status != OrderStatus.Ready && !order.IsDelivery)
                                order = null;
                            if (order != null)
                            {
                                state = state.With(orders: state.Orders.Replace(order, order.With(status: OrderStatus.ToDelivery, courier: courier)));
                            }
                        }
                        break;
                    case "order-deliveried":
                        {
                            var orderId = ConvertHlp.ToGuid(json.JPath("data", "order"));
                            var order = state.Orders.FirstOrDefault(_order => _order.Id == orderId);
                            if (order != null && order.Status != OrderStatus.ToDelivery)
                                order = null;
                            if (order != null)
                            {
                                state = state.With(orders: state.Orders.Replace(order, order.With(status: OrderStatus.Deliveried)));
                            }
                        }
                        break;
                    case "order-to-table":
                        {
                            var orderId = ConvertHlp.ToGuid(json.JPath("data", "order"));
                            var order = state.Orders.FirstOrDefault(_order => _order.Id == orderId);
                            if (order != null && order.Status != OrderStatus.Ready && order.IsDelivery)
                                order = null;
                            if (order != null)
                            {
                                state = state.With(orders: state.Orders.Replace(order, order.With(status: OrderStatus.ToTable)));
                            }
                        }
                        break;
                    default:
                        break;
                }
            }
            state = state.With(orders: DeQueue(state.Orders, DateTime.Now));

//.........这里部分代码省略.........
开发者ID:Serj-Tm,项目名称:NitroBolt.Wui,代码行数:101,代码来源:MainController.cs


注:本文中的JsonData.OrEmpty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。