Esempio n. 1
0
 public bool SupplyMaterial(String type, int amount)
 {
     if (type != null && amount > 0)
     {
         var matStock = GetMaterialStockFormModel();
         var mat      = new MaterialStockFormModel();
         foreach (MaterialStockFormModel x in matStock)
         {
             // prueft ob es Material mit ausreichend Bestand vom entsprechenden Typ gibt
             if (x.ActualStock >= amount && x.Name.ToLower().Contains(type.ToLower()))
             {
                 mat = x;
                 break;
             }
             // gibt false zurueck, falls es kein Material mit ausreichend Bestand gibt
             //else return false;
         }
         var stockModel = _context.Stock.Where(x => x.MaterialId == mat.MaterialId && x.Amount > amount).First();
         var collModel  = new CollectionOrderFormModel
         {
             Amount    = amount,
             OrderType = "Supply",
             StockId   = stockModel.StockId
         };
         CreateCollectionOrder(collModel);
         return(true);
     }
     return(false);
 }
Esempio n. 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);
        }
Esempio n. 3
0
 public CollectionOrder CreateCollectionOrder(CollectionOrderFormModel data)
 {
     data.OrderType = "Collect";
     return(this._context.CreateCollectionOrder(data));
 }