public void Invoke() { ProductUpdateData productdata = new ProductUpdateData(); productdata.Product = this.Product; productdata.Update(); }
public bool Invoke() { bool complete = false; try { ProductUpdateData productdata = new ProductUpdateData(); productdata.Product = this.Product; productdata.Update(); complete = true; } catch (Exception ex) { throw ex; } return(complete); }
public async Task <List <ProductUpdateData> > BuildProductUpdateData() { var yesterday = DateTime.Now.AddDays(-1); var startOfYesterday = new DateTime(yesterday.Year, yesterday.Month, yesterday.Day, 0, 0, 0); var yesterdaysProductUpdates = await _productQuery.ListByDate(startOfYesterday); var yesterdaysPriceScheduleUpdates = await _priceScheduleQuery.ListByDate(startOfYesterday); var filterString = String.Join("|", yesterdaysPriceScheduleUpdates.Select(p => p.ResourceID)); var defaultPriceScheduleProducts = await _oc.Products.ListAsync(filters : $"DefaultPriceScheduleID={filterString}"); var updatedProducts = yesterdaysProductUpdates.Select(p => p.Resource).Concat(defaultPriceScheduleProducts.Items.Where(p => !yesterdaysProductUpdates.Select(p => p.ResourceID).Contains(p.ID))); var dataToSend = new List <ProductUpdateData>(); foreach (var product in updatedProducts) { var productUpdateRecord = yesterdaysProductUpdates.Find(p => p.ResourceID == product.ID); var updatedProduct = productUpdateRecord?.Resource; var priceScheduleUpdateRecord = yesterdaysPriceScheduleUpdates.Find(p => p.ResourceID == product.DefaultPriceScheduleID); var updatedPriceSchedule = priceScheduleUpdateRecord?.Resource; var oldProduct = (await _productQuery.GetVersionByDate(updatedProduct?.ID, startOfYesterday))?.Resource; var oldPriceSchedule = (await _priceScheduleQuery.GetVersionByDate(updatedPriceSchedule?.ID, startOfYesterday))?.Resource; var updateData = new ProductUpdateData() { Supplier = product.OwnerID, ProductID = product.ID, ProductAction = productUpdateRecord != null?Enum.GetName(typeof(ActionType), productUpdateRecord?.Action) : null, DefaultPriceScheduleID = updatedPriceSchedule?.ID, DefaultPriceScheduleAction = priceScheduleUpdateRecord != null?Enum.GetName(typeof(ActionType), priceScheduleUpdateRecord?.Action) : null, }; if (updatedProduct?.xp?.ProductType != oldProduct?.xp?.ProductType) { updateData.NewProductType = updatedProduct?.xp?.ProductType.ToString(); updateData.NewProductType = updatedProduct?.xp?.ProductType.ToString(); } if (updatedProduct?.xp?.UnitOfMeasure?.Qty != oldProduct?.xp?.UnitOfMeasure?.Qty) { updateData.NewUnitQty = updatedProduct?.xp?.UnitOfMeasure?.Qty; updateData.OldUnitQty = oldProduct?.xp?.UnitOfMeasure?.Qty; } if (updatedProduct?.xp?.UnitOfMeasure?.Unit != oldProduct?.xp?.UnitOfMeasure?.Unit) { updateData.NewUnitMeasure = updatedProduct?.xp?.UnitOfMeasure?.Unit; updateData.OldUnitMeasure = oldProduct?.xp?.UnitOfMeasure?.Unit; } if (updatedProduct?.Active != oldProduct?.Active) { updateData.NewActiveStatus = updatedProduct?.Active; updateData.OldActiveStatus = oldProduct?.Active; } if (updatedPriceSchedule?.MaxQuantity != oldPriceSchedule?.MaxQuantity) { updateData.NewMaxQty = updatedPriceSchedule?.MaxQuantity; updateData.OldMaxQty = oldPriceSchedule?.MaxQuantity; } if (updatedPriceSchedule?.MinQuantity != oldPriceSchedule?.MinQuantity) { updateData.NewMaxQty = updatedPriceSchedule?.MinQuantity; updateData.OldMaxQty = oldPriceSchedule?.MinQuantity; } if (updatedPriceSchedule?.PriceBreaks != oldPriceSchedule?.PriceBreaks) { var updatedBreaks = updatedPriceSchedule.PriceBreaks?.Select(p => JsonConvert.SerializeObject(p))?.ToList(); var oldBreaks = oldPriceSchedule?.PriceBreaks?.Select(p => JsonConvert.SerializeObject(p))?.ToList(); updateData.NewPriceBreak = updatedBreaks == null ? null : String.Join(",", updatedBreaks); updateData.OldPriceBreak = oldBreaks == null ? null : String.Join(",", oldBreaks); } dataToSend.Add(updateData); } return(dataToSend); }