Exemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("LineItemId,StaticPowderInfoId,VendorDescription,Weight,LineItemCost,ParticleSizeMin,ParticleSizeMax,PowderOrderId,NumBottles")] LineItem lineItem)
        {
            if (ModelState.IsValid)
            {
                lineItem.LineItemId       = Guid.NewGuid();
                lineItem.StaticPowderInfo = await _repo.GetStaticPowderInfo((Guid)lineItem.StaticPowderInfoId);

                lineItem.StaticPowderInfoId = lineItem.StaticPowderInfo.StaticPowderInfoId;
                SetUIDs();
                await _repo.AddLineItem(lineItem);

                List <PowderBottle> bottles = new List <PowderBottle>();
                for (int i = 0; i < lineItem.NumBottles; i++)
                {
                    var newPowder = new PowderBottle
                    {
                        PowderBottleId     = Guid.NewGuid(),
                        BottleNumber       = "",
                        LotNumber          = "",
                        InitWeight         = 0,
                        Weight             = 0,
                        LineItem           = lineItem,
                        LineItemId         = lineItem.LineItemId,
                        StaticPowderInfo   = lineItem.StaticPowderInfo,
                        StaticPowderInfoId = lineItem.StaticPowderInfo.StaticPowderInfoId
                    };

                    bottles.Add(newPowder);
                }
                SetUIDs();
                await _repo.AddPowderBottles(bottles);

                if (bottles.Any())
                {
                    ViewBag.IsInitialized = true;
                }
                return(RedirectToAction("Index", "PowderOrders"));
            }
            return(View(lineItem));
        }