public async Task<TrainingCenterViewModel> Create(AddTrainingCenterViewModel viewModel) { var trainingCenter = _mappingEngine.Map<TrainingCenter>(viewModel); trainingCenter.CreatorId = _userManager.GetCurrentUserId(); _trainingCenters.Add(trainingCenter); await _unitOfWork.SaveChangesAsync(); return await GetCenterViewModel(trainingCenter.Id); }
public Task FillAddViewMolde(AddTrainingCenterViewModel viewModel, string path) { viewModel.States = _stateService.GetAsSelectListItemAsync(viewModel.State, path); viewModel.Cities = _cityService.GetAsSelectListByStateNameAsync(viewModel.State, viewModel.City, path); return Task.FromResult(0); }
public Task<AddTrainingCenterViewModel> GetForCreate(string path) { var viewModel = new AddTrainingCenterViewModel { States = _stateService.GetAsSelectListItemAsync(null, path) }; return Task.FromResult(viewModel); }
public virtual async Task<ActionResult> Create(AddTrainingCenterViewModel viewModel) { if (await _trainingCenterService.IsNameExistAsync(viewModel.CenterName, null, viewModel.City)) this.AddErrors("CenterName", "یک موسسه کارآموزی با این نام در این شهر قبلا ثبت شده است"); if (!ModelState.IsValid) { await _trainingCenterService.FillAddViewMolde(viewModel, IranCitiesPath); return new JsonNetResult { Data = new { success = false, View = this.RenderPartialViewToString(MVC.TrainingCenter.Views._TrainingCenterItem, viewModel) } }; } var newCenter = await _trainingCenterService.Create(viewModel); return new JsonNetResult { Data = new { success = true, View = this.RenderPartialViewToString(MVC.TrainingCenter.Views._TrainingCenterItem, newCenter) } }; }