public async Task <IActionResult> Edit(HP_VideoViewModel ViewModel) { var user = await _userManager.GetUserAsync(HttpContext.User); if (ModelState.IsValid) { var vdv = _hP_VideoVersionRepository.GetByVideoId(ViewModel.Id); var videoVersions = ViewModel.MapToVideoVersionModel(); //if hP_VideoVersion wasn't exist or HP_VideoViewModel approved or ignored then create new version if (vdv == null || ViewModel.VersionStatusEnum == VersionStatusEnum.Approved || ViewModel.VersionStatusEnum == VersionStatusEnum.Ignored) { videoVersions.CreatedById = user.Id; videoVersions.CreationDate = DateTime.Now; videoVersions.VersionStatusEnum = VersionStatusEnum.Draft; videoVersions.ChangeActionEnum = ChangeActionEnum.Update; videoVersions.Id = 0; videoVersions.HomePageVideoId = ViewModel.Id; _hP_VideoVersionRepository.Add(videoVersions); _toastNotification.AddSuccessToastMessage(ToasrMessages.EditSuccess); _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Update, "Home Page > Video > Edit", ViewModel.VideoUrl); return(RedirectToAction(nameof(Index))); } videoVersions.CreationDate = DateTime.Now; videoVersions.Id = vdv.Id; videoVersions.VersionStatusEnum = VersionStatusEnum.Draft; videoVersions.ChangeActionEnum = ChangeActionEnum.Update; videoVersions.ApprovalDate = vdv.ApprovalDate; videoVersions.ApprovedById = vdv.ApprovedById; videoVersions.CreatedById = vdv.CreatedById; videoVersions.CreationDate = vdv.CreationDate; videoVersions.ModificationDate = vdv.ModificationDate; videoVersions.ModifiedById = vdv.ModifiedById; videoVersions.HomePageVideoId = vdv.HomePageVideoId; var update = _hP_VideoVersionRepository.Update(videoVersions); if (update) { _toastNotification.AddSuccessToastMessage(ToasrMessages.EditSuccess); _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Update, "Home Page > Video > Edit", ViewModel.VideoUrl); return(RedirectToAction(nameof(Index))); } else { _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Warning, "Home Page > Video > Edit", ViewModel.VideoUrl); _toastNotification.AddErrorToastMessage(ToasrMessages.warning); return(View(ViewModel)); } } return(View(ViewModel)); }
public static HomePageVideoVersions MapToVideoVersionModel(this HP_VideoViewModel pgMinisty) { HomePageVideoVersions viewModel = new HomePageVideoVersions() { Id = pgMinisty.VideoId ?? pgMinisty.Id, IsActive = pgMinisty.IsActive, IsDeleted = pgMinisty.IsDeleted, VersionStatusEnum = pgMinisty.VersionStatusEnum, ChangeActionEnum = pgMinisty.ChangeActionEnum, CreationDate = pgMinisty.CreationDate, ModificationDate = pgMinisty.ModificationDate, ModifiedById = pgMinisty.ModifiedById, ApprovalDate = pgMinisty.ApprovalDate, ApprovedById = pgMinisty.ApprovedById, CreatedById = pgMinisty.CreatedById, VideoUrl = pgMinisty.VideoUrl, HomePageVideoId = pgMinisty.VideoId }; return(viewModel); }