예제 #1
0
            public void Setup()
            {
                _db  = SingletonTestSetup.Instance().Get();
                repo = new Repo(_db);

                powderInfo = new StaticPowderInfo
                {
                    StaticPowderInfoId = Guid.NewGuid(),
                    EndlasDescription  = "TestPowder",
                    Density            = 1f,
                };
                _db.StaticPowderInfo.Add(powderInfo);
                _db.SaveChanges();

                vendor = new Vendor
                {
                    VendorId       = Guid.NewGuid(),
                    VendorName     = "Name",
                    PointOfContact = "POC",
                    VendorAddress  = "Address",
                    VendorPhone    = "Phone"
                };
                _db.Vendors.Add(vendor);
                _db.SaveChanges();

                powderOrderGood = new PowderOrder
                {
                    PowderOrderId     = Guid.NewGuid(),
                    PurchaseOrderDate = DateTime.Now,
                    PurchaseOrderNum  = "",
                    ShippingCost      = 0.0f,
                    TaxCost           = 0.0f,
                    Vendor            = vendor,
                    VendorId          = vendor.VendorId,
                };
                _db.PowderOrders.Add(powderOrderGood);

                powderOrderBad = new PowderOrder
                {
                    PowderOrderId     = Guid.NewGuid(),
                    PurchaseOrderDate = DateTime.Now,
                    PurchaseOrderNum  = "",
                    ShippingCost      = 0.0f,
                    TaxCost           = 0.0f,
                    Vendor            = vendor,
                    VendorId          = vendor.VendorId,
                };
                _db.PowderOrders.Add(powderOrderBad);
                _db.SaveChanges();
            }
        public async Task <IActionResult> Create([Bind("StaticPowderInfoId,EndlasDescription,Density,Description,EstCostPerLb,Composition,FlowRateSlope,FlowRateYIntercept,InformationFile")] StaticPowderInfo staticPowderInfo)
        {
            if (ModelState.IsValid)
            {
                staticPowderInfo.StaticPowderInfoId = Guid.NewGuid();
                if (staticPowderInfo.InformationFile != null)
                {
                    staticPowderInfo.InformationFilePdfBytes = await FileURL.GetFileBytes(staticPowderInfo.InformationFile);
                }
                SetUIDs();
                await _repo.AddStaticPowderInfo(staticPowderInfo);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(staticPowderInfo));
        }
        public async Task <IActionResult> Edit(Guid id, [Bind("StaticPowderInfoId,EndlasDescription,Density,Description,EstCostPerLb,Composition,ClearInformation,FlowRateSlope,FlowRateYIntercept,InformationFile")] StaticPowderInfo staticPowderInfo)
        {
            if (id != staticPowderInfo.StaticPowderInfoId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (staticPowderInfo.ClearInformation)
                    {
                        staticPowderInfo.InformationFilePdfBytes = null;
                    }
                    else if (staticPowderInfo.InformationFile != null)
                    {
                        staticPowderInfo.InformationFilePdfBytes = await FileURL.GetFileBytes(staticPowderInfo.InformationFile);
                    }
                    SetUIDs();
                    await _repo.UpdateStaticPowderInfo(staticPowderInfo);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!(await StaticPowderInfoExists(staticPowderInfo.StaticPowderInfoId)))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(staticPowderInfo));
        }