public async Task <IActionResult> Create(HP_PhotoSliderViewModel viewModel) { viewModel.ArDescription.ValidateHtml("ArDescription", ModelState); viewModel.EnDescription.ValidateHtml("EnDescription", ModelState); if (ModelState.IsValid) { await EditMethod(viewModel); _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Add, "Home Page > Photos Slider > Add", viewModel.EnTitle); return(RedirectToAction(nameof(Index))); } return(View(viewModel)); }
/// <summary> /// edit HP_PhotoSlider /// </summary> /// <param name="viewModel"></param> /// <returns></returns> private async Task <IActionResult> EditMethod(HP_PhotoSliderViewModel viewModel) { viewModel.ArDescription.ValidateHtml("ArDescription", ModelState); viewModel.EnDescription.ValidateHtml("EnDescription", ModelState); ModelState.Remove(nameof(viewModel.ImageFile)); ModelState.Remove(nameof(viewModel.HomePagePhotoSliderId)); if (ModelState.IsValid) { var sliderVersionBySliderId = _hP_PhotoSliderVersionReopsitory.GetBySliderId(viewModel.HomePagePhotoSliderId ?? 0); var sliderVersionById = _hP_PhotoSliderVersionReopsitory.GetById(viewModel.Id); sliderVersionBySliderId = sliderVersionById == null ? sliderVersionBySliderId : sliderVersionById; var sliderVersionModel = viewModel.MapToPhotoSliderVersionModel(); var user = await _userManager.GetUserAsync(HttpContext.User); //if hP_PhotoSliderVersion wasn't exist or HP_PhotoSliderViewModel approved or ignored then create new version if (sliderVersionBySliderId == null || sliderVersionModel.VersionStatusEnum == VersionStatusEnum.Approved || sliderVersionModel.VersionStatusEnum == VersionStatusEnum.Ignored) { sliderVersionModel.CreatedById = user.Id; sliderVersionModel.CreationDate = DateTime.Now; sliderVersionModel.VersionStatusEnum = VersionStatusEnum.Draft; sliderVersionModel.ChangeActionEnum = ChangeActionEnum.Update; sliderVersionModel.Id = 0; sliderVersionModel.HomePagePhotoSliderId = viewModel.HomePagePhotoSliderId > 0 ? viewModel.HomePagePhotoSliderId : (int?)null; if (viewModel.ImageFile != null) { sliderVersionModel.ImageUrl = _fileService.UploadImageUrlNew(viewModel.ImageFile); } _hP_PhotoSliderVersionReopsitory.Add(sliderVersionModel); _toastNotification.AddSuccessToastMessage(ToasrMessages.EditSuccess); _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Update, "Home Page > Photos Slider > Update", viewModel.EnTitle); return(RedirectToAction(nameof(Index))); } sliderVersionModel.Id = sliderVersionBySliderId != null ? sliderVersionBySliderId.Id : viewModel.Id; if (viewModel.ImageFile != null) { sliderVersionModel.ImageUrl = _fileService.UploadImageUrlNew(viewModel.ImageFile); } _hP_PhotoSliderVersionReopsitory.Update(sliderVersionModel); _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Update, "Home Page > Photos Slider > Update", viewModel.EnTitle); return(RedirectToAction(nameof(Index))); } return(View(viewModel)); }
public static HomePagePhotoSlider MapToPhotoSliderModel(this HP_PhotoSliderViewModel viewModel) { return(new HomePagePhotoSlider() { Id = viewModel.Id, ArDescription = viewModel.ArDescription, EnDescription = viewModel.EnDescription, ImageUrl = viewModel.ImageUrl, IsActive = viewModel.IsActive, IsDeleted = viewModel.IsDeleted, Url = viewModel.Url, ArTitle = viewModel.ArTitle, EnTitle = viewModel.EnTitle }); }
public static HomePagePhotoSliderVersion MapToPhotoSliderVersionModel(this HP_PhotoSliderViewModel viewModel) { return(new HomePagePhotoSliderVersion() { Id = viewModel.Id, ArDescription = viewModel.ArDescription, EnDescription = viewModel.EnDescription, ImageUrl = viewModel.ImageUrl, IsActive = viewModel.IsActive, IsDeleted = viewModel.IsDeleted, Url = viewModel.Url, ArTitle = viewModel.ArTitle, EnTitle = viewModel.EnTitle, CreatedById = viewModel.CreatedById, ModificationDate = viewModel.ModificationDate, VersionStatusEnum = viewModel.VersionStatusEnum, ModifiedById = viewModel.ModifiedById, ApprovedById = viewModel.ApprovedById, ChangeActionEnum = viewModel.ChangeActionEnum, HomePagePhotoSliderId = viewModel.HomePagePhotoSliderId, ApprovalDate = viewModel.ApprovalDate, CreationDate = viewModel.CreationDate, }); }
public async Task <IActionResult> Edit(HP_PhotoSliderViewModel viewModel) { return(await EditMethod(viewModel)); }