public ActionResult AddRecyclability(int cid)
 {
     ViewBag.Regions = _regionRepository.GetAll().ToList();
     var locatedIn = new LocatedIn
     {
         Constituent = _constituentRepository.GetById(cid)
     };
     return View(locatedIn);
 }
 public ActionResult AddRecyclability(LocatedIn locatedIn)
 {
     var constituent = _constituentRepository.GetById(locatedIn.Constituent.Id);
     var region = _regionRepository.GetById(locatedIn.Region.Id);
     locatedIn.Region = region;
     locatedIn.Constituent = constituent;
     _locatedInRepository.SaveOrUpdate(locatedIn);
     return RedirectToAction("Edit", new { id = locatedIn.Constituent.Id });
 }
Пример #3
0
        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 EditRecyclability(LocatedIn locatedIn)
 {
     using (var uow = _unitOfWorkFactory.UnitOfWork)
     {
         _locatedInRepository.SaveOrUpdate(locatedIn);
         uow.SaveChanges();
         return RedirectToAction("Edit", new { id = locatedIn.Constituent.Id });
     }
 }