/// <summary> /// SaveImage /// </summary> /// <param name="image"></param> /// <returns></returns> public void SaveImage(SiteImage image, byte[] fileData) { #region Check Permission List<PermissionEnum> userPermissions = _securityManager.GetUserFeaturePermissions(UserContextDetails.UserId, FeatureEnum.ImageGallery); if ((image.ImageId.Equals(0) && !userPermissions.Contains(PermissionEnum.AddContent)) || (!image.ImageId.Equals(0) && !userPermissions.Contains(PermissionEnum.EditContent))) throw new BusinessException(_coreValidationResourceManager.GetString(CoreValidationMessagesConstants.UnAuthorized), CoreValidationMessagesConstants.UnAuthorized); #endregion //check contentSetting SecurityManager securityManager = new SecurityManager(); List<SiteContentSettingResult> siteContentSettingResults = securityManager.GetSiteFeatureSettings(FeatureEnum.ImageGallery); bool approvalRequired = siteContentSettingResults.Where(qry => qry.ContentSettingId.Equals((int)FeatureSettingEnum.ApprovalRequired)).FirstOrDefault().IsAssigned; //self approved in case approval not required if (!approvalRequired) { image.ApprovalStatus = WorkflowConstants.ApprovedStatus; image.ApproveRejectDate = DateTime.UtcNow; image.ApproveRejectById = UserContextDetails.UserId; } else { image.ApprovalStatus = WorkflowConstants.ApprovalWaitingStatus; image.ApproveRejectById = null; image.ApproveRejectDate = null; } if (image.ImageId.Equals(0)) // New SiteImage { AddImage(image, fileData, approvalRequired); } else // Update SiteImage { UpdateImage(image, fileData, approvalRequired); } }
/// <summary> /// SaveContentPage /// </summary> /// <param name="contentPage"></param> /// <returns></returns> public void SaveContentPage(ContentPage contentPage) { #region Check Permission List<PermissionEnum> userPermissions = _securityManager.GetUserFeaturePermissions(UserContextDetails.UserId, FeatureEnum.ContentPage); if ((contentPage.ContentPageId.Equals(0) && !userPermissions.Contains(PermissionEnum.AddContent)) || (!contentPage.ContentPageId.Equals(0) && !userPermissions.Contains(PermissionEnum.EditContent))) throw new BusinessException(_coreValidationResourceManager.GetString(CoreValidationMessagesConstants.UnAuthorized), CoreValidationMessagesConstants.UnAuthorized); #endregion //check contentSetting SecurityManager securityManager = new SecurityManager(); List<SiteContentSettingResult> siteContentSettingResults = securityManager.GetSiteFeatureSettings(FeatureEnum.ContentPage); bool approvalRequired = siteContentSettingResults.Where(qry => qry.ContentSettingId.Equals((int)FeatureSettingEnum.ApprovalRequired)).FirstOrDefault().IsAssigned; //self approved in case approval not required if (!approvalRequired) { contentPage.ApprovalStatus = WorkflowConstants.ApprovedStatus; contentPage.ApproveRejectDate = DateTime.UtcNow; contentPage.ApproveRejectById = UserContextDetails.UserId; } else { contentPage.ApprovalStatus = WorkflowConstants.ApprovalWaitingStatus; contentPage.ApproveRejectById = null; contentPage.ApproveRejectDate = null; } if (contentPage.ContentPageId.Equals(0)) // New ContentPage { contentPage.CreatedById = UserContextDetails.UserId; contentPage.CreatedOn = DateTime.UtcNow; if (approvalRequired) contentPage.ApprovalStatus = WorkflowConstants.ApprovalWaitingStatus; eCollabroDbContext.Repository<ContentPage>().Insert(contentPage); eCollabroDbContext.Save(); if (approvalRequired) { _workflowManager.CreateWorkflowTask(ContextEnum.ContentPage, contentPage.ContentPageId, "New Content Page [" + contentPage.ContentPageTitle + "] ", "Content Page Description : " + contentPage.ContentPageDescription); } } else // Update ContentPage { ContentPage oldContentPage = eCollabroDbContext.Repository<ContentPage>().Query().Filter(qry => qry.ContentPageId.Equals(contentPage.ContentPageId)).Get().FirstOrDefault(); if (oldContentPage != null) { if (approvalRequired && oldContentPage.ApprovalStatus.Equals(WorkflowConstants.ApprovedStatus)) // Save to Queue { contentPage.ModifiedById = UserContextDetails.UserId; contentPage.ModifiedOn = DateTime.UtcNow; contentPage.ApprovalStatus = WorkflowConstants.ApprovalWaitingStatus; TempContentPage tempContentPage = Mapper.Map<ContentPage, TempContentPage>(contentPage); _workflowManager.SaveToQueue<TempContentPage>(tempContentPage, ContextEnum.ContentPage, tempContentPage.ContentPageId); _workflowManager.CreateWorkflowTask(ContextEnum.ContentPage, contentPage.ContentPageId, "New Content Page [" + contentPage.ContentPageTitle + "] ", "Content Page Description : " + contentPage.ContentPageDescription); } else // Record is new and not in Queue { oldContentPage.ContentPageTitle = contentPage.ContentPageTitle; oldContentPage.ContentPageDescription = contentPage.ContentPageDescription; oldContentPage.ContentPageContent = contentPage.ContentPageContent; oldContentPage.ContentPageCategoryId = contentPage.ContentPageCategoryId; oldContentPage.IsActive = contentPage.IsActive; oldContentPage.IsAnomynousAccess = contentPage.IsAnomynousAccess; oldContentPage.IsCommentsAllowed = contentPage.IsCommentsAllowed; oldContentPage.IsLikeAllowed = contentPage.IsLikeAllowed; oldContentPage.IsRatingAllowed = contentPage.IsRatingAllowed; oldContentPage.IsVotingAllowed = contentPage.IsVotingAllowed; oldContentPage.ModifiedById = UserContextDetails.UserId; oldContentPage.ModifiedOn = DateTime.UtcNow; oldContentPage.ApprovalStatus = contentPage.ApprovalStatus; oldContentPage.ApproveRejectDate = contentPage.ApproveRejectDate; oldContentPage.ApproveRejectById = contentPage.ApproveRejectById; eCollabroDbContext.Save(); if (approvalRequired) // approval required // create or update task { _workflowManager.CreateWorkflowTask(ContextEnum.ContentPage, contentPage.ContentPageId, "New Content Page [" + contentPage.ContentPageTitle + "] ", "Content Page Description : " + contentPage.ContentPageDescription); } } } else { throw new DBConcurrencyException(); } } }