/// <summary> /// Update a page section object in database /// </summary> /// <param name="pageSectionVersion">page section version object</param> /// <returns></returns> public void NormalUpdate(PageSectionVersion pageSectionVersion) { try { _db.PageSectionVersions.Update(pageSectionVersion); _db.SaveChanges(); } catch (Exception er) { } }
/// <summary> /// Coping page section and its cards to page section versions which has the same page route version id /// </summary> /// <param name="pageRouteVersion">page route version object which i will take it's id to copy objects</param> /// <returns></returns> public void CopyPageSectionVersions(PageRouteVersion pageRouteVersion) { if (pageRouteVersion.PageRouteId != null && !pageRouteVersion.PageSectionVersions.Any()) { var pageSections = _db.PageSections.Include(d => d.PageSectionCards).Where(d => d.PageRouteId == pageRouteVersion.PageRouteId && !d.IsDeleted).ToList(); foreach (var section in pageSections) { var secVer = new PageSectionVersion { ArDescription = section.ArDescription, ArImageAlt = section.ArImageAlt, ArTitle = section.ArTitle, EnDescription = section.EnDescription, EnImageAlt = section.EnImageAlt, EnTitle = section.EnTitle, CreatedById = pageRouteVersion.CreatedById, CreationDate = DateTime.Now, IsActive = section.IsActive, IsDeleted = false, Order = section.Order, PageRouteVersionId = pageRouteVersion.Id, PageSectionId = section.Id, PageSectionTypeId = section.PageSectionTypeId, Url = section.Url }; foreach (var card in section.PageSectionCards.Where(d => !d.IsDeleted)) { secVer.PageSectionCardVersions.Add(new PageSectionCardVersion { ArDescription = card.ArDescription, ArImageAlt = card.ArImageAlt, ArTitle = card.ArTitle, CreatedById = pageRouteVersion.CreatedById, CreationDate = DateTime.Now, EnDescription = card.EnDescription, EnImageAlt = card.EnImageAlt, EnTitle = card.EnTitle, FileUrl = card.FileUrl, ImageUrl = card.ImageUrl, IsActive = card.IsActive, IsDeleted = false, Order = card.Order, PageSectionCardId = card.Id, PageSectionVersionId = secVer.Id }); } _db.PageSectionVersions.Add(secVer); } _db.SaveChanges(); } }
public IActionResult Edit(PageSectionEditViewModel sectionViewModel) { RemoveFieldsFromModelStateDependOnSectionType(ModelState, sectionViewModel.SectionTypeId.Value); sectionViewModel.Section.EnDescription.ValidateHtml("EnDescription", ModelState); sectionViewModel.Section.ArDescription.ValidateHtml("ArDescription", ModelState); if (ModelState.IsValid) { sectionViewModel = RemoveTagsFromDescription(sectionViewModel); PageSectionVersion pageSectionVersion = sectionViewModel.MapToPageSectionVersion(); string oldFilePath = null; var sectionType = _dynamicPageSectionRepository.GetPageSectionType(sectionViewModel.SectionTypeId.Value); if (sectionType.MediaType == SectionMediaType.Image.ToString() && sectionViewModel.Section.Photo != null) { oldFilePath = pageSectionVersion.Url; pageSectionVersion.Url = _fileService.UploadImageUrlNew(sectionViewModel.Section.Photo); } if (sectionType.MediaType == SectionMediaType.Video.ToString()) { pageSectionVersion.Url = sectionViewModel.Section.Url; } PageSectionVersion newPageSectionVersion = _dynamicPageSectionVersionRepository.Update(pageSectionVersion); if (newPageSectionVersion != null) { if (oldFilePath != null) { _fileService.RemoveImage(oldFilePath); } _toastNotification.AddSuccessToastMessage(ToasrMessages.EditSuccess); _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Update, "Dynamic Page > " + ViewBag.DynamicPageName + " > Sections > Edit", newPageSectionVersion.EnTitle); return(RedirectToAction("Index", new { pageRouteVersionId = newPageSectionVersion.PageRouteVersionId })); } _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Warning, "Dynamic Page > " + ViewBag.DynamicPageName + " > Sections > Warning in Edit", pageSectionVersion.EnTitle); _toastNotification.AddErrorToastMessage(ToasrMessages.warning); return(View(sectionViewModel)); } List <PageSectionType> sectionTypes = _dynamicPageSectionRepository.GetPageSectionTypes(); sectionViewModel.SectionTypes = sectionTypes; return(View(sectionViewModel)); }
public static PageSectionVersion MapToPageSectionVersion(this PageSectionCreateViewModel dynamicPageSectionViewModel) { PageSectionVersion pageSectionVersion = new PageSectionVersion(); pageSectionVersion.EnTitle = dynamicPageSectionViewModel.Section.EnTitle; pageSectionVersion.ArTitle = dynamicPageSectionViewModel.Section.ArTitle; pageSectionVersion.EnDescription = dynamicPageSectionViewModel.Section.EnDescription; pageSectionVersion.ArDescription = dynamicPageSectionViewModel.Section.ArDescription; pageSectionVersion.EnImageAlt = dynamicPageSectionViewModel.Section.EnImageAlt; pageSectionVersion.ArImageAlt = dynamicPageSectionViewModel.Section.ArImageAlt; pageSectionVersion.Url = dynamicPageSectionViewModel.Section.Url; pageSectionVersion.Order = dynamicPageSectionViewModel.Section.Order; pageSectionVersion.IsActive = dynamicPageSectionViewModel.Section.IsActive; pageSectionVersion.PageSectionTypeId = dynamicPageSectionViewModel.SectionTypeId.Value; pageSectionVersion.PageRouteVersionId = dynamicPageSectionViewModel.pageRouteVersionId; return(pageSectionVersion); }
public IActionResult Delete(int id, int pageRouteVersionId) { PageSectionVersion pageSectionVersion = _dynamicPageSectionVersionRepository.Delete(id, pageRouteVersionId); if (pageSectionVersion != null) { if (pageSectionVersion.PageRouteVersion.StatusId != (int)RequestStatus.Draft) { _pageRouteVersionRepository.ChangeStatus(pageSectionVersion.PageRouteVersionId, RequestStatus.Draft); } _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Delete, "Dynamic Page > " + ViewBag.DynamicPageName + " > Sections > Delete", pageSectionVersion.EnTitle); TempData[notificationMessageKey] = ToasrMessages.DeleteSuccess; TempData[notificationTypeKey] = notificationSuccess; return(Json(new { })); } _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Delete, "Dynamic Page > " + ViewBag.DynamicPageName + " > Sections > Warning in Delete", pageSectionVersion.EnTitle); TempData[notificationMessageKey] = "Error has been occurred."; TempData[notificationTypeKey] = notificationError; return(Json(new { })); }
/// <summary> /// Delete a page section version from database by id /// </summary> /// <param name="id">page section version id</param> /// <param name="pageRouteVersionId">page route version id</param> /// <returns>Deleted page section version</returns> public PageSectionVersion Delete(int id, int pageRouteVersionId) { try { bool isVersion = true; var pageRouteVersion = _db.PageRouteVersions.Include(d => d.PageSectionVersions).FirstOrDefault(d => d.Id == pageRouteVersionId); if (pageRouteVersion.VersionStatusEnum == VersionStatusEnum.Ignored || pageRouteVersion.VersionStatusEnum == VersionStatusEnum.Approved) { pageRouteVersion = AddNewPageRouteVersion(pageRouteVersion); isVersion = false; } pageRouteVersion.ContentVersionStatusEnum = pageRouteVersion.ContentVersionStatusEnum == VersionStatusEnum.Submitted ? VersionStatusEnum.Submitted : VersionStatusEnum.Draft; _db.PageRouteVersions.Update(pageRouteVersion); CopyPageSectionVersions(pageRouteVersion); PageSectionVersion entry = null; if (isVersion) { entry = _db.PageSectionVersions.First(e => e.Id == id); } else { entry = _db.PageSectionVersions.OrderByDescending(d => d.Id).First(e => e.PageSectionId == id); } entry.IsDeleted = true; _db.PageSectionVersions.Attach(entry); _db.Entry(entry).State = EntityState.Modified; _db.SaveChanges(); return(_db.PageSectionVersions.Include(x => x.PageRouteVersion).FirstOrDefault(s => s.Id == entry.Id)); } catch (Exception ex) { return(null); } }
public static PageSectionVersion MapToPageSectionVersion(this PageSection pageSection) { PageSectionVersion pageRouteVersion = new PageSectionVersion { Id = pageSection.PageSectionVersionId.Value, EnTitle = pageSection.EnTitle, ArTitle = pageSection.ArTitle, EnDescription = pageSection.EnDescription, ArDescription = pageSection.ArDescription, Order = pageSection.Order, IsActive = pageSection.IsActive, Url = pageSection.Url, EnImageAlt = pageSection.EnImageAlt, ArImageAlt = pageSection.ArImageAlt, PageSectionType = pageSection.PageSectionType, PageSectionTypeId = pageSection.PageSectionTypeId, PageRouteVersion = pageSection.PageSectionVersion.PageRouteVersion, PageRouteVersionId = pageSection.PageSectionVersion.PageRouteVersionId }; return(pageRouteVersion); }
public static SectionViewModel MapToSectionViewModel(this PageSectionVersion pageSectionVersion) { SectionViewModel sectionViewModel = new SectionViewModel { Id = pageSectionVersion.Id, EnTitle = pageSectionVersion.EnTitle, ArTitle = pageSectionVersion.ArTitle, EnDescription = pageSectionVersion.EnDescription, ArDescription = pageSectionVersion.ArDescription, EnImageAlt = pageSectionVersion.EnImageAlt, ArImageAlt = pageSectionVersion.ArImageAlt, Order = pageSectionVersion.Order, IsActive = pageSectionVersion.IsActive, Url = pageSectionVersion.Url, SectionTypeId = pageSectionVersion.PageSectionTypeId, CreationDate = pageSectionVersion.CreationDate, CreatedById = pageSectionVersion.CreatedById, MediaType = pageSectionVersion.PageSectionType.MediaType }; return(sectionViewModel); }
/// <summary> /// Update a page section object in database /// </summary> /// <param name="pageSectionVersion">page section version object</param> /// <returns>Updated object</returns> public PageSectionVersion Update(PageSectionVersion pageSectionVersion) { try { bool isVersion = true; var pageRouteVersion = _db.PageRouteVersions.Include(d => d.PageSectionVersions).FirstOrDefault(d => d.Id == pageSectionVersion.PageRouteVersionId); if (pageRouteVersion.VersionStatusEnum == VersionStatusEnum.Ignored || pageRouteVersion.VersionStatusEnum == VersionStatusEnum.Approved) { pageRouteVersion = AddNewPageRouteVersion(pageRouteVersion); isVersion = false; } pageRouteVersion.ContentVersionStatusEnum = pageRouteVersion.ContentVersionStatusEnum == VersionStatusEnum.Submitted ? VersionStatusEnum.Submitted : VersionStatusEnum.Draft; _db.PageRouteVersions.Update(pageRouteVersion); CopyPageSectionVersions(pageRouteVersion); PageSectionVersion entry = null; if (isVersion) { entry = _db.PageSectionVersions.First(e => e.Id == pageSectionVersion.Id); } else { entry = _db.PageSectionVersions.OrderByDescending(d => d.Id).First(e => e.PageSectionId == pageSectionVersion.Id); pageSectionVersion.Id = entry.Id; pageSectionVersion.PageSectionId = entry.PageSectionId; pageSectionVersion.PageRouteVersionId = entry.PageRouteVersionId; } _db.Entry(entry).CurrentValues.SetValues(pageSectionVersion); _db.SaveChanges(); return(_db.PageSectionVersions.Include(x => x.PageRouteVersion).FirstOrDefault(s => s.Id == pageSectionVersion.Id)); } catch (Exception ex) { return(null); } }
/// <summary> /// Add a new page section version to database /// </summary> /// <param name="pageSectionVersion">page section version model</param> /// <returns>Added object</returns> public PageSectionVersion Add(PageSectionVersion pageSectionVersion) { try { var pageRouteVersion = _db.PageRouteVersions.Include(d => d.PageSectionVersions).FirstOrDefault(d => d.Id == pageSectionVersion.PageRouteVersionId); if (pageRouteVersion.VersionStatusEnum == VersionStatusEnum.Ignored || pageRouteVersion.VersionStatusEnum == VersionStatusEnum.Approved) { pageRouteVersion = AddNewPageRouteVersion(pageRouteVersion); } pageRouteVersion.ContentVersionStatusEnum = pageRouteVersion.ContentVersionStatusEnum == VersionStatusEnum.Submitted ? VersionStatusEnum.Submitted : VersionStatusEnum.Draft; _db.PageRouteVersions.Update(pageRouteVersion); CopyPageSectionVersions(pageRouteVersion); pageSectionVersion.PageRouteVersionId = pageRouteVersion.Id; _db.PageSectionVersions.Add(pageSectionVersion); _db.SaveChanges(); return(_db.PageSectionVersions.Include(x => x.PageRouteVersion).FirstOrDefault(s => s.Id == pageSectionVersion.Id)); } catch (Exception ex) { return(null); } }
public static PageSectionVersion MapToPageSectionVersion(this PageSection model) { PageSectionVersion pageSectionVersion = new PageSectionVersion() { Id = model.PageSectionVersionId.Value, ApprovalDate = model.ApprovalDate, ApprovedById = model.ApprovedById, EnTitle = model.EnTitle, ArTitle = model.ArTitle, EnDescription = model.EnDescription, ArDescription = model.ArDescription, EnImageAlt = model.EnImageAlt, ArImageAlt = model.ArImageAlt, Url = model.Url, IsActive = model.IsActive, IsDeleted = model.IsDeleted, Order = model.Order, CreationDate = model.CreationDate, CreatedById = model.CreatedById, PageSection = model }; return(pageSectionVersion); }
public async Task <IActionResult> Create(PageSectionCreateViewModel sectionViewModel) { List <PageSectionType> sectionTypes; RemoveFieldsFromModelStateDependOnSectionType(ModelState, sectionViewModel.SectionTypeId ?? 0); sectionViewModel.Section.EnDescription.ValidateHtml("EnDescription", ModelState); sectionViewModel.Section.ArDescription.ValidateHtml("ArDescription", ModelState); PageSectionType sectionType = null; if (sectionViewModel.SectionTypeId != null) { sectionType = _dynamicPageSectionRepository.GetPageSectionType(sectionViewModel.SectionTypeId.Value); if (sectionType.MediaType == SectionMediaType.Image.ToString() && sectionViewModel.Section.Photo == null) { ModelState.AddModelError(nameof(sectionViewModel.Section.Photo), "you should uplaod a photo."); _toastNotification.AddWarningToastMessage("you should uplaod a photo."); } } if (ModelState.IsValid) { sectionViewModel = RemoveTagsFromDescription(sectionViewModel); PageSectionVersion pageSectionVersion = sectionViewModel.MapToPageSectionVersion(); if (sectionType.MediaType == SectionMediaType.Image.ToString()) { pageSectionVersion.Url = _fileService.UploadImageUrlNew(sectionViewModel.Section.Photo); } var user = await _userManager.GetUserAsync(HttpContext.User); pageSectionVersion.CreatedById = user.Id; pageSectionVersion.CreationDate = DateTime.Now; PageSectionVersion newDynamicPageSectionVersion = _dynamicPageSectionVersionRepository.Add(pageSectionVersion); if (newDynamicPageSectionVersion != null) { _toastNotification.AddSuccessToastMessage(ToasrMessages.AddSuccess); if (sectionViewModel.submit != null) { return(RedirectToAction("Index", "DynamicSectionCard", new { id = newDynamicPageSectionVersion.Id, pageRouteVersionId = newDynamicPageSectionVersion.PageRouteVersionId })); } _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Add, "Dynamic Page > " + ViewBag.DynamicPageName + " > Sections > Add ", pageSectionVersion.EnTitle); return(RedirectToAction("Index", new { pageRouteVersionId = newDynamicPageSectionVersion.PageRouteVersionId })); } else { _eventLogger.LogInfoEvent(HttpContext.User.Identity.Name, Common.ActivityEnum.Warning, "Dynamic Page > " + ViewBag.DynamicPageName + " > Sections > Warning in Add", pageSectionVersion.EnTitle); _toastNotification.AddErrorToastMessage(ToasrMessages.warning); sectionTypes = _dynamicPageSectionRepository.GetPageSectionTypes(); sectionViewModel = new PageSectionCreateViewModel(sectionTypes); return(View(sectionViewModel)); } } sectionTypes = _dynamicPageSectionRepository.GetPageSectionTypes(); var pageRouteVer = sectionViewModel.pageRouteVersionId; sectionViewModel = new PageSectionCreateViewModel(sectionTypes); sectionViewModel.pageRouteVersionId = pageRouteVer; return(View(sectionViewModel)); }