public Task FillEditViewMode(EditTrainingCenterViewModel viewModel, string path)
 {
     viewModel.States = _stateService.GetAsSelectListItemAsync(viewModel.State, path);
     viewModel.Cities =
          _cityService.GetAsSelectListByStateNameAsync(viewModel.State, viewModel.City, path);
     return Task.FromResult(0);
 }
 public async Task EditAsync(EditTrainingCenterViewModel viewModel)
 {
     var trainingCenter = await _trainingCenters.FirstAsync(a => a.Id == viewModel.Id);
     _mappingEngine.Map(viewModel, trainingCenter);
     trainingCenter.LasModifierId = _userManager.GetCurrentUserId();
 }
        public virtual async Task<ActionResult> Edit(EditTrainingCenterViewModel viewModel)
        {
            if (await _trainingCenterService.IsNameExistAsync(viewModel.CenterName, viewModel.Id, viewModel.City))
                this.AddErrors("CenterName", "یک مرکز کارآموزی با این نام در این شهر قبلا ثبت شده است");
            if (!await _trainingCenterService.IsInDb(viewModel.Id))
                this.AddErrors("CenterName", "مرکز کارآموزی مورد نظر توسط یکی از کاربران در شبکه،حذف شده است");

            if (!ModelState.IsValid)
            {
                await _trainingCenterService.FillEditViewMode(viewModel, IranCitiesPath);
                return new JsonNetResult
                {
                    Data = new
                    {
                        success = false,
                        View = this.RenderPartialViewToString(MVC.TrainingCenter.Views._Edit, viewModel)
                    }
                };
            }

            await _trainingCenterService.EditAsync(viewModel);
            var message = await _unitOfWork.ConcurrencySaveChangesAsync();
            if (message.HasValue()) this.AddErrors("CenterName", string.Format(message, "مرکز کارآموزی"));

            if (ModelState.IsValid)
            {
                var center = await _trainingCenterService.GetCenterViewModel(viewModel.Id);
                return new JsonNetResult
                {
                    Data = new
                    {
                        success = true,
                        View = this.RenderPartialViewToString(MVC.TrainingCenter.Views._TrainingCenterItem, center)
                    }
                };
            }
            await _trainingCenterService.FillEditViewMode(viewModel, IranCitiesPath);
            return new JsonNetResult
            {
                Data = new
                {
                    success = false,
                    View = this.RenderPartialViewToString(MVC.TrainingCenter.Views._Edit, viewModel)
                }
            };
        }