Inheritance: DomainEntity
Esempio n. 1
0
        public void Execute(RecipeJob recipeJob)
        {
            var recipes = _recipeFinder.FindRecipes(recipeJob);
            if (recipes == null)
            {
                Console.WriteLine("Could not find recipe for {0}", recipeJob.SalesItem);
                return;
            }
            Console.WriteLine("Got recipe(s) for {0}", recipeJob.SalesItem);
            foreach(var recipe in recipes)
            {
                foreach (var recipeItem in recipe.RecipeItems)
                {
                    var stock = _stockFinder.FindStockFor(recipeJob, recipeItem);
                    if (stock == null)
                    {
                        Console.WriteLine("Could not find stock for {0}", recipeItem.RecipeableItem.Name);
                        continue;
                    }
                    Console.WriteLine("Got stock {0} for {1}", stock.Name, recipeItem.RecipeableItem.Name);
                    _dbConversation.UsingTransaction(()=>
                        {
                            var moveRecipe = new StockMoveRecipe {OfStock = stock, ExecutedAt = DateTime.Now, Recipe = recipe};

                            var quantity = recipeJob.Quantity * recipeItem.Quantity;
                            var fromStockItem = _stockBooker.BookItemOutOfStock(stock, quantity, recipeItem.Unit, recipeItem.RecipeableItem);
                            if (fromStockItem != null)
                                _dbConversation.InsertObjectOnCommit(fromStockItem);
                            var moveItem = new StockMoveItem
                            {
                                Unit = recipeItem.Unit,
                                Quantity = quantity,
                                RecipeableItem = recipeItem.RecipeableItem,
                            };
                            moveRecipe.AddMoveItem(moveItem);

                            _dbConversation.InsertObjectOnCommit(moveRecipe);
                        });
                }
            }
        }
Esempio n. 2
0
 public virtual void RemoveMoveItem(StockMoveItem moveItem)
 {
     _moveItems.Remove(moveItem);
 }
Esempio n. 3
0
 public virtual void AddMoveItem(StockMoveItem moveItem)
 {
     moveItem.StockMovement = this;
     _moveItems.Add(moveItem);
 }
        public bool Submit()
        {
            try
            {
                DbConversation.UsingTransaction(() =>
                    {
                        var moveTransfer = new StockMoveTransfer{FromStock = FromStock, OfStock = ToStock, ExecutedAt = DateTime.Now};

                        foreach (var item in ItemsToMove.Where(c => c.QuantityToBook != 0.0m))
                        {
                            var toStockItem = _stockBooker.BookItemIntoStock(ToStock, item.QuantityToBook, item.UnitToBook, item.ItemToBook);
                            if (toStockItem == null)
                                continue;
                            DbConversation.InsertObjectOnCommit(toStockItem);
                            var fromStockItem = _stockBooker.BookItemOutOfStock(FromStock, item.QuantityToBook, item.UnitToBook, item.ItemToBook);
                            if( fromStockItem!=null )
                                DbConversation.InsertObjectOnCommit(fromStockItem);
                        
                            var moveItem = new StockMoveItem
                                {
                                    Unit = item.UnitToBook,
                                    Quantity = item.QuantityToBook,
                                    RecipeableItem = item.ItemToBook,
                                };
                            moveTransfer.AddMoveItem(moveItem);
                        }

                        DbConversation.InsertObjectOnCommit(moveTransfer);
                    });
                EventAggregator.GetEvent<StockChangedEvent>().Publish(ToStock);
                EventAggregator.GetEvent<StockChangedEvent>().Publish(FromStock);
                return true;
            }
            catch
            {
                MessageBox.Show(Strings.Error_BookItems_CannotBook);
                return false;
            }

        }