Пример #1
0
 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);
 }
Пример #2
0
 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);
 }
Пример #3
0
 public Task<AddTrainingCenterViewModel> GetForCreate(string path)
 {
     var viewModel = new AddTrainingCenterViewModel
     {
         States = _stateService.GetAsSelectListItemAsync(null, path)
     };
     return Task.FromResult(viewModel);
 }
Пример #4
0
 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)
         }
     };
 }