public ActionResult Create(AdminEditProductClassViewModel model) { if (ModelState.IsValid) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { try { var productClass = new ProductClass { Name = model.Name, Image = model.Image, Description = model.Description, Colour = model.Colour, IsLocked = model.IsLocked }; _productSevice.Add(productClass); if (model.AllAttribute != null) { foreach (var it in model.AllAttribute) { if (it.IsCheck) { var a = new ProductClassAttribute { ProductAttributeId = it.Id, ProductClassId = productClass.Id, IsShow = it.IsShow, }; _productSevice.Add(a); } } } unitOfWork.Commit(); TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel { Message = "Thành công thêm nhóm sản phẩm", MessageType = GenericMessages.success }; return(RedirectToAction("Index")); } catch { unitOfWork.Rollback(); ModelState.AddModelError("", "Lỗi khi thêm nhóm sản phẩm"); } } } foreach (var it in model.AllAttribute) { it.Name = _productSevice.GetAttribute(it.Id).LangName; } return(View(model)); }