public async Task <ActionResult <CustomerOrderSearchResult> > SearchCustomerOrders([FromBody] OrderSearchCriteria criteria) { if (criteria == null) { criteria = new OrderSearchCriteria(); } var authorizationResult = await _authorizationService.AuthorizeAsync(User, null, SecurityConstants.Permissions.CanViewOrders); if (!authorizationResult.Succeeded) { //Does not allow to see a other customer orders criteria.CustomerId = WorkContext.CurrentUser.Id; } var result = await _orderApi.SearchCustomerOrderAsync(criteria.ToSearchCriteriaDto()); var orders = result.Results.Select(x => x.ToCustomerOrder(WorkContext.AllCurrencies, WorkContext.CurrentLanguage)).ToArray(); await _orderService.LoadProductsAsync(orders); _orderService.SelectConfiguredProductParts(orders); return(new CustomerOrderSearchResult { Results = orders, TotalCount = result.TotalCount ?? default(int), }); }
protected virtual async Task <IPagedList <CustomerOrder> > InnerSearchOrdersAsync(OrderSearchCriteria criteria, WorkContext workContext) { if (criteria == null) { throw new ArgumentNullException(nameof(criteria)); } var result = await _orderApi.SearchCustomerOrderAsync(criteria.ToSearchCriteriaDto()); return(new StaticPagedList <CustomerOrder>(result.Results.Select(x => x.ToCustomerOrder(workContext.AllCurrencies, workContext.CurrentLanguage)), criteria.PageNumber, criteria.PageSize, result.TotalCount.Value)); }
private async Task <User> PrepareUserResultAsync(MemoryCacheEntryOptions options, AutoRestClients.PlatformModuleApi.Models.ApplicationUser userDto) { if (userDto != null) { var user = userDto.ToUser(); var orderSearchResult = await _orderModule.SearchCustomerOrderAsync(new CustomerOrderSearchCriteria() { CustomerId = user.Id, Take = 0, Skip = 0, }); user.IsFirstTimeBuyer = orderSearchResult.TotalCount == 0; options.AddExpirationToken(new PollingApiUserChangeToken(_platformSecurityApi, _options.ChangesPollingInterval)); options.AddExpirationToken(SecurityCacheRegion.CreateChangeToken(userDto.Id)); return(user); } return(null); }