public virtual IHttpActionResult GetOrders(int start, int maxCount) { Logger.LogGet("GetOrders", Request, new [] { start.ToString(), maxCount.ToString() }); if (maxCount < 1 || maxCount > 100) { maxCount = 10; } try { // http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-Commerce/9/Orders/Searching-for-orders/ var searchOptions = new OrderSearchOptions { CacheResults = false, StartingRecord = start, RecordsToRetrieve = maxCount, Namespace = "Mediachase.Commerce.Orders" }; var parameters = new OrderSearchParameters(); searchOptions.Classes.Add("PurchaseOrder"); parameters.SqlMetaWhereClause = "META.TrackingNumber LIKE '%PO%'"; parameters.SqlWhereClause = "OrderGroupId IN (SELECT OrdergroupId FROM Shipment WHERE NOT ShipmentTrackingNumber IS NULL)"; var orders = OrderContext.Current.FindPurchaseOrders(parameters, searchOptions); return(Ok(orders.Select(x => x.ConvertToPurchaseOrder()).ToArray())); } catch (Exception exception) { Logger.Error(exception.Message, exception); return(InternalServerError(exception)); } }
public IPurchaseOrder GetPurchaseOrderByKlarnaOrderId(string orderId) { OrderSearchOptions searchOptions = new OrderSearchOptions { CacheResults = false, StartingRecord = 0, RecordsToRetrieve = 1, Classes = new System.Collections.Specialized.StringCollection { "PurchaseOrder" }, Namespace = "Mediachase.Commerce.Orders" }; var parameters = new OrderSearchParameters(); parameters.SqlMetaWhereClause = $"META.{Constants.KlarnaOrderIdField} LIKE '{orderId}'"; var purchaseOrder = OrderContext.Current.FindPurchaseOrders(parameters, searchOptions)?.FirstOrDefault(); if (purchaseOrder != null) { return(_orderRepository.Load <IPurchaseOrder>(purchaseOrder.OrderGroupId)); } return(null); }
public static ICart GetCartByPredictableOrderId(string predictableOrderId) { if (!string.IsNullOrEmpty(predictableOrderId)) { try { var sqlMetaWhereClause = $@"META.{DinteroConstants.PredictableOrderIdMetaField} = '{predictableOrderId}'"; var orderSearchOptions = new OrderSearchOptions(); orderSearchOptions.Classes.Add("ShoppingCart"); orderSearchOptions.CacheResults = false; orderSearchOptions.RecordsToRetrieve = 1; var results = Cart.Search( new OrderSearch { SearchParameters = new OrderSearchParameters { SqlMetaWhereClause = sqlMetaWhereClause }, SearchOptions = orderSearchOptions }, out var number); if (number > 0) { return(results.FirstOrDefault()); } } catch (Exception ex) { return(null); } } return(null); }
/// <summary> /// Finds the purchase orders. /// </summary> /// <param name="parameters">The parameters.</param> /// <param name="options">The options.</param> /// <returns></returns> public PurchaseOrder[] FindPurchaseOrders(OrderSearchParameters parameters, OrderSearchOptions options) { int totalRecords = 0; PurchaseOrder[] pos = FindPurchaseOrders(parameters, options, out totalRecords); return(pos); }
/// <summary> /// Finds the carts. /// </summary> /// <param name="parameters">The parameters.</param> /// <param name="options">The options.</param> /// <returns></returns> public Cart[] FindCarts(OrderSearchParameters parameters, OrderSearchOptions options) { int totalRecords = 0; Cart[] carts = FindCarts(parameters, options, out totalRecords); return(carts); }
/// <summary> /// Binds the statistics. /// </summary> private void BindStatistics() { // calculate number of entries int recordsCount = 0; CatalogContext.Current.FindItemsDto(new CatalogSearchParameters(), new CatalogSearchOptions(), ref recordsCount); EntriesCount.InnerHtml = recordsCount > 0 ? recordsCount.ToString() : "0"; // calculate number of nodes recordsCount = 0; CatalogContext.Current.FindNodesDto(new CatalogSearchParameters(), new CatalogSearchOptions(), ref recordsCount); NodesCount.InnerHtml = recordsCount > 0 ? recordsCount.ToString() : "0"; // Calculate number of orders OrderSearchOptions orderoptions = new OrderSearchOptions(); orderoptions.Namespace = "Mediachase.Commerce.Orders"; orderoptions.Classes.Add("PurchaseOrder"); OrderContext.Current.FindPurchaseOrders(new OrderSearchParameters(), orderoptions, out recordsCount); OrdersCount.InnerHtml = recordsCount > 0 ? recordsCount.ToString() : "0"; // Calculate number of customers ProfileSearchOptions profileOptions = new ProfileSearchOptions(); profileOptions.Namespace = "Mediachase.Commerce.Profile"; profileOptions.Classes.Add("Account"); ProfileContext.Current.FindAccounts(new ProfileSearchParameters(), profileOptions, out recordsCount); CustomerCount.InnerHtml = recordsCount > 0 ? recordsCount.ToString() : "0"; // Calculate number of promotions recordsCount = PromotionManager.GetPromotionDto().Promotion.Count; PromotionCount.InnerHtml = recordsCount > 0 ? recordsCount.ToString() : "0"; }
public virtual IHttpActionResult GetCarts(int start, int maxCount) { Logger.LogGet("GetCarts", Request, new [] { start.ToString(), maxCount.ToString() }); if (maxCount < 1 || maxCount > 100) { maxCount = 10; } Cart[] carts; try { // http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-Commerce/9/Orders/Searching-for-orders/ OrderSearchOptions searchOptions = new OrderSearchOptions { CacheResults = false, StartingRecord = start, RecordsToRetrieve = maxCount, Namespace = "Mediachase.Commerce.Orders" }; OrderSearchParameters parameters = new OrderSearchParameters(); searchOptions.Classes.Add("LineItemEx"); parameters.SqlWhereClause = "OrderGroupId IN (Select ObjectId FROM OrderGroup_ShoppingCart)"; carts = OrderContext.Current.FindCarts(parameters, searchOptions); } catch (Exception exception) { Logger.Error(exception.Message, exception); return(InternalServerError(exception)); } return(Ok(carts)); }
public static PurchaseOrder GetOrderByTrackingNumber(string orderId) { var orderSearchParameters = new OrderSearchParameters { SqlMetaWhereClause = $@"META.TrackingNumber = '{orderId}'" }; var orderSearchOptions = new OrderSearchOptions { Namespace = "Mediachase.Commerce.Orders" }; orderSearchOptions.Classes.Add("PurchaseOrder"); orderSearchOptions.Classes.Add("Shipment"); orderSearchOptions.CacheResults = false; orderSearchOptions.RecordsToRetrieve = 1; var purchaseOrders = OrderContext.Current.FindPurchaseOrders(orderSearchParameters, orderSearchOptions).ToList(); if (purchaseOrders.Count > 0) { // order was found return(purchaseOrders.FirstOrDefault()); } else if (int.TryParse(orderId, out var orderIdNumeric)) { // order was not found; try to get by id return(OrderContext.Current.GetPurchaseOrderById(orderIdNumeric)); } return(null); }
public IPurchaseOrder GetByPayeeReference(string payeeReference) { OrderSearchOptions searchOptions = new OrderSearchOptions { CacheResults = false, StartingRecord = 0, RecordsToRetrieve = 1, Classes = new System.Collections.Specialized.StringCollection { "PurchaseOrder" }, Namespace = "Mediachase.Commerce.Orders" }; var parameters = new OrderSearchParameters { SqlMetaWhereClause = $"META.{Constants.SwedbankPayPayeeReference} = '{payeeReference}'" }; var purchaseOrder = OrderContext.Current.Search <PurchaseOrder>(parameters, searchOptions)?.FirstOrDefault(); if (purchaseOrder != null) { return(_orderRepository.Load <IPurchaseOrder>(purchaseOrder.OrderGroupId)); } return(null); }
public IQueryable <Order> SearchOrder(OrderSearchOptions options) { if (options == null) { //throw new ArgumentNullException("Null Options"); return(null); } var query = dbContext .Set <Order>() .AsQueryable(); if (options.OrderId != null) { query = query.Where(o => o.OrderId == options.OrderId); } if (options.CustomerId != null) { query = query.Where(o => o.CustomerId == options.CustomerId.Value); } query = query.Take(500); return(query); }
/// <summary> /// Finds the payment plans. /// </summary> /// <param name="parameters">The parameters.</param> /// <param name="options">The options.</param> /// <returns></returns> public PaymentPlan[] FindPaymentPlans(OrderSearchParameters parameters, OrderSearchOptions options) { int totalRecords = 0; PaymentPlan[] plans = FindPaymentPlans(parameters, options, out totalRecords); return(plans); }
/// <summary> /// Finds the carts. /// </summary> /// <param name="parameters">The parameters.</param> /// <param name="options">The options.</param> /// <param name="totalRecords">The total records.</param> /// <returns></returns> public Cart[] FindCarts(OrderSearchParameters parameters, OrderSearchOptions options, out int totalRecords) { OrderSearch search = new OrderSearch(this); search.SearchOptions = options; search.SearchParameters = parameters; MetaStorageCollectionBase <Cart> orders = Cart.Search(search, out totalRecords); return(orders.ToArray()); }
/// <summary> /// Finds the payment plans. /// </summary> /// <param name="parameters">The parameters.</param> /// <param name="options">The options.</param> /// <param name="totalRecords">The total records.</param> /// <returns></returns> public PaymentPlan[] FindPaymentPlans(OrderSearchParameters parameters, OrderSearchOptions options, out int totalRecords) { OrderSearch search = new OrderSearch(this); search.SearchOptions = options; search.SearchParameters = parameters; MetaStorageCollectionBase <PaymentPlan> orders = PaymentPlan.Search(search, out totalRecords); return(orders.ToArray()); }
private PurchaseOrder GetMockOrder() { var parameters = new OrderSearchParameters { SqlMetaWhereClause = "[ObjectId] = (SELECT TOP 1 OrderGroupId FROM OrderGroup order by Total desc)" }; var options = new OrderSearchOptions { RecordsToRetrieve = 1, Classes = new StringCollection { "PurchaseOrder" } }; return OrderContext.Current.FindPurchaseOrders(parameters, options).FirstOrDefault(); }
private PurchaseOrder GetMockOrder() { var parameters = new OrderSearchParameters { SqlMetaWhereClause = "[ObjectId] = (SELECT TOP 1 OrderGroupId FROM OrderGroup order by Total desc)" }; var options = new OrderSearchOptions { RecordsToRetrieve = 1, Classes = new StringCollection { "PurchaseOrder" } }; return(OrderContext.Current.FindPurchaseOrders(parameters, options).FirstOrDefault()); }
private OrderSearchOptions GetOrderSearchOptions(int page = 1) { if (page < 1) { throw new ArgumentException("page cannot be less than one", nameof(page)); } var options = new OrderSearchOptions { CacheResults = false, StartingRecord = (page - 1) * _batchSize, RecordsToRetrieve = _batchSize }; options.Classes.Add("PurchaseOrder"); return(options); }
private IPurchaseOrder GetPurchaseOrder(string orderId, bool cacheResults) { var searchOptions = new OrderSearchOptions { CacheResults = cacheResults, StartingRecord = 0, RecordsToRetrieve = 1, Classes = new StringCollection { "PurchaseOrder" }, Namespace = "Mediachase.Commerce.Orders" }; var parameters = new OrderSearchParameters { SqlMetaWhereClause = $"META.{VippsConstants.VippsOrderIdField} = '{orderId}'" }; return(OrderContext.Current.Search <PurchaseOrder>(parameters, searchOptions)?.FirstOrDefault()); }
/// <summary> /// Processes the application. /// </summary> /// <param name="applicationName">Name of the application.</param> void ProcessApplication(string applicationName) { _Log.Info(String.Format("Processing Payment Plans for \"{0}\" application.", applicationName)); try { int totalRecords = -1; int startRowIndex = 0; OrderSearchOptions options = new OrderSearchOptions(); OrderSearchParameters parameters = new OrderSearchParameters(); options.Namespace = "Mediachase.Commerce.Orders"; options.Classes.Add("PaymentPlan"); options.RecordsToRetrieve = 50; parameters.OrderByClause = String.Format("OrderGroupId DESC"); do { options.StartingRecord = startRowIndex; PaymentPlan[] orders = OrderContext.Current.FindPaymentPlans(parameters, options, out totalRecords); if (orders != null) { foreach (PaymentPlan plan in orders) { // Charge the plan ProcessPlan(plan); } } startRowIndex += options.RecordsToRetrieve; }while (totalRecords > 0); _Log.Info("Successfully completed."); } catch (Exception ex) { _Log.Error("Processing Payment Plans failed.", ex); } }
public static List<PurchaseOrder> GetOrders(string sqlWhereClause, string sqlMetaWhereClause, int recordCount = int.MaxValue) { var orderSearchParameters = new OrderSearchParameters(); if (!string.IsNullOrEmpty(sqlWhereClause)) { orderSearchParameters.SqlWhereClause = sqlWhereClause; } if (!string.IsNullOrEmpty(sqlMetaWhereClause)) { orderSearchParameters.SqlMetaWhereClause = sqlMetaWhereClause; } var orderSearchOptions = new OrderSearchOptions(); orderSearchOptions.Namespace = "Mediachase.Commerce.Orders"; orderSearchOptions.Classes.Add("PurchaseOrder"); orderSearchOptions.Classes.Add("Shipment"); orderSearchOptions.CacheResults = false; orderSearchOptions.RecordsToRetrieve = recordCount; return OrderContext.Current.FindPurchaseOrders(orderSearchParameters, orderSearchOptions).ToList(); }
public IPurchaseOrder GetByTrackingNumber(string trackingNumber) { OrderSearchOptions searchOptions = new OrderSearchOptions(); searchOptions.CacheResults = false; searchOptions.StartingRecord = 0; searchOptions.RecordsToRetrieve = 1; searchOptions.Classes = new System.Collections.Specialized.StringCollection { "PurchaseOrder" }; searchOptions.Namespace = "Mediachase.Commerce.Orders"; var parameters = new OrderSearchParameters(); parameters.SqlMetaWhereClause = $"META.TrackingNumber = '{trackingNumber}'"; var purchaseOrder = OrderContext.Current.FindPurchaseOrders(parameters, searchOptions)?.FirstOrDefault(); if (purchaseOrder != null) { return(_orderRepository.Load <IPurchaseOrder>(purchaseOrder.OrderGroupId)); } return(null); }
public static List <PurchaseOrder> GetOrders(string sqlWhereClause, string sqlMetaWhereClause, int recordCount = int.MaxValue) { var orderSearchParameters = new OrderSearchParameters(); if (!string.IsNullOrEmpty(sqlWhereClause)) { orderSearchParameters.SqlWhereClause = sqlWhereClause; } if (!string.IsNullOrEmpty(sqlMetaWhereClause)) { orderSearchParameters.SqlMetaWhereClause = sqlMetaWhereClause; } var orderSearchOptions = new OrderSearchOptions(); orderSearchOptions.Namespace = "Mediachase.Commerce.Orders"; orderSearchOptions.Classes.Add("PurchaseOrder"); orderSearchOptions.Classes.Add("Shipment"); orderSearchOptions.CacheResults = false; orderSearchOptions.RecordsToRetrieve = recordCount; return(OrderContext.Current.FindPurchaseOrders(orderSearchParameters, orderSearchOptions).ToList()); }
/// <summary> /// Returns a Cart based on the PayEx orderReference /// </summary> /// <param name="orderRef">PayEx orderReference</param> /// <param name="orderNumber">Order number</param> /// <returns>Cart</returns> private Cart GetCartByOrderRef(string orderRef, out string orderNumber) { var parameters = new OrderSearchParameters { SqlMetaWhereClause = "", SqlWhereClause = "OrderGroupId IN (SELECT OrderGroupId FROM OrderFormPayment WHERE TransactionType LIKE 'Authorization' AND Status LIKE 'Pending')" }; var options = new OrderSearchOptions { Classes = new StringCollection { "ShoppingCart" }, CacheResults = false, RecordsToRetrieve = 10000, Namespace = "Mediachase.Commerce.Orders" }; var carts = OrderContext.Current.FindCarts(parameters, options); foreach (var cart in carts) { var payment = GetPayExPayment(cart); if (payment == null || string.IsNullOrWhiteSpace(payment.PayExOrderRef)) { continue; } if (payment.PayExOrderRef.Equals(orderRef)) { orderNumber = payment.OrderNumber; return(cart); } } orderNumber = string.Empty; return(null); }
/// <summary> /// Inits the data source. /// </summary> /// <param name="startRowIndex">Start index of the row.</param> /// <param name="recordsCount">The records count.</param> /// <param name="returnTotalCount">if set to <c>true</c> [return total count].</param> /// <param name="orderByClause">The order by clause.</param> private void InitDataSource(int startRowIndex, int recordsCount, bool returnTotalCount, string orderByClause) { DateTime startDate = DateTime.UtcNow; DateTime endDate = DateTime.UtcNow; DateTime nowDate = DateTime.UtcNow; bool applyDateFilter = false; if (FilterType == "thisweek") { startDate = nowDate.AddDays(-nowDate.DayOfWeek.GetHashCode()); endDate = nowDate; applyDateFilter = true; } else if (FilterType == "thismonth") { startDate = nowDate.AddDays(-nowDate.Day); endDate = nowDate; applyDateFilter = true; } else if (FilterType == "today") { startDate = new DateTime(nowDate.Year, nowDate.Month, nowDate.Day); endDate = nowDate; applyDateFilter = true; } else { applyDateFilter = false; } if (applyDateFilter) { OrderListDataSource.Parameters.SqlMetaWhereClause = String.Format("META.Modified between '{0}' and '{1}'", startDate.ToString("s"), endDate.ToString("s")); } if (!String.IsNullOrEmpty(Status)) { OrderListDataSource.Parameters.SqlWhereClause = String.Format("Status = '{0}'", Status); } if (String.IsNullOrEmpty(orderByClause)) { orderByClause = String.Format("OrderGroupId DESC"); } OrderSearchOptions options = new OrderSearchOptions(); OrderListDataSource.Options.Namespace = "Mediachase.Commerce.Orders"; OrderListDataSource.Options.Classes.Add(ClassType); if (ClassType == "ShoppingCart") { MyListView.DataMember = OrderDataSource.OrderDataSourceView.CartsViewName; } else if (ClassType == "PaymentPlan") { MyListView.DataMember = OrderDataSource.OrderDataSourceView.PaymentPlansViewName; } else { MyListView.DataMember = OrderDataSource.OrderDataSourceView.PurchaseOrdersViewName; } OrderListDataSource.Options.RecordsToRetrieve = recordsCount; OrderListDataSource.Options.StartingRecord = startRowIndex; OrderListDataSource.Parameters.OrderByClause = orderByClause; }
/// <summary> /// Inits the data source. /// </summary> /// <param name="startRowIndex">Start index of the row.</param> /// <param name="recordsCount">The records count.</param> /// <param name="returnTotalCount">if set to <c>true</c> [return total count].</param> /// <param name="orderByClause">The order by clause.</param> private void InitDataSource(int startRowIndex, int recordsCount, bool returnTotalCount, string orderByClause) { MyListView.DataSourceID = OrderListDataSource.ID; DateTime nowDate = DateTime.UtcNow; DateTime startDate = DateTime.UtcNow; DateTime endDate = DateTime.UtcNow; bool applyDateFilter = false; String filterType = DataRange.SelectedValue; if (String.Compare(filterType, "thisweek", true) == 0) { startDate = nowDate.AddDays(-nowDate.DayOfWeek.GetHashCode()); endDate = nowDate; applyDateFilter = true; } else if (String.Compare(filterType, "thismonth", true) == 0) { startDate = nowDate.AddDays(-nowDate.Day); endDate = nowDate; applyDateFilter = true; } else if (String.Compare(filterType, "today", true) == 0) { startDate = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day); endDate = nowDate; applyDateFilter = true; } else { applyDateFilter = false; } if (applyDateFilter) { OrderListDataSource.Parameters.SqlMetaWhereClause = String.Format("META.Modified between '{0}' and '{1}'", startDate.ToString("s"), endDate.ToString("s")); } StringBuilder sqlWhereClause = new StringBuilder("(1=1)"); int orderId = 0; if (int.TryParse(OrderNumber.Text, out orderId) && orderId > 0) { sqlWhereClause.AppendFormat(" AND (OrderGroupId = {0})", orderId); } string status = OrderStatus.SelectedValue; if (!String.IsNullOrEmpty(status)) { sqlWhereClause.AppendFormat(" AND (Status = '{0}')", status); } if (String.IsNullOrEmpty(orderByClause)) { orderByClause = String.Format("OrderGroupId DESC"); } //search by CustomerName if (!String.IsNullOrEmpty(CustomerKeyword.Text)) { StringBuilder customerWhereClause = new StringBuilder(); foreach (string keyword in CustomerKeyword.Text.Split(' ')) { if (customerWhereClause.Length > 0) { customerWhereClause.Append(" OR "); } customerWhereClause.AppendFormat(" CustomerName LIKE '%{0}%'", keyword.Replace("'", "''")); } sqlWhereClause.AppendFormat(" AND ({0})", customerWhereClause); } OrderListDataSource.Parameters.SqlWhereClause = sqlWhereClause.ToString(); OrderSearchOptions options = new OrderSearchOptions(); OrderListDataSource.Options.Namespace = "Mediachase.Commerce.Orders"; string classType = ClassType.SelectedValue; OrderListDataSource.Options.Classes.Add(classType); if (String.Compare(classType, _ShoppingCartClass, true) == 0) { MyListView.DataMember = OrderDataSource.OrderDataSourceView.CartsViewName; } else if (String.Compare(classType, _PaymentPlanClass, true) == 0) { MyListView.DataMember = OrderDataSource.OrderDataSourceView.PaymentPlansViewName; } else { MyListView.DataMember = OrderDataSource.OrderDataSourceView.PurchaseOrdersViewName; } OrderListDataSource.Options.RecordsToRetrieve = recordsCount; OrderListDataSource.Options.StartingRecord = startRowIndex; OrderListDataSource.Parameters.OrderByClause = orderByClause; }
private void InitDataSource(int startRowIndex, int recordsCount, bool returnTotalCount, string orderByClause) { DateTime now = DateTime.Now; DateTime dateTime1 = now; DateTime dateTime2 = now; bool flag; bool marketFlag = false; string market = string.Empty; if (this.FilterType == "thisweek") { dateTime1 = ManagementHelper.GetStartOfWeek(now.Date); dateTime2 = now; flag = true; } else if (this.FilterType == "thismonth") { dateTime1 = new DateTime(now.Year, now.Month, 1); dateTime2 = now; flag = true; } else if (this.FilterType == "today") { dateTime1 = now.Date; dateTime2 = now; flag = true; } else { if (this.FilterType == "sunstore") { market = this.FilterType; marketFlag = true; } else if (this.FilterType == "amavita") { market = this.FilterType; marketFlag = true; } else if (this.FilterType == "coop") { market = this.FilterType; marketFlag = true; } flag = false; } if (flag) { this.OrderListDataSource.Parameters.SqlMetaWhereClause = string.Format("META.Modified between '{0}' and '{1}'", (object)dateTime1.ToUniversalTime().ToString("s"), (object)dateTime2.ToUniversalTime().ToString("s")); } if (!string.IsNullOrEmpty(this.Status)) { this.OrderListDataSource.Parameters.SqlWhereClause = string.Format("Status = '{0}'", (object)ManagementHelper.MakeSafeSearchFilter(this.Status)); } if (marketFlag && !string.IsNullOrEmpty(market)) { this.OrderListDataSource.Parameters.JoinSourceTable = "[dbo].[OrderForm]"; this.OrderListDataSource.Parameters.JoinSourceTableKey = "[OrderGroupId]"; this.OrderListDataSource.Parameters.JoinSourceTable = "[dbo].[OrderGroup]"; this.OrderListDataSource.Parameters.JoinSourceTableKey = "[OrderGroupId]"; if (!string.IsNullOrEmpty(this.OrderListDataSource.Parameters.SqlWhereClause)) { this.OrderListDataSource.Parameters.SqlWhereClause += string.Format("AND OrderGroup.MarketId = '{0}'", market); } else { this.OrderListDataSource.Parameters.SqlWhereClause = string.Format("OrderGroup.MarketId = '{0}'", market); } } if (string.IsNullOrEmpty(orderByClause)) { orderByClause = string.Format("OrderGroupId DESC"); } OrderSearchOptions orderSearchOptions = new OrderSearchOptions(); this.OrderListDataSource.Options.Namespace = "Mediachase.Commerce.Orders"; this.OrderListDataSource.Options.Classes.Add(this.ClassType); this.MyListView.DataMember = !(this.ClassType == "ShoppingCart") ? (!(this.ClassType == "PaymentPlan") ? OrderDataSource.OrderDataSourceView.PurchaseOrdersViewName : OrderDataSource.OrderDataSourceView.PaymentPlansViewName) : OrderDataSource.OrderDataSourceView.CartsViewName; this.OrderListDataSource.Options.RecordsToRetrieve = recordsCount; this.OrderListDataSource.Options.StartingRecord = startRowIndex; this.OrderListDataSource.Parameters.OrderByClause = orderByClause; }
public virtual IHttpActionResult SearchOrders(int start, int maxCount, [FromUri(Name = "")] SearchOrdersRequest request) { Logger.LogGet("GetOrders", Request, new[] { start.ToString(), maxCount.ToString(), $"{request?.OrderShipmentStatus}", $"{request?.ShippingMethodId}" }); if (maxCount < 1 || maxCount > 100) { maxCount = 10; } try { var searchOptions = new OrderSearchOptions { CacheResults = false, StartingRecord = start, RecordsToRetrieve = maxCount, Namespace = "Mediachase.Commerce.Orders" }; var parameters = new OrderSearchParameters(); searchOptions.Classes.Add("PurchaseOrder"); parameters.SqlMetaWhereClause = string.Empty; if (request?.ModifiedFrom.HasValue ?? false) { parameters.SqlMetaWhereClause = $"META.Modified >= '{request.ModifiedFrom.Value:s}'"; } if (request?.OrderShipmentStatus != null && request.ShippingMethodId != null && request.ShippingMethodId != Guid.Empty) { parameters.SqlWhereClause = $"[OrderGroupId] IN (SELECT [OrderGroupId] FROM [Shipment] WHERE [Status] = '{request.OrderShipmentStatus}' AND [ShippingMethodId] = '{request.ShippingMethodId}')"; } else if (request?.OrderShipmentStatus != null) { parameters.SqlWhereClause = $"[OrderGroupId] IN (SELECT [OrderGroupId] FROM [Shipment] WHERE [Status] = '{request.OrderShipmentStatus}')"; } else if (request?.ShippingMethodId != null && request.ShippingMethodId != Guid.Empty) { parameters.SqlWhereClause = $"[OrderGroupId] IN (SELECT [OrderGroupId] FROM [Shipment] WHERE [ShippingMethodId] = '{request.ShippingMethodId}')"; } if (request != null && request.Status?.Length > 0) { if (!string.IsNullOrEmpty(parameters.SqlWhereClause)) { parameters.SqlWhereClause += " AND "; } var statusesParam = string.Join(",", request.Status.Select(x => $"'{x}'")); parameters.SqlWhereClause += $"Status IN ({statusesParam})"; } var orders = OrderContext.Current.FindPurchaseOrders(parameters, searchOptions); return(Ok(orders.Select(x => x.ConvertToPurchaseOrder()).ToArray())); } catch (Exception exception) { Logger.Error(exception.Message, exception); return(InternalServerError(exception)); } }