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; }
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; }