예제 #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)
         }
     };
 }