public ActionResult Edit(AdminEditProductClassViewModel model) { if (ModelState.IsValid) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { try { var productClass = _productSevice.GetProductClass(model.Id); if (productClass == null) { return(RedirectToAction("index")); } model.Image = productClass.Image; productClass.Name = model.Name; productClass.Image = model.Image; productClass.Description = model.Description; productClass.Colour = model.Colour; productClass.IsLocked = model.IsLocked; _productSevice.Update(productClass); _productSevice.DelAllAttributeForProductClass(productClass.Id); 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 cập nhật nhóm sản phẩm", MessageType = GenericMessages.success }; } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex.Message); ModelState.AddModelError("", "Lỗi khi thêm nhóm sản phẩm"); } } } if (model.AllAttribute != null) { foreach (var it in model.AllAttribute) { it.Name = _productSevice.GetAttribute(it.Id).LangName; } } return(View(model)); }