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 }); }
public ActionResult WasteFactors(List<WasteFactorModel> models) { var factors = models.Select(model => new WasteFactor { ID = model.ID, CompanyID = model.CompanyID, CreatedOn = model.CreatedOn, ModifiedOn = model.ModifiedOn, ModifiedBy = model.ModifiedBy, WasteFactor1 = model.Factor, ProductLineID = model.ProductLineID, ProductID = model.ProductID }).ToList(); using (var wfm = new WasteFactorManager()) { var result = wfm.UpdateWasteFactors(factors); } return RedirectToAction("List"); }
public ActionResult WasteFactors(int companyID) { var wasteFactors = new List<WasteFactor>(); var model = new List<WasteFactorModel>(); var prodParts = new List<ProductToLine>(); List<Product> products = new List<Product>(); List<ProductLine> partsOfHouse = new List<ProductLine>(); using (var mm = new MaterialsManager()) { prodParts = mm.AllProductToProductLine().ToList(); products = mm.AllProducts().ToList(); partsOfHouse = mm.ActiveProductLines().ToList(); } using (var wfm = new WasteFactorManager()) { wasteFactors = wfm.ByCompany(companyID).ToList(); } foreach (var pph in prodParts) { if (!wasteFactors.Any(wf => wf.ProductID == pph.ProductID && wf.ProductLineID == pph.ProductLineID)) { model.Add(new WasteFactorModel { CompanyID = companyID, CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, ModifiedBy = User.Identity.Name, ProductLineID = pph.ProductLineID, ProductID = pph.ProductID, ProductName = products.FirstOrDefault(p => p.ID == pph.ProductID).Name, ProductLineName = partsOfHouse.FirstOrDefault(p => p.ID == pph.ProductID).Name }); } else { var fact = wasteFactors.FirstOrDefault( wf => wf.ProductID == pph.ProductID && wf.ProductLineID == pph.ProductLineID); model.Add(new WasteFactorModel { ID = fact.ID, CompanyID = companyID, CreatedOn = fact.CreatedOn, ModifiedOn = fact.CreatedOn, ModifiedBy = fact.ModifiedBy, ProductLineID = pph.ProductLineID, ProductID = pph.ProductID, ProductName = products.FirstOrDefault(p => p.ID == pph.ProductID).Name, ProductLineName = partsOfHouse.FirstOrDefault(p => p.ID == pph.ProductID).Name, Factor = fact.WasteFactor1.GetValueOrDefault() }); } } return View("WasteFactors", model); }