public ActionResult Edit(Guid id) { var cart = _shoppingCartService.Get(id); if (cart == null) { return(RedirectToAction("Index", "ShoppingCart")); } var viewModel = new ShoppingCartEditViewModel { Id = cart.Id, Name = cart.Name, Email = cart.Email, Phone = cart.Phone, Addren = cart.Addren, ShipName = cart.ShipName, ShipPhone = cart.ShipPhone, ShipAddren = cart.ShipAddren, ShipNote = cart.ShipNote, TotalMoney = cart.TotalMoney, Note = cart.Note, Status = cart.Status, CreateDate = cart.CreateDate, products = _shoppingCartProductService.GetList(cart), }; return(View(viewModel)); }
public ActionResult Edit(ShoppingCartEditViewModel viewModel) { var cart = _shoppingCartService.Get(viewModel.Id); if (cart == null) { return(RedirectToAction("Index", "ShoppingCart")); } viewModel.Id = cart.Id; viewModel.Name = cart.Name; viewModel.Email = cart.Email; viewModel.Phone = cart.Phone; viewModel.Addren = cart.Addren; viewModel.ShipName = cart.ShipName; viewModel.ShipPhone = cart.ShipPhone; viewModel.ShipAddren = cart.ShipAddren; viewModel.ShipNote = cart.ShipNote; viewModel.TotalMoney = cart.TotalMoney; viewModel.CreateDate = cart.CreateDate; if (ModelState.IsValid) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { try { var t = Request.Form; cart.Note = viewModel.Note; cart.Status = viewModel.Status; _shoppingCartService.Update(cart); unitOfWork.Commit(); // We use temp data because we are doing a redirect TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel { Message = "Cập nhật thành công", MessageType = GenericMessages.success }; } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex.Message); ModelState.AddModelError(string.Empty, LocalizationService.GetResourceString("Lỗi khi cập nhật!")); } } } viewModel.products = _shoppingCartProductService.GetList(cart); return(View(viewModel)); }