protected static void ImportModelState(ActionExecutedContext filterContext) { if (!(filterContext.Controller is Controller controller) || filterContext.ModelState == null || !controller.TempData.ContainsKey(Key)) { return; } var jsonValue = controller.TempData[Key] as string; var modelState = ModelStateExtensions.DeserializeModelState(jsonValue); filterContext.ModelState.Merge(modelState); }
public BsJsonResult New(BsToolbarModel <UserSearchModel, UserNewModel> model) { var msg = string.Empty; var status = BsResponseStatus.Success; long?userId = null; var row = string.Empty; ClearModelStateOnAdd(ModelState, model.New); if (ModelState.IsValid) { var userDomainModel = new UserModel(); var userProfileDomainModel = new UserProfileModel(); var addressDomainModel = new AddressModel(); var newModel = model.New; newModel.ToUserProfileDomainModel(userProfileDomainModel); newModel.ToAddressDomainModel(addressDomainModel); newModel.ToUserDomainModel(userDomainModel); userId = _userService.Create(userDomainModel, userProfileDomainModel, addressDomainModel); var rowModel = _usersRepository.ReadRow(userId); var viewModel = _usersRepository.ToBsGridViewModel(rowModel).Wrap <UsersPageModel>(x => x.Grid); row = this.BsRenderPartialView("Grid/_Grid", viewModel); msg = Resource.SaveSuccess; } else { return(new BsJsonResult( new Dictionary <string, object> { { "Errors", ModelStateExtensions.GetErrors(ModelState) } }, BsResponseStatus.ValidationError)); } return(new BsJsonResult(new { Message = msg, UserId = userId, Row = row }, status, msg)); }