/// <summary> /// Returns an enumerable collection of TopN orders of the given customer ordered by OrderDate descending. /// </summary> /// <param name="customerId">Customer's identifier.</param> /// <param name="count">Number of retrieved orders. Using 0 returns all records.</param> /// <returns>Collection of the customer's orders. See <see cref="OrderInfo"/> for detailed information.</returns> public IEnumerable <OrderInfo> GetByCustomerId(int customerId, int count = 0) { return(repositoryCacheHelper.CacheObjects(() => { return orderInfoProvider.GetBySite(SiteContext.CurrentSiteID) .WhereEquals("OrderCustomerID", customerId) .TopN(count) .OrderByDescending(orderInfo => orderInfo.OrderDate); }, $"{nameof(OrderRepository)}|{nameof(GetByCustomerId)}|{customerId}|{count}")); }
//EndDocSection:SetAsPaid //DocSection:MyOrders /// <summary> /// Displays a listing of the current user's orders. /// </summary> public ActionResult MyOrders() { // Gets the current customer CustomerInfo currentCustomer = shoppingService.GetCurrentCustomer(); // If the customer does not exist, returns error 404 if (currentCustomer == null) { return(HttpNotFound()); } // Retrieves from the database a collection of all orders made by the current customer var orders = orderInfoProvider.GetBySite(siteService.CurrentSite.SiteID) .WhereEquals("OrderCustomerID", currentCustomer.CustomerID) .OrderByDescending(orderInfo => orderInfo.OrderDate); // Creates a list of view models representing the collection of a customer's orders IList <OrderViewModel> model = orders .Select(order => new OrderViewModel(order, currencyInfoProvider)) .ToList(); return(View(model)); }