public async Task <IActionResult> Create(CityPlanEditViewModel cityPlanVM) { if (ModelState.IsValid) { await EditMethod(cityPlanVM); return(RedirectToAction(nameof(Index))); } return(View(cityPlanVM)); }
/// <summary> /// Core method for create or edit a city plan object /// </summary> /// <param name="viewModel">city plan view model</param> /// <returns></returns> private async Task <IActionResult> EditMethod(CityPlanEditViewModel viewModel) { var pageRouteVersion = _pageRouteVersionRepository.GetPageRouteVersionByPageType(PageTypeConsts.CityPlan); if (ModelState.IsValid) { var cityPlanVersionByCityPlanId = _cityPlanVersionRepository.GetByCityId(viewModel.CityPlanId ?? 0); var cityPlanVersionById = _cityPlanVersionRepository.GetDetail(viewModel.Id); cityPlanVersionByCityPlanId = cityPlanVersionById == null ? cityPlanVersionByCityPlanId : cityPlanVersionById; var cityPlanVersionModel = viewModel.MapToCityPlanVersion(); var user = await _userManager.GetUserAsync(HttpContext.User); if (cityPlanVersionByCityPlanId == null || cityPlanVersionModel.VersionStatusEnum == VersionStatusEnum.Approved || cityPlanVersionModel.VersionStatusEnum == VersionStatusEnum.Ignored) { cityPlanVersionModel.CreatedById = user.Id; cityPlanVersionModel.CreationDate = DateTime.Now; cityPlanVersionModel.VersionStatusEnum = VersionStatusEnum.Draft; cityPlanVersionModel.ChangeActionEnum = ChangeActionEnum.Update; cityPlanVersionModel.Id = 0; cityPlanVersionModel.CityPlanId = viewModel.CityPlanId > 0 ? viewModel.CityPlanId : (int?)null; pageRouteVersion.ContentVersionStatusEnum = VersionStatusEnum.Draft; _cityPlanVersionRepository.Add(cityPlanVersionModel); _pageRouteVersionRepository.Update(pageRouteVersion); _toastNotification.AddSuccessToastMessage(ToasrMessages.EditSuccess); return(RedirectToAction(nameof(Index))); } cityPlanVersionModel.Id = cityPlanVersionByCityPlanId != null ? cityPlanVersionByCityPlanId.Id : viewModel.Id; pageRouteVersion.ContentVersionStatusEnum = VersionStatusEnum.Draft; _cityPlanVersionRepository.Update(cityPlanVersionModel); _pageRouteVersionRepository.Update(pageRouteVersion); return(RedirectToAction(nameof(Index))); } return(View(viewModel)); }
public async Task <IActionResult> Edit(CityPlanEditViewModel viewModel) { return(await EditMethod(viewModel)); }
public static CityPlanEditViewModel MapToCityPlanViewModel(this CityPlan cityPlan) { var ctPlan = new CityPlanEditViewModel() { Id = 0, ModificationDate = cityPlan.ModificationDate, VersionStatusEnum = VersionStatusEnum.Draft, IsDeleted = cityPlan.IsDeleted, ChangeActionEnum = ChangeActionEnum.New, CityPlanId = cityPlan.Id, ModifiedById = cityPlan.ModifiedById, CreationDate = cityPlan.CreationDate, CreatedById = cityPlan.CreatedById, ApprovalDate = cityPlan.ApprovalDate, ApprovedById = cityPlan.ApprovedById, IsActive = cityPlan.IsActive, EnPageDescription = cityPlan.EnPageDescription, ArPageDescription = cityPlan.ArPageDescription, EnAlexandria = cityPlan.EnAlexandria, ArAlexandria = cityPlan.ArAlexandria, EnAswan = cityPlan.EnAswan, ArAswan = cityPlan.ArAswan, EnAsyut = cityPlan.EnAsyut, ArAsyut = cityPlan.ArAsyut, EnBeheira = cityPlan.EnBeheira, ArBeheira = cityPlan.ArBeheira, EnBeniSuef = cityPlan.EnBeniSuef, ArBeniSuef = cityPlan.ArBeniSuef, EnCairo = cityPlan.EnCairo, ArCairo = cityPlan.ArCairo, EnDakahlia = cityPlan.EnDakahlia, ArDakahlia = cityPlan.ArDakahlia, EnDamietta = cityPlan.EnDamietta, ArDamietta = cityPlan.ArDamietta, EnFaiyum = cityPlan.EnFaiyum, ArFaiyum = cityPlan.ArFaiyum, EnGharbia = cityPlan.EnGharbia, ArGharbia = cityPlan.ArGharbia, EnGiza = cityPlan.EnGiza, ArGiza = cityPlan.ArGiza, EnIsmailia = cityPlan.EnIsmailia, ArIsmailia = cityPlan.ArIsmailia, EnKafrElSheikh = cityPlan.EnKafrElSheikh, ArKafrElSheikh = cityPlan.ArKafrElSheikh, EnLuxor = cityPlan.EnLuxor, ArLuxor = cityPlan.ArLuxor, EnMatruh = cityPlan.EnMatruh, ArMatruh = cityPlan.ArMatruh, EnMinya = cityPlan.EnMinya, ArMinya = cityPlan.ArMinya, EnMonufia = cityPlan.EnMonufia, ArMonufia = cityPlan.ArMonufia, EnNewValley = cityPlan.EnNewValley, ArNewValley = cityPlan.ArNewValley, EnNorthSinai = cityPlan.EnNorthSinai, ArNorthSinai = cityPlan.ArNorthSinai, EnPortSaid = cityPlan.EnPortSaid, ArPortSaid = cityPlan.ArPortSaid, EnQalyubia = cityPlan.EnQalyubia, ArQalyubia = cityPlan.ArQalyubia, EnQena = cityPlan.EnQena, ArQena = cityPlan.ArQena, EnRedSea = cityPlan.EnRedSea, ArRedSea = cityPlan.ArRedSea, EnSharqia = cityPlan.EnSharqia, ArSharqia = cityPlan.ArSharqia, EnSohag = cityPlan.EnSohag, ArSohag = cityPlan.ArSohag, EnSouthSinai = cityPlan.EnSouthSinai, ArSouthSinai = cityPlan.ArSouthSinai, EnSuez = cityPlan.EnSuez, ArSuez = cityPlan.ArSuez, }; return(ctPlan); }