public void ChangePassword() { RequestContext.Current.Add<UserContext>("UserContext", new UserContext { UserId = 1, LanguageId = 1, UserName = "******", SiteId = 1 }); SecurityManager securityManager = new SecurityManager(); string password = DataEncryption.Encrypt("Password1"); // securityManager.CreateAccount(new UserMembership { UserName = "******", Password = password }); securityManager.ChangePassword("admin", "oldPassword", password); }
/// <summary> /// GetContentComment /// </summary> /// <param name="contextId"></param> /// <param name="contextId"></param> /// <returns></returns> public ContentCommentData GetContentComments(ContextEnum context, int contextContentId) { ContentCommentData contentCommentData = new ContentCommentData(); contentCommentData.ContentComments = eCollabroDbContext.Repository<ContentComment>().Query().Filter(qry => qry.ContextId.Equals((int)context) && qry.ContextContentId.Equals(contextContentId)).Get().ToList(); SecurityManager securityManager = new SecurityManager(); List<UserMembership> users = securityManager.GetUsers(contentCommentData.ContentComments.Select(fld => fld.CreatedById).ToList()); foreach (ContentComment contentComment in contentCommentData.ContentComments) { UserMembership user = users.Where(qry => qry.UserId.Equals(contentComment.CreatedById)).FirstOrDefault(); contentComment.CreatedBy = user == null ? "Unknown" : user.UserName; contentComment.TimeInterval = CommonFunctions.GetTimeInterval(contentComment.CreatedOn); } contentCommentData.NumberOfLikes = eCollabroDbContext.Repository<ContentLikeDislike>().Query().Get().Count(); contentCommentData.NumberOfVotes = eCollabroDbContext.Repository<ContentVote>().Query().Get().Count(); int totalRates = eCollabroDbContext.Repository<ContentRating>().Query().Get().Count(); if (totalRates != 0) contentCommentData.AverageRatings =Math.Round(eCollabroDbContext.Repository<ContentRating>().Query().Get().Sum(op => op.Rating) / totalRates,2); contentCommentData.UserLiked = eCollabroDbContext.Repository<ContentLikeDislike>().Query().Filter(op => op.CreatedById.Equals(UserContextDetails.UserId)).Get().Any(); ContentRating userRating = eCollabroDbContext.Repository<ContentRating>().Query().Filter(op => op.CreatedById.Equals(UserContextDetails.UserId)).Get().FirstOrDefault(); if (userRating != null) contentCommentData.UserRating =Convert.ToInt32(userRating.Rating); contentCommentData.UserVoted = eCollabroDbContext.Repository<ContentVote>().Query().Filter(op => op.CreatedById.Equals(UserContextDetails.UserId)).Get().Any(); return contentCommentData; }
/// <summary> /// ContentManager /// </summary> public ContentManager() { _securityManager = new SecurityManager(); _workflowManager = new WorkflowManager(); }
/// <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(); } } }
/// <summary> /// CheckSiteCollectionAdminPermission /// </summary> /// <param name="userId"></param> private void CheckSiteCollectionAdminPermission(int userId) { if (_securityManager == null) _securityManager = new SecurityManager(); bool isSiteCollectionAdmin = _securityManager.CheckSiteCollectionAdmin(userId); if (!isSiteCollectionAdmin) throw new BusinessException(_coreValidationResourceManager.GetString(CoreValidationMessagesConstants.UnAuthorized), CoreValidationMessagesConstants.UnAuthorized); }
/// <summary> /// SaveContentPage /// </summary> /// <param name="contentPage"></param> /// <returns></returns> public ServiceResponse<int> SaveContentPage(ContentPageDC contentPage) { ServiceResponse<int> contentPageResponse = new ServiceResponse<int>(); try { SetContext(); ContentPage contentPageModel = Mapper.Map<ContentPageDC, ContentPage>(contentPage); _contentManager.SaveContentPage(contentPageModel); contentPageResponse.Result = contentPageModel.ContentPageId; SecurityManager securityManager = null; // Create Navigation if (contentPage.AddToNavigation) { securityManager = new SecurityManager(); int? navigationParentId = null; if (!contentPage.NavigationParentId.Equals(0)) navigationParentId = contentPage.NavigationParentId; securityManager.SaveNavigation(new Navigation { NavigationText = contentPage.MenuTitle, ContentPageId = contentPageModel.ContentPageId, CreatedById = securityManager.UserContextDetails.UserId, CreatedOn = DateTime.UtcNow, NavigationTypeId = (int)NavigationTypeEnum.Content, IsActive = true, SiteId = securityManager.UserContextDetails.SiteId, NavigationParentId = navigationParentId }); } // set as Home Page if (contentPage.SetToHomePage) { if (securityManager == null) securityManager = new SecurityManager(); SiteConfiguration siteConfiguration = securityManager.GetSiteConfiguration(); siteConfiguration.HomePageContentPageId = contentPageModel.ContentPageId; securityManager.SaveSiteConfiguration(siteConfiguration); } } catch (Exception ex) { HandleError(ex, contentPageResponse); } return contentPageResponse; }