public IHttpActionResult UpdateProductsPrices(webModel.ProductPrice[] productPrices) { var result = _pricingSearchService.SearchPrices(new Domain.Pricing.Model.Search.PricesSearchCriteria { Take = int.MaxValue, ProductIds = productPrices.Select(x => x.ProductId).ToArray() }); var targetPricesGroups = result.Results.GroupBy(x => x.PricelistId); var sourcePricesGroups = productPrices.SelectMany(x => x.Prices).GroupBy(x => x.PricelistId); var changedPrices = new List <Price>(); var deletedPrices = new List <Price>(); foreach (var sourcePricesGroup in sourcePricesGroups) { var targetPricesGroup = targetPricesGroups.FirstOrDefault(x => x.Key == sourcePricesGroup.Key); if (targetPricesGroup != null) { sourcePricesGroup.ToArray().CompareTo(targetPricesGroup.ToArray(), EqualityComparer <Price> .Default, (state, x, y) => { switch (state) { case EntryState.Modified: case EntryState.Added: changedPrices.Add(x); break; case EntryState.Deleted: deletedPrices.Add(x); break; } }); } else { changedPrices.AddRange(sourcePricesGroup); } } _pricingService.SavePrices(changedPrices.ToArray()); if (!deletedPrices.IsNullOrEmpty()) { _pricingService.DeletePrices(deletedPrices.Select(x => x.Id).ToArray()); } return(StatusCode(HttpStatusCode.NoContent)); }
public virtual Task Handle(ProductChangedEvent message) { if (message == null) { throw new ArgumentNullException(nameof(message)); } var deletedProductIds = message.ChangedEntries.Where(x => x.EntryState == EntryState.Deleted && x.OldEntry.Id != null) .Select(x => x.OldEntry.Id) .Distinct().ToArray(); if (!deletedProductIds.IsNullOrEmpty()) { var searchResult = _pricingSearchService.SearchPrices(new PricesSearchCriteria { ProductIds = deletedProductIds, Take = int.MaxValue }); if (searchResult.Results.Any()) { _pricingService.DeletePrices(searchResult.Results.Select(p => p.Id).ToArray()); } } return(Task.CompletedTask); }
public void DeletePrices(string[] ids) { _pricingService.DeletePrices(ids); ClearCache(); }