Esempio n. 1
0
        internal static DL.Models.Product SetProduct(ProductStock.DL.Models.Product product)
        {
            if (!ProductStocks.ContainsKey(product.Id))
            {
                ProductStocks.Add(product.Id, product);

                var result = new DL.Models.Product(product.Id, product.Number, product.Description);
                Products.Add(product.Id, result);

                var priceChanges = ChangeFactory.ToOrderedChangeEvent <
                    DL.Models.Product,
                    ProductStock.DL.Models.ProductPrice,
                    Guid,
                    double,
                    DateTimeOffset>(
                    x => x.Price,
                    0,
                    product.Prices,
                    x => x.Id,
                    x => x.Price,
                    x => x.RegisterDate).
                                   Cast <IEvent <DL.Models.Product, Guid> >().ToList();

                var stockAvailableMutations = MutationFactory.ToOrderedMutationEvent <
                    DL.Models.Product,
                    ProductStock.DL.Models.ProductStockMutation,
                    Guid,
                    int,
                    DateTimeOffset>(
                    x => x.Available,
                    product.StockMutations,
                    x => x.Id,
                    x => x.Amount * (x.Type == ProductStock.DL.Enums.MutationType.Purchase ? -1 : 1),
                    x => x.OrderDate).Cast <IEvent <DL.Models.Product, Guid> >().ToList();

                var stockInStockMutations = MutationFactory.ToOrderedMutationEvent <
                    DL.Models.Product,
                    ProductStock.DL.Models.ProductStockMutation,
                    Guid,
                    int,
                    DateTimeOffset>(
                    x => x.InStock,
                    product.StockMutations,
                    x => x.Id,
                    x => x.Amount * (x.Type == ProductStock.DL.Enums.MutationType.Purchase ? -1 : 1),
                    x => x.ShipmentDate).Cast <IEvent <DL.Models.Product, Guid> >().ToList();

                AddEvents(product.Id, new OrderedEventCollection <DL.Models.Product, Guid, DateTimeOffset>(priceChanges.ToList()));
                AddEvents(product.Id, new OrderedEventCollection <DL.Models.Product, Guid, DateTimeOffset>(stockAvailableMutations.ToList()));
                AddEvents(product.Id, new OrderedEventCollection <DL.Models.Product, Guid, DateTimeOffset>(stockInStockMutations.ToList()));

                return(result);
            }

            return(Products[product.Id]);
        }
Esempio n. 2
0
 private void cmdProductExpanded_Execute()
 {
     ProductStocks.Clear();
     foreach (var productStock in ContextManager.Context.dProductStocks)
     {
         ProductStocks.Add(new wrapProductStock {
             Stock = productStock
         });
     }
 }