public ActionResult Create(SpecificationsListViewModel spec) { var specViewModelList = new List <SpecificationsViewModel>(); var specsList = specsHandler.GetSpecs(spec.CategoryId); var catSpecsList = specsHandler.GetCatSpecs(spec.CategoryId); foreach (var s in specsList) { specViewModelList.Add(new SpecificationsViewModel { Name = s.Name, SpecId = s.SpecId, CatSpecId = catSpecsList .Where(x => x.SpecId == s.SpecId & x.CategoryId == spec.CategoryId) .Select(x => x.CategorySpecsId) .First(), Value = s.Value }); } var specs = new SpecificationsListViewModel() { ProductId = spec.ProductId, Specifications = specViewModelList, CategoryId = spec.CategoryId }; return(View(specs)); }
public ActionResult CreateSpec(SpecificationsListViewModel specs) { if (ModelState.IsValid) { var prod_CatSpedList = new List <Prod_CatSpecModel>(); foreach (var s in specs.Specifications) { prod_CatSpedList.Add(new Prod_CatSpecModel { ProductId = specs.ProductId, SpecValue = s.Value, CategorySpecId = s.CatSpecId }); } specsHandler.Create(prod_CatSpedList); return(RedirectToAction("Index", "Product")); } return(View(specs)); }