public ActionResult AddConstituent(int pid) { var constituents = _constituentRepository.GetAll().ToList(); ViewBag.Constituent = constituents.OrderBy(x => x.ConstituentName); var product = _productRepository.GetById(pid); var phasc = new ProductHasConstituent { Product = product }; return View(phasc); }
public ActionResult AddConstituent(ProductHasConstituent phasc) { if (phasc.PartWeight > 0) { var constituent = _constituentRepository.GetById(phasc.Constituent.Id); phasc.Constituent = constituent; var product = _productRepository.GetById(phasc.Product.Id); phasc.Product = product; _productHasConstituentRepository.SaveOrUpdate(phasc); return RedirectToAction("Edit", new { id = phasc.Product.Id }); } var constituents = _constituentRepository.GetAll().ToList(); ViewBag.Constituent = constituents.OrderBy(x => x.ConstituentName); return View(phasc); }
public ActionResult Create(ProductDTO productdto, FormCollection collection) { try { using (var uow = _unitOfWorkFactory.UnitOfWork) { productdto.product.Category = _categoryRepository.GetById(Int32.Parse(collection["CategoryId"])); HttpPostedFileBase file = Request.Files["ProductImage"]; // Verify that the user selected a file if (file != null && file.ContentLength > 0) { if (file.ContentType == "image/jpeg" || file.ContentType == "image/jpg" || file.ContentType == "image/png") { // extract only the fielname var fileExtension = Path.GetExtension(file.FileName); // store the file inside ~/App_Data/uploads folder var path = "pics/" + productdto.product.UPC + fileExtension; string dirPath = System.Web.HttpContext.Current.Server.MapPath("~/") + path; file.SaveAs(dirPath); productdto.product.ImagePath = path; } } productdto.product.LastUpdated = DateTime.Now; string[] cnames = collection["cform[cname][]"].Split(','); string[] cpweights = collection["cform[pweight][]"].Split(','); string[] cType = collection["cform[Type][]"].Split(','); string[] cclassifications = collection["cform[classification][]"].Split(','); for (int i = 0; i < cnames.Length; i++) { Constituent constituent = _constituentRepository.Query.Where(x => x.ConstituentName.Equals(cnames[i])).FirstOrDefault(); if (constituent == null) { constituent = new Constituent { ConstituentName = cnames[i] }; }; var newPhasC = new ProductHasConstituent { Product = productdto.product, PartWeight = Double.Parse(cpweights[i]), Constituent = constituent, }; var newLocatedIn = new LocatedIn { Constituent = constituent, Region = _regionRepository.Query.Where(x => x.RegionName == productdto.region.RegionName).FirstOrDefault(), Classification = cclassifications[i], }; _productRepository.SaveOrUpdate(productdto.product); _constituentRepository.SaveOrUpdate(constituent); _productHasConstituentRepository.SaveOrUpdate(newPhasC); _locatedInRepository.SaveOrUpdate(newLocatedIn); } uow.SaveChanges(); return RedirectToAction("Index"); } } catch { return View(); } }
public ActionResult EditConstituent(ProductHasConstituent phasc) { using (var uow = _unitOfWorkFactory.UnitOfWork) { var phascDb = _productHasConstituentRepository.GetById(phasc.Id); phascDb.PartWeight = phasc.PartWeight; _productHasConstituentRepository.SaveOrUpdate(phascDb); uow.SaveChanges(); return RedirectToAction("Edit", new { id = phascDb.Product.Id }); } }