コード例 #1
0
ファイル: QuotesController.cs プロジェクト: BizzyQuote/BQ2013
        public ActionResult AddQuoteItem(QuoteItem item)
        {
            Material material;
            List<WasteFactor> wasteFactors = new List<WasteFactor>();
            using (var mm = new MaterialsManager())
            {
                material = mm.SingleMaterial(item.MaterialID.GetValueOrDefault());
            }
            using (var qm = new QuoteManager())
            {
                var quote = qm.Single(item.QuoteID);
                using (var wfm = new WasteFactorManager())
                {
                    wasteFactors = wfm.ByCompany(quote.CompanyID.GetValueOrDefault()).ToList();
                }
                decimal wasteFactor =
                            wasteFactors.Any(
                                wf => wf.ProductID == item.ProductID && wf.ProductLineID == item.ProductLineID)
                                ? wasteFactors.First(
                                    wf => wf.ProductID == item.ProductID && wf.ProductLineID == item.ProductLineID)
                                              .WasteFactor1.GetValueOrDefault() : 0M;
                // calculate the amount and save
                switch (item.Measurement)
                {
                    case(Measurement.SquareFeet):
                        if (item.SquareFt.GetValueOrDefault() == 0)
                        {
                            item.SquareFt = item.Height*item.Width;
                        }
                        var pieceSqFt = (material.Height - material.Overlap.GetValueOrDefault())*(1M/12M)*material.Width;
                        var pieces = Math.Ceiling((decimal)(item.SquareFt.GetValueOrDefault() * (1M + wasteFactor) / pieceSqFt));

                        item.Amount = pieces * material.UnitCost;
                        break;
                    case (Measurement.LinearFeet):
                        item.Amount = item.LinearFt * (1M + wasteFactor) * material.UnitCost / material.Width;
                        break;
                    case (Measurement.Constant):
                        item.Amount = item.Dollars;
                        break;
                }

                item = qm.CreateItem(item);
            }
            return RedirectToAction("Edit", new { id = item.QuoteID });
        }
コード例 #2
0
ファイル: QuotesController.cs プロジェクト: BizzyQuote/BQ2013
        public ActionResult Edit(int id)
        {
            Quote quote;
            using (var qm = new QuoteManager())
            {
                quote = qm.Single(id);
                ViewBag.Quote = quote;
            }

            // determine the supplier and materials available
            List<CompanyToSupplier> companySuppliers;
            using (var sm = new SupplierManager())
            {
                companySuppliers = sm.ByCompanyID(quote.CompanyID.GetValueOrDefault()).ToList();
            }
            List<Product> products;
            using (var mm = new MaterialsManager())
            {
                List<Material> allMaterials = new List<Material>();
                foreach (var companyToSupplier in companySuppliers)
                {
                    allMaterials.AddRange(mm.BySupplier(companyToSupplier.SupplierID));
                }
                ViewBag.AvailableMaterials = allMaterials;

                products = mm.ActiveProducts(quote.CompanyID.GetValueOrDefault()).ToList();

                var productLines = mm.ActiveProductLines().ToList();
                ViewBag.ProductLines = productLines.AsEnumerable();
                ViewBag.ProductToProductLine = mm.AllProductToProductLine().ToList();
                ViewBag.MaterialToProducts = mm.AllMaterialToProducts().ToList();
            }

            ViewBag.Products = products;

            return View("Edit");
        }