public ActionResult Products() { ProductHouseModel model = new ProductHouseModel(); List<ProductToProductLineModel> phModel = new List<ProductToProductLineModel>(); using (var mm = new MaterialsManager()) { List<Product> products = mm.ActiveProducts().ToList(); List<ProductLine> partsOfHouse = mm.ActiveProductLines().ToList(); List<ProductToLine> prodHouses = mm.AllProductToProductLine().ToList(); model.Products = products.AsEnumerable(); model.PartsOfHouse = partsOfHouse.AsEnumerable(); // create the list based on our product and part list foreach (var partOfHouse in partsOfHouse) { foreach (var product in products) { phModel.Add(new ProductToProductLineModel { IsActive = prodHouses.Any(ph => ph.ProductID == product.ID && ph.ProductLineID == partOfHouse.ID) && prodHouses.First(ph => ph.ProductID == product.ID && ph.ProductLineID == partOfHouse.ID).IsActive, ProductID = product.ID, ProductLineID = partOfHouse.ID, ProductName = product.Name, ProductLineName = partOfHouse.Name }); } } model.ProductPartHouse = phModel.AsEnumerable(); } return View("Products", model); }
//[HttpPost] public ActionResult Clone(int id) { Material newMaterial = new Material(); using (var mm = new MaterialsManager()) { Material mat = mm.SingleMaterial(id); // use reflection to populate the new Material // reflect to get instances of the entity preoprties var editProperties = from p in mat.GetType().GetProperties() select p; // copy the values PropertyInfo[] editProps = editProperties.ToArray(); foreach (PropertyInfo propertyInfo in editProps) { propertyInfo.SetValue(newMaterial, propertyInfo.GetValue(mat, null), null); } // set specifics newMaterial.Name = mat.Name + " - Clone"; if (newMaterial.Name.Length > 100) { newMaterial.Name = newMaterial.Name.Substring(0, 100); } newMaterial.CreatedOn = DateTime.Now; newMaterial.ModifiedOn = DateTime.Now; newMaterial.ID = 0; newMaterial = mm.CreateMaterial(newMaterial); } return RedirectToAction("EditMaterial", new {id = newMaterial.ID}); }
public ActionResult AllMaterials() { List<Material> materials; using (var mm = new MaterialsManager()) { materials = mm.AllMaterials().ToList(); } ViewBag.Materials = materials; return View("MaterialList"); }
public ActionResult AllProducts() { List<Product> products; using (var mm = new MaterialsManager()) { products = mm.AllProducts().ToList(); } ViewBag.Products = products; return View("ProductList"); }
public ActionResult AvailableProducts(int materialID) { List<Product> products; List<MaterialToProduct> materialProducts; using (var mm = new MaterialsManager()) { products = mm.ActiveProducts().OrderBy(p => p.Name).ToList(); materialProducts = mm.ByMaterialID(materialID).ToList(); } ViewBag.Products = products; ViewBag.MaterialToProducts = materialProducts; return View("AvailableProducts"); }
public void CreateProduct() { Product product = new Product(); product.CreatedOn = DateTime.Now; product.Measurement = Measurement.SquareFeet; product.ModifiedOn = DateTime.Now; product.Name = "Siding"; using (var mm = new MaterialsManager()) { product = mm.CreateProduct(product); Assert.IsTrue(product.ID > 0); } }
public void CreateMaterialTest() { Material material = new Material(); material.CreatedOn = DateTime.Now; material.Measurement = Measurement.SquareFeet; material.ModifiedOn = DateTime.Now; material.Name = "Wood Siding"; material.SubName = "Light Blue"; using (var mm = new MaterialsManager()) { material = mm.CreateMaterial(material); Assert.IsTrue(material.ID > 0); } }
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 MaterialProductsGrid(MaterialProductGridModel model) { List<MaterialToProduct> mpAdd = new List<MaterialToProduct>(); List<int> mpDelete = new List<int>(); foreach (var mp in model.MaterialProducts) { if (mp.IsActive) { // we only need to add new ones since nothing will change with existing ones if (mp.MaterialToProductID == 0) { mpAdd.Add(new MaterialToProduct { ID = mp.MaterialToProductID, MaterialID = mp.MaterialID, ProductID = mp.ProductID }); } } else { // only need to delete ones that already exist in the database if (mp.MaterialToProductID > 0) { mpDelete.Add(mp.MaterialToProductID); } } } // now update the database by deleting ones and updating others using (var mm = new MaterialsManager()) { mm.DeleteMaterialToProducts(mpDelete); mm.InsertMaterialToProducts(mpAdd); } return RedirectToAction("Index"); }
public ActionResult MaterialProductsGrid(int? supplierID) { using (var um = new UserManager()) { var currentUser = um.ByUsername(User.Identity.Name); if (currentUser.SupplierID != null) { supplierID = currentUser.SupplierID.GetValueOrDefault(); } } var model = new MaterialProductGridModel(); var materialToProductModels = new List<MaterialToProductModel>(); using (var mm = new MaterialsManager()) { var products = mm.ActiveProducts().ToList(); var materials = mm.BySupplier(supplierID.GetValueOrDefault()).ToList(); var materialToProducts = mm.ByManufacturerID(supplierID.GetValueOrDefault()).ToList(); model.Products = products.AsEnumerable(); model.Materials = materials.AsEnumerable(); // create the list based on our product and material list foreach (var material in materials) { foreach (var product in products) { materialToProductModels.Add(new MaterialToProductModel { IsActive = materialToProducts.Any(mp => mp.ProductID == product.ID && mp.MaterialID == material.ID), ProductID = product.ID, MaterialID = material.ID, ProductName = product.Name, MaterialName = material.Name, MaterialToProductID = materialToProducts.Any(mp => mp.ProductID == product.ID && mp.MaterialID == material.ID) ? materialToProducts.First(mp => mp.ProductID == product.ID && mp.MaterialID == material.ID).ID : 0 }); } } model.MaterialProducts = materialToProductModels.AsEnumerable(); } return View("MaterialProductsGrid", model); }
public ActionResult EditProduct(Product product) { using (var mm = new MaterialsManager()) { product = mm.EditProduct(product); } return RedirectToAction("Products"); }
public ActionResult EditProduct(int id) { using (var mm = new MaterialsManager()) { var product = mm.SingleProduct(id); ViewBag.Product = product; return View("EditProduct"); } }
public ActionResult Products(ProductHouseModel model) { List<ProductToLine> parts = new List<ProductToLine>(); // loop through to create a list and then save foreach (var part in model.ProductPartHouse.Where(m => m.IsActive)) { parts.Add(new ProductToLine { IsActive = true, ProductLineID = part.ProductLineID, ProductID = part.ProductID}); } // first delete all of the existing ones using (var mm = new MaterialsManager()) { mm.DeleteProductToProductLine(); mm.CreateProductToProductLine(parts); } return RedirectToAction("Index", "Home"); }
public ActionResult BySupplier(int id) { List<Pricing> prices; List<Material> materials; int supplierID = id; using (var um = new UserManager()) { // any user tied to a supplier can only see their supplier rates var currentUser = um.ByUsername(User.Identity.Name); if (currentUser.SupplierID != null) { supplierID = currentUser.SupplierID.GetValueOrDefault(); } } using (var mm = new MaterialsManager()) { materials = mm.BySupplier(supplierID).ToList(); } using (var pm = new PricingManager()) { prices = pm.BySupplier(supplierID).ToList(); } // populate the model List<PricingModel> model = new List<PricingModel>(); foreach (var mat in materials) { var m = new PricingModel(); if (prices.Any(p => p.MaterialID == mat.ID)) { var price = prices.FirstOrDefault(p => p.MaterialID == mat.ID); m.ID = price.ID; m.CompanyID = price.CompanyID; m.MaterialID = price.MaterialID; m.SupplierID = price.SupplierID; m.CreatedOn = price.CreatedOn; m.CreatedBy = price.CreatedBy; m.ModifiedBy = price.ModifiedBy; m.ModifiedOn = price.ModifiedOn; m.Price = price.Price; m.MaterialName = mat.Name; } else { m.ID = 0; m.MaterialID = mat.ID; m.SupplierID = supplierID; m.CreatedOn = DateTime.Now; m.CreatedBy = User.Identity.Name; m.ModifiedBy = User.Identity.Name; m.ModifiedOn = DateTime.Now; m.MaterialName = mat.Name; } model.Add(m); } return View("PricingList", model); }
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"); }
public ActionResult Options(int id) { List<Manufacturer> manufacturers; List<ProductLine> productLines; var model = new QuoteOptionsModel {QuoteID = id}; using (var mm = new ManufacturerManager()) { manufacturers = mm.All().ToList(); } using (var mm = new MaterialsManager()) { productLines = mm.ActiveProductLines().ToList(); } model.ManufacturerSelectionModels = manufacturers.Select(manufacturer => new ManufacturerSelectionModel { IsSelected = false, ManufacturerID = manufacturer.ID, ManufacturerName = manufacturer.Name }).ToList(); model.ProductLineSelectionModels = productLines.Select(productLine => new ProductLineSelectionModel { IsSelected = false, ProductLineID = productLine.ID, ProductLineName = productLine.Name }).ToList(); return View("Options", model); }
public ActionResult SupplierMaterials(int supplierID) { List<Material> materials; using (var mm = new MaterialsManager()) { materials = mm.BySupplier(supplierID).ToList(); } ViewBag.Materials = materials; return View("MaterialList"); }
public ActionResult EditMaterial(int id) { using (var mm = new MaterialsManager()) { var material = mm.SingleMaterial(id); var model = new MaterialModel(material); return View("EditMaterial", model); } }
public ActionResult EditMaterial(MaterialModel model) { using (var mm = new MaterialsManager()) { // TODO: Refactor into an extention method that uses generics var material = new Material { Name = model.Name, SubName = model.SubName, Measurement = model.Measurement, CreatedOn = model.CreatedOn, ModifiedOn = model.ModifiedOn, UnitCost = model.UnitCost, IsActive = model.IsActive, ManufacturerID = model.ManufacturerID, Height = model.Height, Width = model.Width, Thickness = model.Thickness, Texture = model.Texture, Finish = model.Finish, Overlap = model.Overlap, SKU = model.SKU, ID = model.ID }; material = mm.EditMaterial(material); } return RedirectToAction("Materials"); }
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); }