public async Task <PagedResult <ScheduleDetailDto> > ListWithItems(bool completed = false, string alias = "", int page = 1, int size = 30) { UserDto user; if (string.IsNullOrEmpty(alias)) { user = UCenterUser; } else { user = await _uCenterService.GetUser(x => x.Alias, alias); } if (user == null) { return(PagedResult <ScheduleDetailDto> .Empty()); } var hasPrivate = false; if (IsAuthenticated) { hasPrivate = user.UserId == UCenterUser.UserId; } return(await _scheduleService.ListWithItemsAsync(user.UserId, hasPrivate, completed, page, size)); }
/// <summary> /// Load sales transactions using the search criteria. /// </summary> /// <param name="request">Request containing the criteria used to retrieve sales transactions.</param> /// <returns>Instance of <see cref="GetSalesTransactionsServiceResponse"/>.</returns> private static GetSalesTransactionsServiceResponse GetSalesTransactions(GetSalesTransactionsServiceRequest request) { ThrowIf.Null(request, "request"); IDictionary <string, IList <SalesLine> > linesWithUnavailableProducts; // Try to load the transaction GetCartsDataRequest getSalesTransactionDatasetDataRequest = new GetCartsDataRequest(request.SearchCriteria, request.QueryResultSettings); PagedResult <SalesTransaction> salesTransactions = request.RequestContext.Execute <EntityDataServiceResponse <SalesTransaction> >(getSalesTransactionDatasetDataRequest).PagedEntityCollection; if (salesTransactions != null) { // Only search remote in case of customer order. SearchLocation productSearchLocation = salesTransactions.Results.Any(t => t.CartType == CartType.CustomerOrder) ? SearchLocation.All : SearchLocation.Local; linesWithUnavailableProducts = PopulateProductOnSalesLines(request.RequestContext, salesTransactions.Results, request.MustRemoveUnavailableProductLines, productSearchLocation); } else { salesTransactions = PagedResult <SalesTransaction> .Empty(); linesWithUnavailableProducts = new Dictionary <string, IList <SalesLine> >(); } GetSalesTransactionsServiceResponse response = new GetSalesTransactionsServiceResponse(salesTransactions, linesWithUnavailableProducts); return(response); }
public async Task <PagedResult> GetTransfersAsync(TransfersRequest request) { var httpResponseMessage = await this.m_HttpClient.PostAsync("/v1/history/get_transfers", CreateStringContent(JsonConvert.SerializeObject((object)new { contract = "eosio.token", action = "transferex", skip = request.Skip, limit = request.Limit, Owner = request.Owner }))); if (httpResponseMessage.IsSuccessStatusCode) { var contentStr = await httpResponseMessage.Content.ReadAsStringAsync(); var response = JsonConvert.DeserializeObject <TransferResponse>(contentStr); var transfers = response.Actions.Select(a => new Transfer { Id = a.TrxId, blockNum = a.BlockNum, Time = a.BlockTime, From = a.Data.From, To = a.Data.To, Quantity = a.Data.Quantity, Memo = a.Data.Memo, Confirmations = (response.LastIrreversibleBlock > a.BlockNum) ? (response.LastIrreversibleBlock - a.BlockNum) : 0 }).ToList(); var result = PagedResult.Create(transfers, response.Total); return(result); } return(PagedResult.Empty <Transfer>()); }
public async Task <PagedResult <FeedDto> > GetFeeds(string alias, int pageIndex, int pageSize, bool withPrivate = false) { var user = await _uCenterSvc.GetUser(x => x.Alias, alias); if (user == null) { return(PagedResult <FeedDto> .Empty()); } return(await _feedsApi.GetMyFeeds(AppConst.AppId, user.UserId, pageIndex, pageSize, withPrivate)); }
/// <summary> /// For all the product ids given in the request, calculate the price based on the info /// in the product and update the price table in database. /// </summary> /// <param name="request">The request.</param> /// <returns> /// Response containing updated product prices for each given id. /// </returns> internal GetProductPricesServiceResponse CalculatePricesForProducts(GetProductPricesServiceRequest request) { // return empty fast if no products are given if (!request.Products.Any()) { return(new GetProductPricesServiceResponse(PagedResult <ProductPrice> .Empty())); } IList <ProductPrice> prices = this.CalculateProductPrices(request.RequestContext, request.Products); // add materialized updated prices to reponse return(new GetProductPricesServiceResponse(prices.AsPagedResult())); }
/// <summary> /// Gets the commerce lists specified by the request. /// </summary> /// <param name="request">The request.</param> /// <returns><see cref="GetCommerceListResponse"/>Object containing the commerce lists.</returns> protected override GetCommerceListResponse Process(GetCommerceListRequest request) { ThrowIf.Null(request, "request"); ThrowIf.Null(request.RequestContext, "request.RequestContext"); // Async customers do not have commerce lists. if (this.IsAsyncCustomer(request.RequestContext, request.CustomerAccountNumber)) { return(new GetCommerceListResponse(PagedResult <CommerceList> .Empty())); } // Employee can read any commerce lists. // Customer can only read lists owned by him or shared to him. // Anonymous is not allowed to read commerce lists. ICommercePrincipal principal = request.RequestContext.GetPrincipal(); if (principal.IsAnonymous) { throw new NotSupportedException("Anonymous is not allowed to read commerce lists."); } else if (principal.IsCustomer) { request.CustomerAccountNumber = principal.UserId; } // Form a request and get the response GetCommerceListRealtimeRequest serviceRequest = new GetCommerceListRealtimeRequest { Id = request.Id, CustomerAccountNumber = request.CustomerAccountNumber, FavoriteFilter = request.FavoriteFilter, PublicFilter = request.PublicFilter, QueryResultSettings = request.QueryResultSettings }; GetCommerceListRealtimeResponse serviceResponse = this.Context.Execute <GetCommerceListRealtimeResponse>(serviceRequest); return(new GetCommerceListResponse(serviceResponse.Clists)); }
public async Task <ActionResult <PagedResult <FeedDto> > > GetFeeds(string alias, int page = 1, int size = 10, bool guest = false, bool myself = false) { if (guest) { return(await _feedsAppSvc.GetFeeds(alias, page, size)); } else { if (!IsAuthenticated) { return(Unauthorized()); } if (UCenterUser.Alias == alias) { if (myself) { return(await _feedsAppSvc.GetFeeds(alias, page, size, true)); } return(await _feedsAppSvc.GetConcernFeeds(page, size, UCenterUser.UserId)); } return(PagedResult <FeedDto> .Empty()); } }
/// <summary> /// Gets the products requested based on their record identifiers. /// </summary> /// <param name="request">The request to retrieve <see cref="SimpleProduct"/> objects.</param> /// <returns>The response containing the collection of products requested.</returns> private static GetProductsServiceResponse GetProducts(GetProductsServiceRequest request) { ThrowIf.Null(request, "request"); ThrowIf.Null(request.QueryResultSettings, "request.QueryResultSettings"); if (request.ProductIds.IsNullOrEmpty() && request.ItemAndInventDimIdCombinations.IsNullOrEmpty()) { return(new GetProductsServiceResponse(PagedResult <SimpleProduct> .Empty())); } if (request.ProductIds != null && request.ProductIds.Any() && request.ItemAndInventDimIdCombinations != null && request.ItemAndInventDimIdCombinations.Any()) { throw new ArgumentOutOfRangeException("request", "The GetProductsServiceRequest cannot be processed when both product ids and item-inventdim ids are specified. Please specify only one."); } if (request.SearchLocation == SearchLocation.Remote) { throw new NotSupportedException(string.Format("SearchLocation {0} is not supported.", request.SearchLocation)); } bool?downloadedProductsFilter = null; switch (request.SearchLocation) { case SearchLocation.Local: downloadedProductsFilter = false; break; case SearchLocation.Remote: downloadedProductsFilter = true; break; case SearchLocation.All: downloadedProductsFilter = null; break; default: throw new InvalidOperationException(string.Format("SearchLocation '{0}' is not supported.", request.SearchLocation)); } if (request.QueryResultSettings.Sorting.IsSpecified) { // We have to enforce paging by "IsRemote" flag and retrieve local products first. Otherwise result set can be shifted once remote product is inserted to local database. throw new DataValidationException(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_InvalidRequest, "When retrieving products by identifiers only default sort order is supported."); } request.QueryResultSettings.Sorting.Add(new SortColumn(SimpleProduct.IsRemoteColumnName, isDescending: false)); GetProductsDataRequest productsDataRequest; if (!request.ProductIds.IsNullOrEmpty()) { productsDataRequest = new GetProductsDataRequest(request.ProductIds, request.QueryResultSettings, downloadedProductsFilter); } else { productsDataRequest = new GetProductsDataRequest(request.ItemAndInventDimIdCombinations, request.QueryResultSettings, downloadedProductsFilter); } PagedResult <SimpleProduct> products = request.RequestContext.Execute <EntityDataServiceResponse <SimpleProduct> >(productsDataRequest).PagedEntityCollection; // If requested products are not found in the current store, download it to local database as assorted to current channel and then retrieve them. int numberOfProductsRequested = request.ProductIds.IsNullOrEmpty() ? request.ItemAndInventDimIdCombinations.Count : request.ProductIds.Count; int numberOfProductsExpected = request.QueryResultSettings.Paging.NoPageSizeLimit ? numberOfProductsRequested : Math.Min(numberOfProductsRequested, (int)request.QueryResultSettings.Paging.Top); if (request.SearchLocation.HasFlag(SearchLocation.Remote) && (products == null || products.Results.IsNullOrEmpty() || products.TotalCount < numberOfProductsExpected)) { try { UpsertRemoteProductData(request); } catch (FeatureNotSupportedException) { // Suppress FeatureNotSupportException for offline scenario. // Exception will be logged by ExceptionNotificationHandler. } products = request.RequestContext.Execute <EntityDataServiceResponse <SimpleProduct> >(productsDataRequest).PagedEntityCollection; } products = PopulateComplexProductProperties(request.ChannelId, products, request.RequestContext, request.SearchLocation, downloadedProductsFilter, request.CalculatePrice); // If a product is assorted locally and downloaded from virtual catalog, we only return the locally assorted version. // Ideally, collapsing these should happen from the underlying product data service. products.Results = products.Results.GroupBy(p => p.RecordId).Select(group => group.OrderBy(p => p.IsRemote).First()).AsReadOnly(); return(new GetProductsServiceResponse(products)); }
private static PagedResult <SimpleProduct> PopulateComplexProductProperties(long channelId, PagedResult <SimpleProduct> products, RequestContext context, SearchLocation searchLocation, bool?downloadedProductsFilter, bool calculatePrices) { // Retrieving all id collections needed to query the Data Service for complex properties. var productIds = products.Results.Select(p => p.RecordId); var masterTypeProductIds = products.Results.Where(p => p.ProductType == ProductType.Master).Select(p => p.RecordId); var kitVariantTypeProductIds = products.Results.Where(p => p.ProductType == ProductType.KitVariant).Select(v => v.RecordId); var kitMasterTypeProductIds = products.Results.Where(p => p.ProductType == ProductType.KitMaster).Select(v => v.RecordId); var variantTypeProductIds = products.Results.Where(p => p.ProductType == ProductType.Variant).Select(v => v.RecordId); // Products of types Master and KitMaster have dimensions that need to be retrieved. var idsOfProductsContainingDimensions = masterTypeProductIds.Concat(kitMasterTypeProductIds); IEnumerable <ProductComponent> components = new List <ProductComponent>(); IEnumerable <ProductDimension> productDimensions = new List <ProductDimension>(); IEnumerable <ProductDimensionValue> dimensionValues = new List <ProductDimensionValue>(); // Products of type KitVariant have components that need to be retrieved. if (kitVariantTypeProductIds.Any()) { var getProductComponentsDataRequestColummnSet = ProductComponent.DefaultColumnSet; getProductComponentsDataRequestColummnSet.Add("VARIANTPRODUCTID"); var getProductComponentsDataRequestSettings = new QueryResultSettings(getProductComponentsDataRequestColummnSet, PagingInfo.AllRecords); var getProductComponentsDataRequest = new GetProductComponentsForVariantProductsDataRequest(kitVariantTypeProductIds, getProductComponentsDataRequestSettings, downloadedProductsFilter); components = context.Execute <EntityDataServiceResponse <ProductComponent> >(getProductComponentsDataRequest).PagedEntityCollection.Results; } if (idsOfProductsContainingDimensions.Any()) { var getDimensionsDataRequest = new GetProductDimensionsDataRequest(idsOfProductsContainingDimensions, QueryResultSettings.AllRecords); productDimensions = context.Execute <EntityDataServiceResponse <ProductDimension> >(getDimensionsDataRequest).PagedEntityCollection.Results; } // Products of types Variant and KitVariant have dimension values that need to be retrieved. // This collection is populated after retrieving components so that dimension values of Variant type products can also be retrieved in the same transaction. var idsOfProductsContainingDimensionValues = variantTypeProductIds.Concat(kitVariantTypeProductIds).Concat(components.Where(c => c.ProductType == ProductType.Variant).Select(c => c.ProductId).Distinct()); if (idsOfProductsContainingDimensionValues.Any()) { var getDimensionValuesDataRequest = new GetProductDimensionValuesForVariantProductsDataRequest(idsOfProductsContainingDimensionValues, QueryResultSettings.AllRecords, downloadedProductsFilter); dimensionValues = context.Execute <EntityDataServiceResponse <ProductDimensionValue> >(getDimensionValuesDataRequest).PagedEntityCollection.Results; } var productIdsToFetchBehavior = productIds.Concat(components.Select(c => c.ProductId).Distinct()); var productBehaviorSettings = new QueryResultSettings(ProductBehavior.DefaultColumnSet, PagingInfo.CreateWithExactCount(productIdsToFetchBehavior.Count(), skip: 0)); var productsBehaviorDataRequest = new GetProductBehaviorDataRequest(productIdsToFetchBehavior, productBehaviorSettings, downloadedProductsFilter); PagedResult <ProductBehavior> productsBehavior = context.Execute <EntityDataServiceResponse <ProductBehavior> >(productsBehaviorDataRequest).PagedEntityCollection; var getLinkedProductRelationsDataRequest = new GetLinkedProductRelationsDataRequest(productIds, QueryResultSettings.AllRecords, downloadedProductsFilter); PagedResult <LinkedProductRelation> linkedProductRelations = context.Execute <EntityDataServiceResponse <LinkedProductRelation> >(getLinkedProductRelationsDataRequest).PagedEntityCollection; var linkedProductIds = linkedProductRelations.Results.Select(r => r.LinkedProductId).Distinct(); var getLinkedProductsDataRequest = new GetProductsServiceRequest(channelId, linkedProductIds, QueryResultSettings.AllRecords); getLinkedProductsDataRequest.SearchLocation = searchLocation; PagedResult <SimpleProduct> linkedProducts = context.Execute <GetProductsServiceResponse>(getLinkedProductsDataRequest).Products; PagedResult <ProductPrice> productPrices = PagedResult <ProductPrice> .Empty(); if (calculatePrices) { // Pricing APIs currently take Product instead of SimpleProduct. We manually build a Product object // and populate the required field in the interim until uptake of SimpleProduct in pricing service. List <Product> productsTransformedForPricing = ConvertSimpleProductsToProducts(products.Results).ToList(); var priceRequest = new GetProductPricesServiceRequest(productsTransformedForPricing); productPrices = context.Execute <GetProductPricesServiceResponse>(priceRequest).ProductPrices; } return(InsertProductPropertiesIntoProduct(products, productsBehavior, productPrices, linkedProductRelations, linkedProducts, components, productDimensions, dimensionValues)); }