public ActionResult Edit(Product product) { ViewBag.CategoryId = new SelectList(_category.GetAll(), "Id", "Name"); ViewBag.TypeAttribute = _typeAttribute.GetAll().AsQueryable().Include(x => x.Attributes).AsEnumerable(); if (ModelState.IsValid) { var user = Session["User"] as User; if (product.ProductAttributes != null) { foreach (var item in product.ProductAttributes) { item.ProductId = product.Id; } if (!_productAttribute.DeleteRange(_productAttribute.Get(x => x.ProductId == product.Id))) { TempData["UpdateFalse"] = "Update False!"; return(View(product)); } if (!_productAttribute.CreateRange(product.ProductAttributes)) { TempData["UpdateFalse"] = "Update False!"; return(View(product)); } } product.UpdateAt = DateTime.Now; product.UpdateBy = user.Email; product.CreateBy = user.Id; if (_product.Update(product)) { TempData["UpdateSuccess"] = "Update Success"; return(RedirectToAction("Index")); } else { TempData["UpdateFalse"] = "Update False!!"; return(View(product)); } } return(View(product)); }