public ActionResult Create(Constituent constituent)
        {
            if (ModelState.IsValid)
            {
                using (var uow = _unitOfWorkFactory.UnitOfWork)
                {
                    _constituentRepository.SaveOrUpdate(constituent);
                    uow.SaveChanges();
                    return RedirectToAction("Index");
                }
            }

            return View(constituent);
        }
        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 Edit(Constituent constituent)
 {
     if (ModelState.IsValid)
     {
         var constituentdb = _constituentRepository.GetById(constituent.Id);
         AutoMapper.Mapper.Map<Constituent, Constituent>(constituent, constituentdb);
         _constituentRepository.SaveOrUpdate(constituentdb);
         return RedirectToAction("Details", new { id = constituentdb.Id });
     }
     return View(constituent);
 }