Пример #1
0
 private bool updateStockFromCollectionOrder(CollectionOrder colOrder, int?stockId, String orderType)
 {
     if (colOrder != null)
     {
         int?  newAmount   = 0;
         Stock stockFromDB = _context.Stock.Find(stockId);
         if (stockFromDB == null)
         {
             return(false);
         }
         // holt sich aktuellen Amount
         var amount = colOrder.Amount.GetValueOrDefault();
         if (orderType == "Collect")
         {
             // erhoeht Amount um den neu zu eingelagerten Bestand
             newAmount = stockFromDB.Amount = stockFromDB.Amount.GetValueOrDefault() + amount;
         }
         else if (orderType == "Supply")
         {
             // verringert Amount um den neu zu eingelagerten Bestand
             newAmount = stockFromDB.Amount = stockFromDB.Amount.GetValueOrDefault() - amount;
         }
         // Speichert Aenderungen
         _context.Entry(stockFromDB).CurrentValues.SetValues(newAmount);
         _context.SaveChanges();
         return(true);
     }
     return(false);
 }
Пример #2
0
        public CollectionOrder CreateCollectionOrder(CollectionOrderFormModel data)
        {
            bool            valid = false;
            CollectionOrder newCollectionOrder = new CollectionOrder();

            newCollectionOrder.State = "New";

            // Falls Rohmaterial wieder eingelagert werden muss, muss geprueft werden ob es StockId existiert
            if (data.StockId != null || data.StockId != 0)
            {
                valid = _context.Stock.Any(x => x.StockId == data.StockId);
            }
            // wenn Fertigprodukt eingelagert werden soll, darf die Id nicht null sein
            if (data.CustOrderId != null || data.CustOrderId != 0)
            {
                valid = true;
            }
            if (valid)
            {
                _context.CollectionOrder.Add(newCollectionOrder);
                _context.Entry(newCollectionOrder).CurrentValues.SetValues(data);
                _context.SaveChanges();

                return(new CollectionOrder
                {
                    StockId = newCollectionOrder.StockId,
                    ProductionId = newCollectionOrder.ProductionId,
                    CustOrderId = newCollectionOrder.CustOrderId,
                    Amount = newCollectionOrder.Amount,
                    OrderType = newCollectionOrder.OrderType,
                    State = newCollectionOrder.State
                });
            }
            return(null);
        }
Пример #3
0
        private bool updateProducedProductFromCollectionOrder(CollectionOrder colOrder, int?productionId)
        {
            if (colOrder != null && productionId != null)
            {
                ProducedProduct newProducedProduct = new ProducedProduct
                {
                    ProductionId      = productionId.GetValueOrDefault(),
                    CustOrderId       = colOrder.CustOrderId.GetValueOrDefault(),
                    CollectionOrderId = colOrder.CollectionId,
                    Amount            = colOrder.Amount.GetValueOrDefault()
                };
                _context.ProducedProduct.Add(newProducedProduct);
                //_context.Entry(newCollectionOrder).CurrentValues.SetValues(data);
                _context.SaveChanges();

                return(true);
            }
            return(false);
        }
Пример #4
0
        public bool UpdateCollectionOrder(int collectionOrderId)
        {
            if (collectionOrderId == 0)
            {
                return(false);
            }

            bool valid = false;

            CollectionOrder colOrder = _context.CollectionOrder.Find(collectionOrderId);

            //var collectionOrderFromDB = _context.CollectionOrder.Where(x => x.CollectionId == collectionOrderId);
            if (colOrder != null)
            {
                var productionId = colOrder.ProductionId;
                var stockId      = colOrder.StockId;
                var orderType    = colOrder.OrderType;
                if (orderType != null)
                {
                    if (productionId != null)
                    {
                        valid = updateProducedProductFromCollectionOrder(colOrder, productionId);
                    }
                    if (stockId != null)
                    {
                        valid = updateStockFromCollectionOrder(colOrder, stockId, orderType);
                    }

                    // wenn Stock-Tabelle oder Produced-Product-Tabelle geupdatet wurden, dann true
                    if (valid)
                    {
                        var state = colOrder.State = "Done";
                        // Speichert Aenderungen
                        _context.Entry(colOrder).CurrentValues.SetValues(state);
                        _context.SaveChanges();

                        return(true);
                    }
                }
            }
            return(false);
        }