public async Task EditAsync(EditAddressViewModel viewModel) { var address = await _addresses.FirstAsync(a => a.Id == viewModel.Id); _mappingEngine.Map(viewModel, address); }
public void FillEditViewModel(EditAddressViewModel viewModel, string path) { viewModel.States = _stateService.GetAsSelectListItemAsync(viewModel.State, path); viewModel.Cities = _cityService.GetAsSelectListByStateNameAsync(viewModel.State, viewModel.City, path); }
public virtual async Task<ActionResult> Edit(EditAddressViewModel viewModel) { if (!_referentialTeacherService.CanManageTeacher(viewModel.TeacherId)) return HttpNotFound(); if (!await _addressService.IsInDb(viewModel.Id)) this.AddErrors("Location", "آدرس مورد نظر توسط یکی از کاربران در شبکه،حذف شده است"); if (!ModelState.IsValid) { _addressService.FillEditViewModel(viewModel, IranCitiesPath); return new JsonNetResult { Data = new { success = false, View = this.RenderPartialViewToString(MVC.Address.Views._Edit, viewModel) } }; } await _addressService.EditAsync(viewModel); var message = await _unitOfWork.ConcurrencySaveChangesAsync(); if (message.HasValue()) this.AddErrors("Location", string.Format(message, "آدرس")); if (ModelState.IsValid) { var address = await _addressService.GetAddressViewModel(viewModel.Id); return new JsonNetResult { Data = new { success = true, View = this.RenderPartialViewToString(MVC.Address.Views._AddressItem, address) } }; } _addressService.FillEditViewModel(viewModel, IranCitiesPath); return new JsonNetResult { Data = new { success = false, View = this.RenderPartialViewToString(MVC.Address.Views._Edit, viewModel) } }; }
public virtual async Task<ActionResult> Edit(EditAddressViewModel viewModel) { if (!ModelState.IsValid) { _addressService.FillEditViewModel(viewModel, IranCitiesPath); return new JsonNetResult { Data = new { success = false, View = this.RenderPartialViewToString(MVC.Address.Views._Edit, viewModel) } }; } await _addressService.EditAsync(viewModel); await _unitOfWork.SaveAllChangesAsync(auditUserId: _userManager.GetCurrentUserId()); if (ModelState.IsValid) { var address = await _addressService.GetAddressViewModel(viewModel.Id); return new JsonNetResult { Data = new { success = true, View = this.RenderPartialViewToString(MVC.Address.Views._AddressItem, address) } }; } _addressService.FillEditViewModel(viewModel, IranCitiesPath); return new JsonNetResult { Data = new { success = false, View = this.RenderPartialViewToString(MVC.Address.Views._Edit, viewModel) } }; }
public async Task EditAsync(EditAddressViewModel viewModel) { var address = await _addresses.FirstAsync(a => a.Id == viewModel.Id); _mappingEngine.Map(viewModel, address); address.LasModifierId = _userManager.GetCurrentUserId(); }