public virtual async Task <long> GetTotalChangesCountAsync(DateTime?startDate, DateTime?endDate) { long result; if (startDate == null && endDate == null) { // Get total products count using (var repository = _memberRepositoryFactory()) { result = repository.Members.Count(); } } else { var criteria = new ChangeLogSearchCriteria { ObjectType = ChangeLogObjectType, StartDate = startDate, EndDate = endDate, Take = 0 }; // Get changes count from operation log result = (await _changeLogSearchService.SearchAsync(criteria)).TotalCount; } return(result); }
public async Task <ActionResult <ChangeLogSearchResult> > SearchChanges([FromBody] ChangeLogSearchCriteria criteria) { // Get changes count from operation log var result = await _changeLogSearchService.SearchAsync(criteria); return(Ok(result.Results)); }
public async Task <ActionResult <OperationLog[]> > GetOrderChanges(string id) { var result = Array.Empty <OperationLog>(); var order = await _customerOrderService.GetByIdAsync(id); if (order != null) { var authorizationResult = await _authorizationService.AuthorizeAsync(User, order, new OrderAuthorizationRequirement(ModuleConstants.Security.Permissions.Read)); if (!authorizationResult.Succeeded) { return(Unauthorized()); } //Load general change log for order var allHasChangesObjects = order.GetFlatObjectsListWithInterface <IHasChangesHistory>() .Distinct().ToArray(); var criteria = new ChangeLogSearchCriteria { ObjectIds = allHasChangesObjects.Select(x => x.Id).Distinct().ToArray(), ObjectTypes = allHasChangesObjects.Select(x => x.GetType().Name).Distinct().ToArray() }; result = (await _changeLogSearchService.SearchAsync(criteria)).Results.ToArray(); } return(Ok(result)); }
/// <summary> /// Retrieves all price changes and groups them by the product Id they are associated with. /// </summary> /// <param name="startDate">The date time period from</param> /// <param name="endDate">The date time period to</param> /// <returns>The unique list of products identifiers associated with changed prices for passed period</returns> protected virtual async Task <ICollection <string> > GetProductIdsForChangedPricesAsync(DateTime?startDate, DateTime?endDate) { var result = new HashSet <string>(); var criteria = new ChangeLogSearchCriteria { ObjectType = _changeLogObjectType, StartDate = startDate, EndDate = endDate, Take = 0 }; // Get changes from operation log var operations = (await _changeLogSearchService.SearchAsync(criteria)).Results.Select(x => x.ObjectId); using (var repository = _repositoryFactory()) { var totalCount = operations.Count(); for (var i = 0; i < totalCount; i += _batchSize) { var changedPriceIds = operations.Skip(i).Take(_batchSize).ToArray(); var productIds = await repository.Prices.Where(x => changedPriceIds.Contains(x.Id)) .Select(x => x.ProductId) .Distinct() .ToArrayAsync(); result.AddRange(productIds); } } return(result); }
public async Task <long> GetTotalChangesCountAsync(DateTime?startDate, DateTime?endDate) { long result; var criteria = new ChangeLogSearchCriteria { ObjectType = ChangeLogObjectType, StartDate = startDate, EndDate = endDate, Take = 0 }; // Get changes count from operation log result = (await _changeLogSearchService.SearchAsync(criteria)).TotalCount; return(result); }
private async Task <ChangeLogSearchResult> SearchDeleteOperationsInLog(DateTime?startDate, DateTime?endDate, long skip, long take) { var criteria = new ChangeLogSearchCriteria { ObjectType = ChangeLogObjectType, OperationTypes = new[] { EntryState.Deleted }, StartDate = startDate, EndDate = endDate, Skip = Convert.ToInt32(skip), Take = Convert.ToInt32(take) }; var searchResult = (await _changeLogSearchService.SearchAsync(criteria)); return(searchResult); }
public async Task <ActionResult <LastModifiedResponse> > GetLastModifiedDate([FromQuery] string scope = null) { var criteria = new ChangeLogSearchCriteria { Take = 1 }; // Get latest change from operation log var latestChange = (await _changeLogSearchService.SearchAsync(criteria)).Results.FirstOrDefault(); var result = new LastModifiedResponse { Scope = scope, LastModifiedDate = new DateTime(Math.Max((latestChange?.ModifiedDate ?? _lastTimestamp).Ticks, _lastTimestamp.Ticks)) }; return(Ok(result)); }
public virtual async Task <long> GetTotalChangesCountAsync(DateTime?startDate, DateTime?endDate) { long result; if (startDate == null && endDate == null) { // We don't know the total products count result = 0L; } else { var criteria = new ChangeLogSearchCriteria { ObjectType = ChangeLogObjectType, StartDate = startDate, EndDate = endDate, Take = 0 }; // Get changes count from operation log result = (await _changeLogSearchService.SearchAsync(criteria)).TotalCount; } return(result); }
private async Task <int> GetCustomerSegmentsChangesCount(DateTime?startDate, DateTime?endDate) { var customerSegmentsChangesCount = 0; if (startDate != null || endDate != null) { var criteria = new ChangeLogSearchCriteria { ObjectType = nameof(DemoCustomerSegment), StartDate = startDate, EndDate = endDate, Take = 0 }; // Get customer segments count from operation log customerSegmentsChangesCount = (await _changeLogSearchService.SearchAsync(criteria)).TotalCount; } return(customerSegmentsChangesCount); }
private async Task <IReadOnlyCollection <IndexDocumentChange> > PerformGettingOrders(int skip, int take) { if (_startDate == null && _endDate == null) { var searchCriteria = new CustomerOrderSearchCriteria { Skip = skip, Take = take }; var searchResult = await _orderSearchService.SearchCustomerOrdersAsync(searchCriteria); return(searchResult.Results .Select(x => new IndexDocumentChange { ChangeDate = x.ModifiedDate ?? DateTime.MinValue, DocumentId = x.Id, ChangeType = IndexDocumentChangeType.Modified }) .ToArray()); } else { var customerOrderType = GetCustomerOrderType(); var searchResult = await _changeLogSearchService.SearchAsync(new ChangeLogSearchCriteria { ObjectType = customerOrderType, StartDate = _startDate, EndDate = _endDate }); return(searchResult.Results.Select(x => x.ObjectId) .Distinct() .Skip(skip) .Take(take) .Select(x => new IndexDocumentChange { ChangeDate = DateTime.MinValue, DocumentId = x, ChangeType = IndexDocumentChangeType.Modified }) .ToArray()); } }
public async Task <ActionResult <OperationLog[]> > GetOrderChanges(string id) { var result = Array.Empty <OperationLog>(); var order = await _customerOrderService.GetByIdAsync(id); if (order != null) { //Load general change log for order var allHasHangesObjects = order.GetFlatObjectsListWithInterface <IHasChangesHistory>() .Distinct().ToArray(); var criteria = new ChangeLogSearchCriteria { ObjectIds = allHasHangesObjects.Select(x => x.Id).Distinct().ToArray(), ObjectTypes = allHasHangesObjects.Select(x => x.GetType().Name).Distinct().ToArray() }; result = (await _changeLogSearchService.SearchAsync(criteria)).Results.ToArray(); } return(Ok(result)); }
public async Task <License[]> GetByIdsAsync(string[] ids) { var result = Array.Empty <License>(); using (var repository = _licenseRepositoryFactory()) { var arrayLicense = await repository.GetByIdsAsync(ids); result = arrayLicense .Select(x => { var retVal = x.ToModel(AbstractTypeFactory <License> .TryCreateInstance()); return(retVal); }).ToArray(); } var searchResult = await _changeLogSearchService.SearchAsync(new ChangeLogSearchCriteria { ObjectIds = ids, ObjectType = typeof(License).Name, Take = int.MaxValue }); foreach (var license in result) { license.OperationsLog = searchResult.Results.Where(x => x.ObjectId == license.Id).ToList(); } return(result); }