public static EgyptVisionVersion MapToEgyptVisionVersionModel(this EgyptVisionVersionEditViewModel pgMinisty) { EgyptVisionVersion viewModel = new EgyptVisionVersion() { Id = pgMinisty.EgyptVisionId ?? pgMinisty.Id, EnEgyptVisionName = pgMinisty.EnEgyptVisionName, ArEgyptVisionName = pgMinisty.ArEgyptVisionName, EnEgyptVisionSmallDesc = pgMinisty.EnEgyptVisionSmallDesc, ArEgyptVisionSmallDesc = pgMinisty.ArEgyptVisionSmallDesc, EnEgyptVisionDesc = pgMinisty.EnEgyptVisionDesc, ArEgyptVisionDesc = pgMinisty.ArEgyptVisionDesc, IsActive = pgMinisty.IsActive, IsDeleted = pgMinisty.IsDeleted, EnImagePath = pgMinisty.EnImagePath, ArImagePath = pgMinisty.ArImagePath, SeoTitleEN = pgMinisty.SeoTitleEN, SeoTitleAR = pgMinisty.SeoTitleAR, SeoDescriptionEN = pgMinisty.SeoDescriptionEN, SeoDescriptionAR = pgMinisty.SeoDescriptionAR, SeoOgTitleEN = pgMinisty.SeoOgTitleEN, SeoOgTitleAR = pgMinisty.SeoOgTitleAR, SeoTwitterCardEN = pgMinisty.SeoTwitterCardEN, SeoTwitterCardAR = pgMinisty.SeoTwitterCardAR, BgColor = pgMinisty.BgColor, LineColor = pgMinisty.LineColor, Order = pgMinisty.Order, ImagePositionIsRight = pgMinisty.ImagePositionIsRight, VersionStatusEnum = pgMinisty.VersionStatusEnum, ChangeActionEnum = pgMinisty.ChangeActionEnum, EgyptVisionId = pgMinisty.EgyptVisionId, StatusId = pgMinisty.StatusId, ApprovalDate = pgMinisty.ApprovalDate, ApprovedById = pgMinisty.ApprovedById, CreatedById = pgMinisty.CreatedById, ModificationDate = pgMinisty.ModificationDate, CreationDate = pgMinisty.CreationDate, ModifiedById = pgMinisty.ModifiedById, PageRouteVersionId = pgMinisty.PageRouteVersionId }; return(viewModel); }
public async Task <IActionResult> Edit(EgyptVisionVersionEditViewModel ViewModel) { var pageRouteVer = _pageRouteVersionRepository.Get(ViewModel.PageRouteVersionId); ViewModel.EnEgyptVisionDesc.ValidateHtml("EnEgyptVisionDesc", ModelState); ViewModel.ArEgyptVisionDesc.ValidateHtml("ArEgyptVisionDesc", ModelState); var user = await _userManager.GetUserAsync(HttpContext.User); if (ModelState.IsValid) { var evv = _egyptVisionVersionRepository.GetByEgyptVisionId(ViewModel.Id); var egyptVisionVersion = ViewModel.MapToEgyptVisionVersionModel(); if (evv == null || ViewModel.VersionStatusEnum == VersionStatusEnum.Approved || ViewModel.VersionStatusEnum == VersionStatusEnum.Ignored) { egyptVisionVersion.CreatedById = user.Id; egyptVisionVersion.CreationDate = DateTime.Now; egyptVisionVersion.VersionStatusEnum = VersionStatusEnum.Draft; pageRouteVer.ContentVersionStatusEnum = VersionStatusEnum.Draft; egyptVisionVersion.ChangeActionEnum = ChangeActionEnum.Update; egyptVisionVersion.Id = 0; egyptVisionVersion.EgyptVisionId = ViewModel.Id; if (ViewModel.EnImageFile != null) { egyptVisionVersion.EnImagePath = _fileService.UploadImageUrlNew(ViewModel.EnImageFile); } if (ViewModel.ArImageFile != null) { egyptVisionVersion.ArImagePath = _fileService.UploadImageUrlNew(ViewModel.ArImageFile); } _egyptVisionVersionRepository.Add(egyptVisionVersion); _pageRouteVersionRepository.Update(pageRouteVer); _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Update, "Static Page > Page Egypt Vision > Edit", ViewModel.EnEgyptVisionName); return(RedirectToAction(nameof(Index), new { id = pageRouteVer.Id })); } if (ViewModel.EnImageFile != null) { egyptVisionVersion.EnImagePath = _fileService.UploadImageUrlNew(ViewModel.EnImageFile); } if (ViewModel.ArImageFile != null) { egyptVisionVersion.ArImagePath = _fileService.UploadImageUrlNew(ViewModel.ArImageFile); } egyptVisionVersion.CreationDate = DateTime.Now; egyptVisionVersion.Id = evv.Id; egyptVisionVersion.VersionStatusEnum = VersionStatusEnum.Draft; pageRouteVer.ContentVersionStatusEnum = VersionStatusEnum.Draft; egyptVisionVersion.ChangeActionEnum = ChangeActionEnum.Update; egyptVisionVersion.ApprovalDate = evv.ApprovalDate; egyptVisionVersion.ApprovedById = evv.ApprovedById; egyptVisionVersion.CreatedById = evv.CreatedById; egyptVisionVersion.CreationDate = evv.CreationDate; egyptVisionVersion.ModificationDate = evv.ModificationDate; egyptVisionVersion.ModifiedById = evv.ModifiedById; egyptVisionVersion.StatusId = evv.StatusId; egyptVisionVersion.EgyptVisionId = evv.EgyptVisionId; _pageRouteVersionRepository.Update(pageRouteVer); var update = _egyptVisionVersionRepository.Update(egyptVisionVersion); if (update) { _toastNotification.AddSuccessToastMessage(ToasrMessages.EditSuccess); _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Update, "Static Page > Page Egypt Vision > Edit", ViewModel.EnEgyptVisionName); return(RedirectToAction(nameof(Index), new { id = pageRouteVer.Id })); } else { _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Warning, "Static Page > Page Egypt Vision > Warning in Edit", ViewModel.EnEgyptVisionName); _toastNotification.AddErrorToastMessage(ToasrMessages.warning); return(View(ViewModel)); } } return(View(ViewModel)); }