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


C# List.FirstOrDefault方法代码示例

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


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

示例1: GetContent

 Content GetContent(object obj)
 {
     var text = obj as string;
     var contentList = new List<Content>() { Content1, Content2, Content3, Content4 };
     var content = contentList.FirstOrDefault(c => c.Value == text);
     return content;
 }
开发者ID:bizmonger,项目名称:ClipPaste,代码行数:7,代码来源:ViewModel.support.cs

示例2: InsertOrder

        public string InsertOrder(Orders Order, List<Entities.Basket> BasketList = null)
        {
            Page page = HttpContext.Current.Handler as Page;
            if (!page.ModelState.IsValid)
            {
                return "";
            }

            if (BasketList == null)
            {
                BasketList = BasketLogic.GetBasket();
            }

            if (BasketList.Count == 0)
            {
                SiteLogic.AddError(Resources.mod.OrderProductsNotFound);
                return "";
            }

            Order.ReferenceCode = (new MiscLogic()).GenerateRandomCode();
            Order.UserId = 0;
            Order.StatusId = (int)OrderStatus.New; //New order
            Order.Total = BasketLogic.GetTotalPrice();
            Order.Tax = 0;
            //Order.ShippingPrice = BasketLogic.GetShippingPrice(Order.ShippingMethod);
            //Order.Discount = BasketLogic.getOrderDiscount(BasketList);
            Order.PaypalEmail = BasketList.FirstOrDefault(b => !string.IsNullOrEmpty(b.Event.PaypalEmail)).Event.PaypalEmail;
            Order.DateCreated = DateTime.Now;

            db.Orders.Add(Order);
            db.SaveChanges();

            foreach (var product in BasketList)
            {
                db.OrderProducts.Add(new OrderProducts()
                {
                    ProductId = product.TicketId,
                    Name = product.Event.Name + "- " + product.Ticket.Name,
                    EventId = product.EventId,
                    Pic = product.Pic,
                    Quantity = product.Quantity,
                    Price = product.Ticket.Price.HasValue ? product.Ticket.Price.Value : 0,
                    OrderId = Order.OrdersId,
                    UserId = Order.UserId.ToString(),
                    DateCreated = DateTime.Now
                });
            }

            db.SaveChanges();
            string redirect = "";
            if(Order.Total > 0)
            {
                PaymentLogic PaymentLogic = new PaymentLogic(ref Order);
                PaymentLogic.ProccessPayment(ref redirect);
            }
            else
            {
                redirect = "/CheckoutFinish?rf=" + Order.ReferenceCode;
            }

            return redirect;
        }
开发者ID:johncoffee,项目名称:eventblock,代码行数:62,代码来源:OrdersLogic.cs


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