public string getBarcode()
        {
            baseproduct       baseProduct = new baseproduct();
            barcodeController barcode     = new barcodeController(_context);
            var barcodeID = barcode.getFirstAvailableBarcode();

            return(barcodeID);
        }
Ejemplo n.º 2
0
 public IActionResult Create([Bind("packedId,packedProductName,packedProductBarcodeID,productRetailPrice,productWholesalePrice")] packedproduct packedproduct)
 {
     if (ModelState.IsValid)
     {
         packedproduct.packedProductDetails = new List <packedproductdetail>();
         var baseIds   = HttpContext.Request.Form["item.baseProduct.baseId"].ToArray();
         var amounts   = HttpContext.Request.Form["packedproductdetails.amount"].ToArray();
         var operation = HttpContext.Request.Form["operation"].ToString();
         packedproduct.productRetailPrice    = decimal.Parse(HttpContext.Request.Form["productRetailPrice"].ToString().Replace('.', ','));
         packedproduct.productWholesalePrice = decimal.Parse(HttpContext.Request.Form["productWholesalePrice"].ToString().Replace('.', ','));
         if (packedproduct.packedProductBarcodeID == null || packedproduct.packedProductBarcodeID.Length != 13)
         {
             barcodeController barcode = new barcodeController(_context);
             packedproduct.packedProductBarcodeID = barcode.getFirstAvailableBarcode();
         }
         for (int i = 0; i < baseIds.Length; i++)
         {
             packedproductdetail item = new packedproductdetail();
             item.baseId                 = int.Parse(baseIds[i]);
             item.amount                 = decimal.Parse(amounts[i].Replace('.', ','));
             item.contentLineNo          = i + 1;
             item.packedId               = packedproduct.packedId;
             item.packedProductBarcodeID = packedproduct.packedProductBarcodeID;
             item.baseProduct            = _context.baseProducts.First(s => s.baseId == item.baseId);
             item.baseProductBarcodeID   = item.baseProduct.barcodeID;
             packedproduct.packedProductDetails.Add(item);
         }
         if (operation == "Add")
         {
             _context.packedProducts.Add(packedproduct);
             _context.SaveChanges();
         }
         else
         {
             for (int i = 0; i < packedproduct.packedProductDetails.Count; i++)
             {
                 if (_context.packedProductDetails.Any(s => s.packedId == packedproduct.packedProductDetails[i].packedId && s.contentLineNo == packedproduct.packedProductDetails[i].contentLineNo))
                 {
                     _context.packedProductDetails.Update(packedproduct.packedProductDetails[i]);
                 }
                 else
                 {
                     _context.packedProductDetails.Add(packedproduct.packedProductDetails[i]);
                 }
             }
             _context.Update(packedproduct);
             _context.SaveChanges();
         }
         return(RedirectToAction("Create", new { packedId = packedproduct.packedId + 1 }));
     }
     return(View(packedproduct));
 }