public OrderDetailModels GetDetailReceipt(string id, ref string msg) { OrderDetailModels model = new OrderDetailModels(); try { GetOrderDetailRequest paraBody = new GetOrderDetailRequest(); paraBody.ID = id; NSLog.Logger.Info("GetReceiptDetail_Request: ", paraBody); var result = (NSApiResponse)ApiResponse.Post <NSApiResponse>(Commons.ClientSiteYourCartGetOrderDetail, null, paraBody); NSLog.Logger.Info("GetReceiptDetail_Response: ", result); if (result != null) { dynamic data = result.Data; //====Receipt detail var receipt = data["OrderDetail"]; var lstObject = JsonConvert.SerializeObject(receipt); model = JsonConvert.DeserializeObject <OrderDetailModels>(lstObject); NSLog.Logger.Info("GetReceiptDetail_Response: ", model); return(model); } else { msg = result.Message; NSLog.Logger.Info("GetReceiptDetail_Response: ", result.Message); return(model); } } catch (Exception e) { NSLog.Logger.Error("GetReceiptDetail_Fail: ", e); return(model); } }
/// <summary> /// 订单详细,根据orderId /// </summary> /// <param name="orderId">订单ID</param> /// <returns></returns> public ActionResult OrderDetail(string orderId) { OrderDetailModels orderDetailModels = new OrderDetailModels(); Orders order = ordersService.GetModel(orderId); //如果没有该订单,则定向到订单查询表 if (order == null) { return(RedirectToAction("OrderSearch", "OrderManager")); } orderDetailModels.Order = order; orderDetailModels.Department = departmentService.GetModel(orderDetailModels.Order.DID); orderDetailModels.Enterprise = enterpriseService.GetModel(orderDetailModels.Department.EID); orderDetailModels.OrderDetailList = orderDetailService.GetList(orderId); if (orderDetailModels.Order == null || orderDetailModels.Department == null || orderDetailModels.Enterprise == null || orderDetailModels.OrderDetailList == null) { //出错了重定向,待写 return(RedirectToAction("OrderSearch", "OrderManager")); } return(View(orderDetailModels)); }
public ActionResult GetDetailReceipt(string id, string IsReseller) { try { OrderDetailModels model = new OrderDetailModels(); string msg = ""; model = _myProfileFactory.GetDetailReceipt(id, ref msg); model.CurrencySymbol = CurrencySymbol; model.CreatedDate = CommonHelper.ConvertToLocalTime(model.CreatedDate); model.PaidTime = CommonHelper.ConvertToLocalTime(model.PaidTime); model.TotalDiscount = Math.Abs(model.TotalDiscount); model.TotalPromotion = Math.Abs(model.TotalPromotion); model.sPaidByMethod = string.Join("<br/>", model.PaidByMethod.Select(x => x.Name)); //-------------- if (model.TaxInfo != null) { if (model.TaxInfo.TaxType == (byte)Commons.ETaxType.AddOn) { model.TaxInfo.TaxTypeName = Commons.ETaxType.AddOn.ToString(); } else if (model.TaxInfo.TaxType == (byte)Commons.ETaxType.Inclusive) { model.TaxInfo.TaxTypeName = Commons.ETaxType.Inclusive.ToString(); } else { model.TaxInfo.TaxTypeName = Commons.ETaxType.TaxExempt.ToString(); } } //-------------- model.ListItems = model.ListItems.OrderBy(x => x.ProductName).ToList(); model.ListItems.ForEach(x => { x.PeriodName = GetPeriodName(x.Period, x.PeriodType); x.ListComposite = x.ListComposite.OrderBy(o => o.ProductName).ToList(); x.ListItem = x.ListItem.OrderBy(o => o.ProductName).ToList(); x.ListItem.ForEach(z => { z.PeriodName = GetPeriodName(z.Period, z.PeriodType); }); }); return(PartialView(IsReseller.ToLower().Equals("true") ? "_ReceiptDetailReseller" : "_ReceiptDetail", model)); } catch (Exception ex) { NSLog.Logger.Error("Receipt_Get detail:", ex); return(new HttpStatusCodeResult(400, ex.Message)); } }
public OrderDetailModels AddItems(AddItemToOrderModels model, ref bool success, ref string msg) { OrderDetailModels item = new OrderDetailModels(); try { YourCartRequest paraBody = new YourCartRequest(); paraBody.CreatedUser = model.CusID; paraBody.CusID = model.CusID; paraBody.OrderID = model.OrderID; paraBody.ListItems = model.ListItems; paraBody.Note = model.Note; // paraBody.isFree = model.IsFree; paraBody.IsFree = model.IsFree; NSLog.Logger.Info("YourCart | AddItems Request: ", paraBody); var result = (NSApiResponse)ApiResponse.Post <NSApiResponse>(Commons.ClientSiteYourCartAddItems, null, paraBody); dynamic data = result.Data; success = result.Success; msg = result.Message; var lstDataRaw = data["OrderDetail"]; var lstObject = JsonConvert.SerializeObject(lstDataRaw); item = JsonConvert.DeserializeObject <OrderDetailModels>(lstObject); if (item == null) { item = new OrderDetailModels(); } NSLog.Logger.Info("YourCart | AddItems", item); return(item); } catch (Exception e) { NSLog.Logger.Error("YourCart | AddItems_Fail", e); return(item); } }
public OrderDetailModels GetOrderDetail(string OrderID, bool?isCheckvalid = null) { OrderDetailModels item = new OrderDetailModels(); try { YourCartRequest paraBody = new YourCartRequest(); paraBody.ID = OrderID; paraBody.isCheckvalid = isCheckvalid; NSLog.Logger.Info("YourCart | GetOrderDetail Request: ", paraBody); var result = (NSApiResponse)ApiResponse.Post <NSApiResponse>(Commons.ClientSiteYourCartGetOrderDetail, null, paraBody); if (result.Success && result.Message != null && result.Message.Equals("The receipt has been paid in full!")) { item.IsPad = true; } dynamic data = result.Data; var lstDataRaw = data["OrderDetail"]; var lstObject = JsonConvert.SerializeObject(lstDataRaw); item = JsonConvert.DeserializeObject <OrderDetailModels>(lstObject); if (item == null) { item = new OrderDetailModels(); } NSLog.Logger.Info("YourCart | GetOrderDetail", item); return(item); } catch (Exception e) { NSLog.Logger.Error("YourCart | GetOrderDetail_Fail", e); return(item); } }
public ActionResult AddToCartOfProductFreeTrial(string Id, string CateID) { OurProductFactory _factory = new OurProductFactory(); YourCartFactory _yourcartFactory = new YourCartFactory(); try { // get detail product by product id PackageDetailViewModels model = new PackageDetailViewModels(); // Set info for breadcrumb if item is product ViewBag.Title = ""; ViewBag.CategoryID = ""; ViewBag.CategoryName = ""; var ListPackages = _factory.GetListData(CurrentUser.UserId, null, 0, null, null, Id); if (ListPackages != null && ListPackages.Any()) { model.PackageDetail = ListPackages.FirstOrDefault(); model.PackageDetail.CusId = CurrentUser.UserId; model.PackageDetail.Quantity = 1; if (model.PackageDetail.IsUnlimitedAmountOfUnit) { model.PackageDetail.AmountOfUnit = -1; } if (model.PackageDetail.IsUnlimitedNumberOfAccount) { model.PackageDetail.NumberOfAccount = -1; } if (model.PackageDetail.IsUnlimitedIncludeStore) { model.PackageDetail.NumOfStore = -1; model.PackageDetail.IncludeStore = -1; } else { model.PackageDetail.NumOfStore = model.PackageDetail.IncludeStore; } if (model.PackageDetail.ImageURL == null || model.PackageDetail.ImageURL.Equals("")) { model.PackageDetail.ImageURL = _ImgDummyPackage; } if (model.PackageDetail.ListPrice != null && model.PackageDetail.ListPrice.Any()) { model.PackageDetail.Period = 30; model.PackageDetail.PeriodType = (int)Commons.EPeriodType.Day; } // If item is package if (model.PackageDetail.ProductType == (byte)Commons.EProductType.Package) { ViewBag.Title = "Package - " + model.PackageDetail.Name; //=======Get List Product Child if (model.PackageDetail.ListProductChild != null && model.PackageDetail.ListProductChild.Any()) { //update bug of Long by Trongntn 22-11-2017 model.PackageDetail.ListProductChild = model.PackageDetail.ListProductChild.Where(x => x.ProductType == (byte)Commons.EProductType.Product).ToList(); model.PackageDetail.ListProductChild.ForEach(xx => { // Get list cate product of package if (xx.ProductType == (byte)Commons.EProductType.Product) { model.ListApplyAdditionProduct.Add(new ProductApplyAdditionPackage { ProductName = xx.Name, ProductId = xx.ID, ProductCateId = xx.ListCategory.Select(s => s.CategoryID).FirstOrDefault().ToString() }); } }); } // If item is package from list recommend in Product list if (!string.IsNullOrEmpty(CateID)) { var listCate = ((List <CategoryDetailModels>)Session["ListItemCategory"]); if (listCate != null) { var CateDetail = listCate.Where(x => x.ID.Equals(CateID)).FirstOrDefault(); // Set info for breadcrumb if item is product ViewBag.CategoryID = CateDetail == null ? "" : CateDetail.ID; ViewBag.CategoryName = CateDetail == null ? "" : CateDetail.Name; } } } // If item is product else if (model.PackageDetail.ProductType == (byte)Commons.EProductType.Product) { ViewBag.Title = "Product - " + model.PackageDetail.Name; if (model.PackageDetail.ListCategory != null && model.PackageDetail.ListCategory.Any()) { var infoCategory = model.PackageDetail.ListCategory.FirstOrDefault(); model.ListApplyAdditionProduct.Add(new ProductApplyAdditionPackage { ProductName = model.PackageDetail.Name, ProductId = model.PackageDetail.ID, ProductCateId = infoCategory.CategoryID }); // Set info for breadcrumb if item is product ViewBag.CategoryID = infoCategory.CategoryID; ViewBag.CategoryName = infoCategory.CategoryName; } } //==========Get List Addition Type //List<SelectListItem> ListAdditionType = new List<SelectListItem>(); //ListAdditionType = GetListAdditionType(); //ViewBag.ListAdditionType = ListAdditionType; model.PackageDetail.CurrencySymbol = CurrencySymbol; model.PackageDetail.Price = 0; model.PackageDetail.DiscountValue = 0; if (model.PackageDetail.ListComposite != null && model.PackageDetail.ListComposite.Any()) { //Product model.PackageDetail.ListProductOnPackage = model.PackageDetail.ListComposite .Where(ww => ww.ProductType == (byte)Commons.EProductType.Product) .OrderBy(ww => ww.Sequence).ThenBy(ww => ww.ProductName).ToList(); model.PackageDetail.ListProductOnPackage.ForEach(x => { if (x.Quantity == -1) { x.ProductName = x.ProductName + " (For unlimited devices)"; } else { x.ProductName = x.ProductName + " (For " + x.Quantity + " device" + (x.Quantity > 1 ? "s" : "") + ")"; } }); //Addition model.PackageDetail.ListComposite = model.PackageDetail.ListComposite .Where(ww => ww.ProductType != (byte)Commons.EProductType.Product) .OrderBy(ww => ww.Sequence).ThenBy(ww => ww.ProductName).ToList(); } } // add to cart AddItemToOrderModels modelAddItems = new AddItemToOrderModels(); modelAddItems.CusID = CurrentUser.UserId; modelAddItems.OrderID = ORDERID; List <Item> ListItems = new List <Item>(); //=============== Item package = new Item(); package.ID = ""; package.ProductID = model.PackageDetail.ID; package.ProductName = model.PackageDetail.Name; package.ProductType = model.PackageDetail.ProductType; package.AdditionType = model.PackageDetail.AdditionType; package.ImageURL = model.PackageDetail.ImageURL; package.Period = model.PackageDetail.Period; package.PeriodType = model.PackageDetail.PeriodType; package.Quantity = model.PackageDetail.Quantity; package.Price = model.PackageDetail.Price; package.NumOfStore = model.PackageDetail.NumOfStore; package.NumOfAccount = model.PackageDetail.NumberOfAccount; package.AmountOfUnit = model.PackageDetail.AmountOfUnit; package.PromotionID = model.PackageDetail.PromotionID; package.PromotionName = model.PackageDetail.PromotionName; package.PromotionAmount = model.PackageDetail.PromotionAmount; package.IsApplyPromotion = model.PackageDetail.IsApplyPromotion; package.DiscountID = model.PackageDetail.DiscountID; package.DiscountName = model.PackageDetail.DiscountName; package.DiscountAmount = model.PackageDetail.DiscountAmount; package.DiscountValue = model.PackageDetail.DiscountValue; package.DiscountType = model.PackageDetail.DiscountType; package.Description = model.PackageDetail.Description; package.ItemGroup = model.PackageDetail.ItemGroup; package.IsDelete = model.PackageDetail.IsDelete; package.ListItem = new List <Item>(); foreach (var item in model.ListAdditionBuy.Where(w => w.IsDelete != true).ToList()) { package.ListItem.Add(new Item { ID = "", ProductID = item.ID, ParentAddition = item.ApplyProductId, ProductName = item.Name, ProductType = (byte)Commons.EProductType.Addition, AdditionType = item.AdditionType, Quantity = item.Quantity, Period = item.Period, PeriodType = item.PeriodType, Price = item.Price, IsDelete = item.IsDelete, AmountOfUnit = item.AmountOfUnit, ItemGroup = (byte)Commons.EItemGroup.Addition }); } package.ListStoreApply = new List <ApplyStore>(); package.ListAdditionApply = new List <AdditionApply>(); package.ListFunction = new List <ItemFunction>(); // Get all composite (products + additions) if (model.PackageDetail.ListComposite == null) { model.PackageDetail.ListComposite = new List <ProductCompositeModels>(); } if (model.PackageDetail.ListProductOnPackage != null && model.PackageDetail.ListProductOnPackage.Any()) { model.PackageDetail.ListComposite.AddRange(model.PackageDetail.ListProductOnPackage); } package.ListComposite = model.PackageDetail.ListComposite; //========= ListItems.Add(package); modelAddItems.ListItems = ListItems; modelAddItems.IsFree = true; //==================== string msg = ""; bool success = false; OrderDetailModels OrderDetail = _yourcartFactory.AddItems(modelAddItems, ref success, ref msg); if (success) { ORDERID = OrderDetail.ID; if (OrderDetail.ListItems != null && OrderDetail.ListItems.Count > 0) { OrderDetail.TotalQuantity = (int)OrderDetail.ListItems.Sum(x => x.Quantity); } return(Json(OrderDetail, JsonRequestBehavior.AllowGet)); } else { if (!string.IsNullOrEmpty(msg)) { if (msg.Equals("Payment is pending!") || msg.Equals("The receipt has been paid in full!")) { var Cookie = Request.Cookies["csc-order-v2"]; if (Cookie != null) { var Order = Cookie.Value; var strOrder = Server.UrlDecode(Order); var ListOrder = JsonConvert.DeserializeObject <List <CookieOrder> >(strOrder); if (ListOrder != null && ListOrder.Any()) { var temp = ListOrder.FirstOrDefault(x => x.OrderId.Equals(ORDERID)); if (temp != null) { ListOrder.Remove(temp); Cookie.Value = null; Response.Cookies.Add(Cookie); var strListOrder = JsonConvert.SerializeObject(ListOrder); Cookie.Value = strListOrder; Response.Cookies.Add(Cookie); } } } ORDERID = ""; return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, msg)); } } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, msg)); } } catch (Exception ex) { NSLog.Logger.Error("AddToCartOfProduct: ", ex); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, ex.Message)); } }
public static IEnumerable <Order> GetCustomerOrders(GetCustomerOrdersRequest request) { /* 20161222 80967 DV. Business rules have changed that will affect search. * 1. Remove filter using Other11 field. * 2. Instead of using ItemCode, use ItemID to identify PartnerStore and AffiliateStore items in an order, because BA and client believe that the ItemCode COULD change. * That is, if an order has ItemID 58 or 627 in the corresponding orderdetails table then simply filter out the entire order from the search results. * Note: For the tab called Partners & Affiliates, only include orders that contain ItemCode 58 or 627 specifically. * Filter out all orders using Order Type "Import" which is value 5. */ if (request.CustomerID == 0) { throw new ArgumentException("CustomerID is required."); } var context = Exigo.CreateODataContext <ExigoContext>(GlobalSettings.Exigo.Api.SandboxID); //Clear the OrderDetailModels if (OrderDetailModels != null) { OrderDetailModels = new List <ExigoService.OrderDetail>(); } var orders = new List <Order>(); // Setup the base orders query var ordersBaseQuery = context.Orders; if (request.IncludePayments) { ordersBaseQuery = ordersBaseQuery.Expand("Payments"); } var ordersQuery = ordersBaseQuery.Where(c => c.CustomerID == request.CustomerID); //20161222 80967 DV. Per item 3 of GetCustomerOrders summary, filter out all orders using Order Type "Import", which is value 5 ordersQuery.Where(c => c.OrderTypeID != 5); // Apply the request variables if (request.OrderID != null) { ordersQuery = ordersQuery.Where(c => c.OrderID == ((int)request.OrderID)); } if (request.OrderStatuses.Length > 0) { ordersQuery = ordersQuery.Where(request.OrderStatuses.ToList().ToOrExpression <Common.Api.ExigoOData.Order, int>("OrderStatusID")); } if (request.OrderTypes.Length > 0) { ordersQuery = ordersQuery.Where(request.OrderTypes.ToList().ToOrExpression <Common.Api.ExigoOData.Order, int>("OrderTypeID")); } if (request.StartDate != null) { ordersQuery = ordersQuery.Where(c => c.OrderDate >= (DateTime)request.StartDate); } if (request.EndDate != null) //20161212 80967 DV. Add ability for user to control both StartDate and EndDate { ordersQuery = ordersQuery.Where(c => c.OrderDate <= Convert.ToDateTime(request.EndDate).AddDays(1)); //20161216 #80967 DV. Like in commissions you need to add 1 to the end date in order to included all data up until 11:59:59:59 PM } //I.M. 11/29/2016 #80967 Add SQL query for grabbing all Order information // var orderSql = new List<ExigoService.Order>(); // try // { // using (var context = Exigo.Sql()) // { // orderSql = context.Query<ExigoService.Order>(@" // SELECT // o.OrderID, // o.OrderDate, // o.OrderStatusID, // o.OrderTypeID, // o.Total, // o.FirstName, // o.LastName, // o.Address1, // o.City, // o.State, // o.Zip, // o.Country, // o.Phone, // o.Email, // od.ItemDescription, // od.ItemCode // FROM // order o INNER JOIN orderdetails od // ON // o.OrderID = od.OrderID // WHERE // // ", new // { // OrderID = request.OrderID, // }).ToList(); // } // } // catch (Exception e) // { // Console.Write(e); // } // return orderSql; // } // Get the orders var odataOrders = ordersQuery .OrderByDescending(c => c.OrderDate) .Skip(request.Skip) //.Take(20) //.Take(request.Take) 20161226 80967 DV. .Select(c => c) .ToList(); //Begin flagged block. 20161230 DV. This block of code will be examined for performance analysis. // If we don't have any orders, stop here. if (odataOrders.Count == 0) { yield break; } // Collect our orders together foreach (var order in odataOrders) { var model = (Order)order; orders.Add(model); } // Get the order details if applicable if (request.IncludeOrderDetails) { // Get the order IDs var orderIDs = orders.Select(c => c.OrderID).Distinct().ToList(); // Get the order details (Results are saved via the ReadingEntity delegate to the private OrderDetailModels property. context.ReadingEntity += context_ReadingEntity; context.OrderDetails .Where(orderIDs.ToOrExpression <Common.Api.ExigoOData.OrderDetail, int>("OrderID")) .ToList(); // Get a unique list of item IDs in the orders var itemIDs = OrderDetailModels.Select(c => c.ItemID).Distinct().ToList(); // Get the extra data we need for each detail var apiItems = new List <Common.Api.ExigoOData.Item>(); if (itemIDs.Count > 0) { apiItems = context.Items .Where(itemIDs.ToOrExpression <Common.Api.ExigoOData.Item, int>("ItemID")) .Select(c => new Common.Api.ExigoOData.Item { ItemCode = c.ItemCode, SmallImageUrl = c.SmallImageUrl, IsVirtual = c.IsVirtual }) .ToList(); } // Format the data to our models foreach (var order in orders) { // Get the order details var details = OrderDetailModels.Where(c => c.OrderID == order.OrderID); foreach (var detail in details) { var apiItem = apiItems.Where(c => c.ItemCode == detail.ItemCode).FirstOrDefault(); if (apiItem != null) { detail.ImageUrl = apiItem.SmallImageUrl; detail.IsVirtual = apiItem.IsVirtual; } } order.Details = details; } } //End of flagged block. //20161222 80967 DV. Per item 2 of GetCustomerOrders summary, filter out any orderID's that has ItemID 58 or 627 in a corresponding orderdetail table foreach (var order in orders.ToList()) { var orderID = order.OrderID; var orderdetails = order.Details.Where(c => c.OrderID == order.OrderID); bool removecurrentorder = false; foreach (var item in orderdetails) { if (request.ShowOnlyPartnerAffiliateOrders) { if (!(item.ItemID == 58 || item.ItemID == 627)) { //orders.Remove(order); removecurrentorder = true; } } else if (request.ShowOnlyFeesAndServicesOrders) //20161229 80697 DV. Add filter to display orders with fees and services { if (!(item.ItemID == 45 || item.ItemID == 289 || item.ItemID == 290)) { //orders.Remove(order); removecurrentorder = true; } } else //Show all orders except orders that contain partner and affiliate items as well as fees and services { if (item.ItemID == 58 || item.ItemID == 627 || item.ItemID == 45 || item.ItemID == 289 || item.ItemID == 290) { orders.Remove(order); } } } if (removecurrentorder) { orders.Remove(order); //removecurrentorder = false; //reset bool } } // Format the data to our models foreach (var order in orders) { yield return(order); } }
public static IEnumerable <Order> GetCustomerOrders(GetCustomerOrdersRequest request) { var context = Exigo.OData(); // Clear the OrderDetailModels if (OrderDetailModels != null) { OrderDetailModels = new List <ExigoService.OrderDetail>(); } var orders = new List <Order>(); // Setup the base orders query var ordersBaseQuery = context.Orders; if (request.IncludePayments) { ordersBaseQuery = ordersBaseQuery.Expand("Payments"); } var ordersQuery = ordersBaseQuery.Where(c => c.CustomerID == request.CustomerID); // Apply the request variables if (request.OrderID != null) { ordersQuery = ordersQuery.Where(c => c.OrderID == ((int)request.OrderID)); } if (request.OrderStatuses.Length > 0) { ordersQuery = ordersQuery.Where(request.OrderStatuses.ToList().ToOrExpression <Common.Api.ExigoOData.Order, int>("OrderStatusID")); } if (request.OrderTypes.Length > 0) { ordersQuery = ordersQuery.Where(request.OrderTypes.ToList().ToOrExpression <Common.Api.ExigoOData.Order, int>("OrderTypeID")); } if (request.StartDate != null) { ordersQuery = ordersQuery.Where(c => c.OrderDate >= (DateTime)request.StartDate); } // Get the orders var odataOrders = ordersQuery .OrderByDescending(c => c.OrderDate) .Skip(request.Skip) .Take(request.Take) .Select(c => c) .ToList(); // If we don't have any orders, stop here. if (odataOrders.Count == 0) { yield break; } // Collect our orders together foreach (var order in odataOrders) { var model = (Order)order; orders.Add(model); } // Get the order details if applicable if (request.IncludeOrderDetails) { // Get the order IDs var orderIDs = orders.Select(c => c.OrderID).Distinct().ToList(); // Get the order details (Results are saved via the ReadingEntity delegate to the private OrderDetailModels property. context.ReadingEntity += context_ReadingEntity; context.OrderDetails .Where(orderIDs.ToOrExpression <Common.Api.ExigoOData.OrderDetail, int>("OrderID")) .ToList(); // Get a unique list of item IDs in the orders var itemIDs = OrderDetailModels.Select(c => c.ItemID).Distinct().ToList(); // Get the extra data we need for each detail var apiItems = new List <Common.Api.ExigoOData.Item>(); if (itemIDs.Count > 0) { apiItems = context.Items .Where(itemIDs.ToOrExpression <Common.Api.ExigoOData.Item, int>("ItemID")) .Select(c => new Common.Api.ExigoOData.Item { ItemCode = c.ItemCode, SmallImageUrl = c.SmallImageUrl, IsVirtual = c.IsVirtual }) .ToList(); } // Format the data to our models foreach (var order in orders) { // Get the order details var details = OrderDetailModels.Where(c => c.OrderID == order.OrderID); foreach (var detail in details) { var apiItem = apiItems.Where(c => c.ItemCode == detail.ItemCode).FirstOrDefault(); if (apiItem != null) { detail.ImageUrl = apiItem.SmallImageUrl; detail.IsVirtual = apiItem.IsVirtual; } } order.Details = details; } } // Format the data to our models foreach (var order in orders) { yield return(order); } }