public ActionResult SuaNhaXe(NhaXeModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.QLNhaXe)) { return(AccessDeniedView()); } var nhaxe = _nhaxeService.GetNhaXeById(model.Id); if (nhaxe == null || nhaxe.isDelete) { //No manufacturer found with the specified id return(RedirectToAction("ListNhaXe")); } if (ModelState.IsValid) { int prevLogoID = nhaxe.LogoID; int prevAnhDaiDienID = nhaxe.AnhDaiDienID; //diachi.Id = nhaxe.DiaChiID; nhaxe = model.ToEntity(nhaxe); _nhaxeService.UpdateNhaXe(nhaxe); var diachi = _diachiService.GetById(nhaxe.DiaChiID); diachi = model.ThongTinDiaChi.ToEntity(diachi); diachi.Id = nhaxe.DiaChiID; _diachiService.Update(diachi); //delete an old picture (if deleted or updated) if (prevLogoID > 0 && prevLogoID != nhaxe.LogoID) { var prevPicture = _pictureService.GetPictureById(prevLogoID); if (prevPicture != null) { _pictureService.DeletePicture(prevPicture); } } if (prevAnhDaiDienID > 0 && prevAnhDaiDienID != nhaxe.AnhDaiDienID) { var prevPicture = _pictureService.GetPictureById(prevAnhDaiDienID); if (prevPicture != null) { _pictureService.DeletePicture(prevPicture); } } if (continueEditing) { //selected tab SaveSelectedTabIndex(); return(RedirectToAction("SuaNhaXe", nhaxe.Id)); } return(RedirectToAction("ListNhaXe")); } return(View(model)); }