本文整理汇总了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;
}
示例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;
}