Example #1
0
        public static Settings SettingsViewModelToSettings(EditSettingsViewModel settingsViewModel, Settings existingSettings)
        {
            //NOTE: The only reason some properties are commented out, are because those items were
            //      moved to their own page when the admin was refactored.

            existingSettings.Id = settingsViewModel.Id;
            existingSettings.ForumName = settingsViewModel.ForumName;
            existingSettings.ForumUrl = settingsViewModel.ForumUrl;
            existingSettings.IsClosed = settingsViewModel.IsClosed;
            existingSettings.EnableRSSFeeds = settingsViewModel.EnableRSSFeeds;
            existingSettings.DisplayEditedBy = settingsViewModel.DisplayEditedBy;
            existingSettings.EnableMarkAsSolution = settingsViewModel.EnableMarkAsSolution;
            existingSettings.MarkAsSolutionReminderTimeFrame = settingsViewModel.MarkAsSolutionReminderTimeFrame;
            //existingSettings.EnableSpamReporting = settingsViewModel.EnableSpamReporting;
            //existingSettings.EnableMemberReporting = settingsViewModel.EnableMemberReporting;
            existingSettings.EnableEmailSubscriptions = settingsViewModel.EnableEmailSubscriptions;
            existingSettings.ManuallyAuthoriseNewMembers = settingsViewModel.ManuallyAuthoriseNewMembers;
            existingSettings.EmailAdminOnNewMemberSignUp = settingsViewModel.EmailAdminOnNewMemberSignUp;
            existingSettings.TopicsPerPage = settingsViewModel.TopicsPerPage;
            existingSettings.PostsPerPage = settingsViewModel.PostsPerPage;
            existingSettings.ActivitiesPerPage = settingsViewModel.ActivitiesPerPage;
            existingSettings.EnablePrivateMessages = settingsViewModel.EnablePrivateMessages;
            existingSettings.MaxPrivateMessagesPerMember = settingsViewModel.MaxPrivateMessagesPerMember;
            existingSettings.PrivateMessageFloodControl = settingsViewModel.PrivateMessageFloodControl;
            existingSettings.EnableSignatures = settingsViewModel.EnableSignatures;
            existingSettings.EnablePoints = settingsViewModel.EnablePoints;
            existingSettings.PointsAllowedToVoteAmount = settingsViewModel.PointsAllowedToVoteAmount;
            existingSettings.PointsAllowedForExtendedProfile = settingsViewModel.PointsAllowedForExtendedProfile;
            existingSettings.PointsAddedPerPost = settingsViewModel.PointsAddedPerPost;
            existingSettings.PointsAddedPostiveVote = settingsViewModel.PointsAddedPostiveVote;
            existingSettings.PointsDeductedNagativeVote = settingsViewModel.PointsDeductedNagativeVote;
            existingSettings.PointsAddedForSolution = settingsViewModel.PointsAddedForSolution;
            existingSettings.AdminEmailAddress = settingsViewModel.AdminEmailAddress;
            existingSettings.NotificationReplyEmail = settingsViewModel.NotificationReplyEmail;
            existingSettings.SMTP = settingsViewModel.SMTP;
            existingSettings.SMTPUsername = settingsViewModel.SMTPUsername;
            existingSettings.SMTPPassword = settingsViewModel.SMTPPassword;
            existingSettings.Theme = settingsViewModel.Theme;
            //existingSettings.AkismentKey = settingsViewModel.AkismentKey;
            //existingSettings.EnableAkisment = settingsViewModel.EnableAkisment;
            existingSettings.SMTPPort = settingsViewModel.SMTPPort.ToString();
            //existingSettings.SpamQuestion = settingsViewModel.SpamQuestion;
            //existingSettings.SpamAnswer = settingsViewModel.SpamAnswer;
            existingSettings.SMTPEnableSSL = settingsViewModel.SMTPEnableSSL;
            //existingSettings.EnableSocialLogins = settingsViewModel.EnableSocialLogins;
            existingSettings.EnablePolls = settingsViewModel.EnablePolls;
            existingSettings.SuspendRegistration = settingsViewModel.SuspendRegistration;
            existingSettings.NewMemberEmailConfirmation = settingsViewModel.NewMemberEmailConfirmation;
            existingSettings.PageTitle = settingsViewModel.PageTitle;
            existingSettings.MetaDesc = settingsViewModel.MetaDesc;
            existingSettings.EnableEmoticons = settingsViewModel.EnableEmoticons;
            existingSettings.DisableDislikeButton = settingsViewModel.DisableDislikeButton;
            existingSettings.AgreeToTermsAndConditions = settingsViewModel.AgreeToTermsAndConditions;
            existingSettings.DisableStandardRegistration = settingsViewModel.DisableStandardRegistration;
            existingSettings.TermsAndConditions = settingsViewModel.TermsAndConditions;
            return existingSettings;
        }
        public void DeleteDefaultLanguage()
        {
            var testLanguage = new Language {Name = "test"};
            var settings = new Settings {DefaultLanguage = testLanguage};

            _settingsRepositorySub.GetSettings().Returns(settings);

            Assert.Throws<ApplicationException>(() => _localizationService.Delete(testLanguage));
        }
Example #3
0
 public void Update(Settings item)
 {
     // Check there's not an object with same identifier already in context
     if (_context.Setting.Local.Select(x => x.Id == item.Id).Any())
     {
         throw new ApplicationException("Object already exists in context - you do not need to call Update. Save occurs on Commit");
     }
     _context.Entry(item).State = EntityState.Modified;  
 }
Example #4
0
        public static EditSettingsViewModel SettingsToSettingsViewModel(Settings currentSettings)
        {
            var settingViewModel = new EditSettingsViewModel
            {
                Id = currentSettings.Id,
                ForumName = currentSettings.ForumName,
                ForumUrl = currentSettings.ForumUrl,
                IsClosed = currentSettings.IsClosed,
                EnableRSSFeeds = currentSettings.EnableRSSFeeds,
                DisplayEditedBy = currentSettings.DisplayEditedBy,
                EnableMarkAsSolution = currentSettings.EnableMarkAsSolution,
                EnableSpamReporting = currentSettings.EnableSpamReporting,
                EnableMemberReporting = currentSettings.EnableMemberReporting,
                EnableEmailSubscriptions = currentSettings.EnableEmailSubscriptions,
                ManuallyAuthoriseNewMembers = currentSettings.ManuallyAuthoriseNewMembers,
                EmailAdminOnNewMemberSignUp = currentSettings.EmailAdminOnNewMemberSignUp,
                TopicsPerPage = currentSettings.TopicsPerPage,
                PostsPerPage = currentSettings.PostsPerPage,
                ActivitiesPerPage = currentSettings.ActivitiesPerPage,
                EnablePrivateMessages = currentSettings.EnablePrivateMessages,
                MaxPrivateMessagesPerMember = currentSettings.MaxPrivateMessagesPerMember,
                PrivateMessageFloodControl = currentSettings.PrivateMessageFloodControl,
                EnableSignatures = currentSettings.EnableSignatures,
                EnablePoints = currentSettings.EnablePoints,
                PointsAllowedToVoteAmount = currentSettings.PointsAllowedToVoteAmount,
                PointsAddedPerPost = currentSettings.PointsAddedPerPost,
                PointsAddedPostiveVote = currentSettings.PointsAddedPostiveVote,
                PointsDeductedNagativeVote = currentSettings.PointsDeductedNagativeVote,
                PointsAddedForSolution = currentSettings.PointsAddedForSolution,
                AdminEmailAddress = currentSettings.AdminEmailAddress,
                NotificationReplyEmail = currentSettings.NotificationReplyEmail,
                SMTP = currentSettings.SMTP,
                SMTPUsername = currentSettings.SMTPUsername,
                SMTPPassword = currentSettings.SMTPPassword,
                AkismentKey = currentSettings.AkismentKey,
                EnableAkisment = currentSettings.EnableAkisment != null && (bool)currentSettings.EnableAkisment,
                NewMemberEmailConfirmation = currentSettings.NewMemberEmailConfirmation != null && (bool)currentSettings.NewMemberEmailConfirmation,
                Theme = currentSettings.Theme,
                SMTPPort = string.IsNullOrEmpty(currentSettings.SMTPPort) ? null : (int?)(Convert.ToInt32(currentSettings.SMTPPort)),
                SpamQuestion = currentSettings.SpamQuestion,
                SpamAnswer = currentSettings.SpamAnswer,
                Themes = AppHelpers.GetThemeFolders(),
                SMTPEnableSSL = currentSettings.SMTPEnableSSL ?? false,
                EnableSocialLogins = currentSettings.EnableSocialLogins ?? false,
                EnablePolls = currentSettings.EnablePolls ?? false,
                SuspendRegistration = currentSettings.SuspendRegistration ?? false
            };

            return settingViewModel;
        }
Example #5
0
 /// <summary>
 /// Maps the posts for a specific topic
 /// </summary>
 /// <param name="posts"></param>
 /// <param name="votes"></param>
 /// <param name="permission"></param>
 /// <param name="topic"></param>
 /// <param name="loggedOnUser"></param>
 /// <param name="settings"></param>
 /// <param name="favourites"></param>
 /// <returns></returns>
 public static List<PostViewModel> CreatePostViewModels(IEnumerable<Post> posts, List<Vote> votes, PermissionSet permission, Topic topic, MembershipUser loggedOnUser, Settings settings, List<Favourite> favourites)
 {
     var viewModels = new List<PostViewModel>();
     var groupedVotes = votes.ToLookup(x => x.Post.Id);
     var groupedFavourites = favourites.ToLookup(x => x.Post.Id);
     foreach (var post in posts)
     {
         var id = post.Id;
         var postVotes = (groupedVotes.Contains(id) ? groupedVotes[id].ToList() : new List<Vote>());
         var postFavs = (groupedFavourites.Contains(id) ? groupedFavourites[id].ToList() : new List<Favourite>());
         viewModels.Add(CreatePostViewModel(post, postVotes, permission, topic, loggedOnUser, settings, postFavs));
     }
     return viewModels;
 }
Example #6
0
 /// <summary>
 /// Save settings (Clears cache upon save)
 /// </summary>
 /// <param name="settings"></param>
 public void Save(Settings settings)
 {
     settings.AdminEmailAddress = StringUtils.SafePlainText(settings.AdminEmailAddress);
     settings.AkismentKey = StringUtils.SafePlainText(settings.AkismentKey);
     settings.CurrentDatabaseVersion = StringUtils.SafePlainText(settings.CurrentDatabaseVersion);
     settings.ForumName = StringUtils.SafePlainText(settings.ForumName);
     settings.ForumUrl = StringUtils.SafePlainText(settings.ForumUrl);
     settings.NotificationReplyEmail = StringUtils.SafePlainText(settings.NotificationReplyEmail);
     settings.SMTP = StringUtils.SafePlainText(settings.SMTP);
     settings.SMTPPassword = StringUtils.SafePlainText(settings.SMTPPassword);
     settings.SMTPPort = StringUtils.SafePlainText(settings.SMTPPort);
     settings.SMTPUsername = StringUtils.SafePlainText(settings.SMTPUsername);
     settings.SpamAnswer = StringUtils.SafePlainText(settings.SpamAnswer);
     settings.SpamQuestion = StringUtils.SafePlainText(settings.SpamQuestion);
     _settingsRepository.Update(settings);
 }
 public static Settings SettingsViewModelToSettings(EditSettingsViewModel settingsViewModel, Settings existingSettings)
 {
     existingSettings.Id = settingsViewModel.Id;
     existingSettings.ForumName = settingsViewModel.ForumName;
     existingSettings.ForumUrl = settingsViewModel.ForumUrl;
     existingSettings.IsClosed = settingsViewModel.IsClosed;
     existingSettings.EnableRSSFeeds = settingsViewModel.EnableRSSFeeds;
     existingSettings.DisplayEditedBy = settingsViewModel.DisplayEditedBy;
     existingSettings.EnableMarkAsSolution = settingsViewModel.EnableMarkAsSolution;
     existingSettings.EnableSpamReporting = settingsViewModel.EnableSpamReporting;
     existingSettings.EnableMemberReporting = settingsViewModel.EnableMemberReporting;
     existingSettings.EnableEmailSubscriptions = settingsViewModel.EnableEmailSubscriptions;
     existingSettings.ManuallyAuthoriseNewMembers = settingsViewModel.ManuallyAuthoriseNewMembers;
     existingSettings.EmailAdminOnNewMemberSignUp = settingsViewModel.EmailAdminOnNewMemberSignUp;
     existingSettings.TopicsPerPage = settingsViewModel.TopicsPerPage;
     existingSettings.PostsPerPage = settingsViewModel.PostsPerPage;
     existingSettings.ActivitiesPerPage = settingsViewModel.ActivitiesPerPage;
     existingSettings.EnablePrivateMessages = settingsViewModel.EnablePrivateMessages;
     existingSettings.MaxPrivateMessagesPerMember = settingsViewModel.MaxPrivateMessagesPerMember;
     existingSettings.PrivateMessageFloodControl = settingsViewModel.PrivateMessageFloodControl;
     existingSettings.EnableSignatures = settingsViewModel.EnableSignatures;
     existingSettings.EnablePoints = settingsViewModel.EnablePoints;
     existingSettings.PointsAllowedToVoteAmount = settingsViewModel.PointsAllowedToVoteAmount;
     existingSettings.PointsAddedPerPost = settingsViewModel.PointsAddedPerPost;
     existingSettings.PointsAddedPostiveVote = settingsViewModel.PointsAddedPostiveVote;
     existingSettings.PointsDeductedNagativeVote = settingsViewModel.PointsDeductedNagativeVote;
     existingSettings.PointsAddedForSolution = settingsViewModel.PointsAddedForSolution;
     existingSettings.AdminEmailAddress = settingsViewModel.AdminEmailAddress;
     existingSettings.NotificationReplyEmail = settingsViewModel.NotificationReplyEmail;
     existingSettings.SMTP = settingsViewModel.SMTP;
     existingSettings.SMTPUsername = settingsViewModel.SMTPUsername;
     existingSettings.SMTPPassword = settingsViewModel.SMTPPassword;
     existingSettings.Theme = settingsViewModel.Theme;
     existingSettings.AkismentKey = settingsViewModel.AkismentKey;
     existingSettings.EnableAkisment = settingsViewModel.EnableAkisment;
     existingSettings.SMTPPort = settingsViewModel.SMTPPort.ToString();
     existingSettings.SpamQuestion = settingsViewModel.SpamQuestion;
     existingSettings.SpamAnswer = settingsViewModel.SpamAnswer;
     existingSettings.SMTPEnableSSL = settingsViewModel.SMTPEnableSSL;
     existingSettings.EnableSocialLogins = settingsViewModel.EnableSocialLogins;
     existingSettings.EnablePolls = settingsViewModel.EnablePolls;
     existingSettings.SuspendRegistration = settingsViewModel.SuspendRegistration;
     existingSettings.NewMemberEmailConfirmation = settingsViewModel.NewMemberEmailConfirmation;
     existingSettings.PageTitle = settingsViewModel.PageTitle;
     existingSettings.MetaDesc = settingsViewModel.MetaDesc;
     return existingSettings;
 }
Example #8
0
        public static PostViewModel CreatePostViewModel(Post post, List<Vote> votes, PermissionSet permission, Topic topic, MembershipUser loggedOnUser, Settings settings, List<Favourite> favourites)
        {
            var allowedToVote = (loggedOnUser != null && loggedOnUser.Id != post.User.Id &&
                                 loggedOnUser.TotalPoints >= settings.PointsAllowedToVoteAmount);

            // Remove votes where no VotedBy has been recorded
            votes.RemoveAll(x => x.VotedByMembershipUser == null);

            var hasVotedUp = false;
            var hasVotedDown = false;
            var hasFavourited = false;
            if (loggedOnUser != null && loggedOnUser.Id != post.User.Id)
            {
                hasFavourited = favourites.Any(x => x.Member.Id == loggedOnUser.Id);
                hasVotedUp = votes.Count(x => x.Amount > 0 && x.VotedByMembershipUser.Id == loggedOnUser.Id) > 0;
                hasVotedDown = votes.Count(x => x.Amount < 0 && x.VotedByMembershipUser.Id == loggedOnUser.Id) > 0;
            }

            // Check for online status
            var date = DateTime.UtcNow.AddMinutes(-AppConstants.TimeSpanInMinutesToShowMembers);

            return new PostViewModel
            {
                Permissions = permission,
                Votes = votes,
                Post = post,
                ParentTopic = topic,
                AllowedToVote = allowedToVote,
                MemberHasFavourited = hasFavourited,
                Favourites = favourites,
                PermaLink = string.Concat(topic.NiceUrl, "?", AppConstants.PostOrderBy, "=", AppConstants.AllPosts, "#comment-", post.Id),
                MemberIsOnline = post.User.LastActivityDate > date,
                HasVotedDown = hasVotedDown,
                HasVotedUp = hasVotedUp
            };
        }
Example #9
0
        public static PostViewModel CreatePostViewModel(Post post, List<Vote> votes, PermissionSet permission, Topic topic, MembershipUser loggedOnUser, Settings settings, List<Favourite> favourites)
        {
            var allowedToVote = (loggedOnUser != null && loggedOnUser.Id != post.User.Id &&
                                 loggedOnUser.TotalPoints > settings.PointsAllowedToVoteAmount &&
                                 votes.All(x => x.User.Id != loggedOnUser.Id));

            var hasFavourited = false;
            if (loggedOnUser != null && loggedOnUser.Id != post.User.Id)
            {
                hasFavourited = favourites.Any(x => x.Member.Id == loggedOnUser.Id);
            }

            return new PostViewModel
            {
                Permissions = permission,
                Votes = votes,
                Post = post,
                ParentTopic = topic,
                AllowedToVote = allowedToVote,
                MemberHasFavourited = hasFavourited,
                Favourites = favourites,
                PermaLink = string.Concat(topic.NiceUrl, "?", AppConstants.PostOrderBy, "=", AppConstants.AllPosts, "#comment-", post.Id)
            };
        }
Example #10
0
 public Settings Add(Settings item)
 {
     return _context.Setting.Add(item);
 }
Example #11
0
        public void SendMail(List<Email> emails, Settings settings)
        {
            // Add all the emails to the email table
            // They are sent every X seconds by the email sending task
            foreach (var email in emails)
            {

                // Sort local images in emails
                email.Body = StringUtils.AppendDomainToImageUrlInHtml(email.Body, settings.ForumUrl.TrimEnd('/'));
                Add(email);
            }
        }
Example #12
0
 public void SendMail(Email email, Settings settings)
 {
     SendMail(new List<Email> { email }, settings);
 }
Example #13
0
        public string EmailTemplate(string to, string content, Settings settings)
        {
            using (var sr = File.OpenText(HostingEnvironment.MapPath(@"~/Content/Emails/EmailNotification.htm")))
            {
                var sb = sr.ReadToEnd();
                sr.Close();
                sb = sb.Replace("#CONTENT#", content);
                sb = sb.Replace("#SITENAME#", settings.ForumName);
                sb = sb.Replace("#SITEURL#", settings.ForumUrl);
                if (!string.IsNullOrEmpty(to))
                {
                    to = $"<p>{to},</p>";
                    sb = sb.Replace("#TO#", to);
                }

                return sb;
            }
        }
        private InstallerResult CreateInitialData()
        {
            var installerResult = new InstallerResult { Successful = true, Message = "Congratulations, MVC Forum has installed successfully" };

            // I think this is all I need to call to kick EF into life
            //EFCachingProviderConfiguration.DefaultCache = new AspNetCache();
            //EFCachingProviderConfiguration.DefaultCachingPolicy = CachingPolicy.CacheAll;

            // Now setup the services as we can't do it in the constructor
            InitialiseServices();

            // First UOW to create the data needed for other saves
            using (var unitOfWork = _UnitOfWorkManager.NewUnitOfWork())
            {
                try
                {
                    // Check if category exists or not, we only do a single check for the first object within this
                    // UOW because, if anything failed inside. Everything else would be rolled back to because of the 
                    // transaction
                    const string exampleCatName = "Example Category";
                    if (_categoryService.GetAll().FirstOrDefault(x => x.Name == exampleCatName) == null)
                    {
                        // Doesn't exist so add the example category
                        var exampleCat = new Category { Name = exampleCatName, ModeratePosts = false, ModerateTopics = false};
                        _categoryService.Add(exampleCat);

                        // Add the default roles
                        var standardRole = new MembershipRole { RoleName = "Standard Members" };
                        var guestRole = new MembershipRole { RoleName = "Guest" };
                        var moderatorRole = new MembershipRole { RoleName = "Moderator" };
                        var adminRole = new MembershipRole { RoleName = "Admin" };
                        _roleService.CreateRole(standardRole);
                        _roleService.CreateRole(guestRole);
                        _roleService.CreateRole(moderatorRole);
                        _roleService.CreateRole(adminRole);

                        unitOfWork.Commit();
                    }

                }
                catch (Exception ex)
                {
                    unitOfWork.Rollback();
                    installerResult.Exception = ex.InnerException;
                    installerResult.Message = "Error creating the initial data >> Category & Roles";
                    installerResult.Successful = false;
                    return installerResult;
                }
            }

            // Add / Update the default language strings
            installerResult = AddOrUpdateTheDefaultLanguageStrings(installerResult);
            if (!installerResult.Successful)
            {
                return installerResult;
            }   

            // Now we have saved the above we can create the rest of the data
            using (var unitOfWork = _UnitOfWorkManager.NewUnitOfWork())
            {
                try
                {
                    // if the settings already exist then do nothing
                    if (_settingsService.GetSettings(false) == null)
                    {
                        // Get the default language
                        var startingLanguage = _localizationService.GetLanguageByName("en-GB");

                        // Get the Standard Members role
                        var startingRole = _roleService.GetRole("Standard Members");

                        // create the settings
                        var settings = new Settings
                        {
                            ForumName = "MVC Forum",
                            ForumUrl = "http://www.mydomain.com",
                            IsClosed = false,
                            EnableRSSFeeds = true,
                            DisplayEditedBy = true,
                            EnablePostFileAttachments = false,
                            EnableMarkAsSolution = true,
                            EnableSpamReporting = true,
                            EnableMemberReporting = true,
                            EnableEmailSubscriptions = true,
                            ManuallyAuthoriseNewMembers = false,
                            EmailAdminOnNewMemberSignUp = true,
                            TopicsPerPage = 20,
                            PostsPerPage = 20,
                            EnablePrivateMessages = true,
                            MaxPrivateMessagesPerMember = 50,
                            PrivateMessageFloodControl = 1,
                            EnableSignatures = false,
                            EnablePoints = true,
                            PointsAllowedToVoteAmount = 1,
                            PointsAddedPerPost = 1,
                            PointsAddedForSolution = 4,
                            PointsDeductedNagativeVote = 2,
                            AdminEmailAddress = "*****@*****.**",
                            NotificationReplyEmail = "*****@*****.**",
                            SMTPEnableSSL = false,
                            Theme = "Metro",
                            NewMemberStartingRole = startingRole,
                            DefaultLanguage = startingLanguage,
                            ActivitiesPerPage = 20,
                            EnableAkisment = false,
                            EnableSocialLogins = false,
                            EnablePolls = true
                        };
                        _settingsService.Add(settings);

                        unitOfWork.Commit();
                    }
                }
                catch (Exception ex)
                {
                    unitOfWork.Rollback();
                    installerResult.Exception = ex.InnerException;
                    installerResult.Message = "Error creating the initial data >> Settings";
                    installerResult.Successful = false;
                    return installerResult;
                }
            }


            // Now we have saved the above we can create the rest of the data
            using (var unitOfWork = _UnitOfWorkManager.NewUnitOfWork())
            {
                try
                {
                    // If the admin user exists then don't do anything else
                    if (_membershipService.GetUser("admin") == null)
                    {
                        // Set up the initial permissions
                        var readOnly = new Permission { Name = "Read Only" };
                        var deletePosts = new Permission { Name = "Delete Posts" };
                        var editPosts = new Permission { Name = "Edit Posts" };
                        var stickyTopics = new Permission { Name = "Sticky Topics" };
                        var lockTopics = new Permission { Name = "Lock Topics" };
                        var voteInPolls = new Permission { Name = "Vote In Polls" };
                        var createPolls = new Permission { Name = "Create Polls" };
                        var createTopics = new Permission { Name = "Create Topics" };
                        var attachFiles = new Permission { Name = "Attach Files" };
                        var denyAccess = new Permission { Name = "Deny Access" };

                        _permissionService.Add(readOnly);
                        _permissionService.Add(deletePosts);
                        _permissionService.Add(editPosts);
                        _permissionService.Add(stickyTopics);
                        _permissionService.Add(lockTopics);
                        _permissionService.Add(voteInPolls);
                        _permissionService.Add(createPolls);
                        _permissionService.Add(createTopics);
                        _permissionService.Add(attachFiles);
                        _permissionService.Add(denyAccess);

                        // create the admin user and put him in the admin role
                        var admin = new MembershipUser
                        {
                            Email = "*****@*****.**",
                            UserName = "******",
                            Password = "******",
                            IsApproved = true,
                            DisableEmailNotifications = false,
                            DisablePosting = false,
                            DisablePrivateMessages = false
                        };
                        _membershipService.CreateUser(admin);

                        // Do a save changes just in case
                        unitOfWork.SaveChanges();

                        // Put the admin in the admin role
                        var adminRole = _roleService.GetRole("Admin");
                        admin.Roles = new List<MembershipRole> { adminRole };

                        unitOfWork.Commit();
                    }
                }
                catch (Exception ex)
                {
                    unitOfWork.Rollback();
                    installerResult.Exception = ex.InnerException;
                    installerResult.Message = "Error creating the initial data >> Admin user & Permissions";
                    installerResult.Successful = false;
                    return installerResult;
                }
            }

            // Do this so search works and doesn't create a null reference.
            _luceneService.UpdateIndex();

            return installerResult;
        }
Example #15
0
 public Settings Add(Settings settings)
 {
     return _settingsRepository.Add(settings);
 }
Example #16
0
        public static TopicViewModel CreateTopicViewModel(Topic topic,
                                                    PermissionSet permission,
                                                    List<Post> posts,
                                                    Post starterPost,
                                                    int? pageIndex,
                                                    int? totalCount,
                                                    int? totalPages,
                                                    MembershipUser loggedOnUser,
                                                    Settings settings,
                                                    bool getExtendedData = false)
        {

            var topicNotificationService = ServiceFactory.Get<ITopicNotificationService>();
            var pollAnswerService = ServiceFactory.Get<IPollAnswerService>();
            var voteService = ServiceFactory.Get<IVoteService>();
            var favouriteService = ServiceFactory.Get<IFavouriteService>();

            var userIsAuthenticated = loggedOnUser != null;

            // Check for online status
            var date = DateTime.UtcNow.AddMinutes(-AppConstants.TimeSpanInMinutesToShowMembers);

            var viewModel = new TopicViewModel
            {
                Permissions = permission,
                Topic = topic,
                Views = topic.Views,
                DisablePosting = loggedOnUser != null && (loggedOnUser.DisablePosting == true),
                PageIndex = pageIndex,
                TotalCount = totalCount,
                TotalPages = totalPages,
                LastPostPermaLink = string.Concat(topic.NiceUrl, "?", AppConstants.PostOrderBy, "=", AppConstants.AllPosts, "#comment-", topic.LastPost.Id),
                MemberIsOnline = topic.User.LastActivityDate > date,
            };
          
            if (starterPost == null)
            {
                starterPost = posts.FirstOrDefault(x => x.IsTopicStarter);
            }

            // Get votes for all posts
            var postIds = posts.Select(x => x.Id).ToList();
            postIds.Add(starterPost.Id);

            // Get all votes by post
            var votes = voteService.GetVotesByPosts(postIds);

            // Get all favourites for this user
            var allFavourites = favouriteService.GetByTopic(topic.Id);

            // Map the votes
            var startPostVotes = votes.Where(x => x.Post.Id == starterPost.Id).ToList();
            var startPostFavs = allFavourites.Where(x => x.Post.Id == starterPost.Id).ToList();

            // Create the starter post viewmodel
            viewModel.StarterPost = CreatePostViewModel(starterPost, startPostVotes, permission, topic, loggedOnUser, settings, startPostFavs);

            // Map data from the starter post viewmodel
            viewModel.VotesUp = startPostVotes.Count(x => x.Amount > 0);
            viewModel.VotesDown = startPostVotes.Count(x => x.Amount < 0);
            viewModel.Answers = totalCount != null ? (int)totalCount : posts.Count() - 1;

            // Create the ALL POSTS view models
            viewModel.Posts = CreatePostViewModels(posts, votes, permission, topic, loggedOnUser, settings, allFavourites);

            // ########### Full topic need everything   

            if (getExtendedData)
            {
                // See if the user has subscribed to this topic or not
                var isSubscribed = userIsAuthenticated && (topicNotificationService.GetByUserAndTopic(loggedOnUser, topic).Any());
                viewModel.IsSubscribed = isSubscribed;

                // See if the topic has a poll, and if so see if this user viewing has already voted
                if (topic.Poll != null)
                {
                    // There is a poll and a user
                    // see if the user has voted or not

                    viewModel.Poll = new PollViewModel
                    {
                        Poll = topic.Poll,
                        UserAllowedToVote = permission[SiteConstants.Instance.PermissionVoteInPolls].IsTicked
                    };

                    var answers = pollAnswerService.GetAllPollAnswersByPoll(topic.Poll);
                    if (answers.Any())
                    {
                        var pollvotes = answers.SelectMany(x => x.PollVotes).ToList();
                        if (userIsAuthenticated)
                        {
                            viewModel.Poll.UserHasAlreadyVoted = (pollvotes.Count(x => x.User.Id == loggedOnUser.Id) > 0);
                        }
                        viewModel.Poll.TotalVotesInPoll = pollvotes.Count();
                    }
                }
            }

            return viewModel;
        }
Example #17
0
        public static List<TopicViewModel> CreateTopicViewModels(List<Topic> topics, 
                                                                IRoleService roleService, 
                                                                MembershipRole usersRole,
                                                                MembershipUser loggedOnUser,
                                                                List<Category> allowedCategories, 
                                                                Settings settings)
        {
            // Get all topic Ids
            var topicIds = topics.Select(x => x.Id).ToList();

            // Gets posts for topics
            var postService = ServiceFactory.Get<IPostService>();
            var posts = postService.GetPostsByTopics(topicIds, allowedCategories);
            var groupedPosts = posts.ToLookup(x => x.Topic.Id);

            // Get all permissions
            var permissions = GetPermissionsForTopics(topics, roleService, usersRole);

            // Create the view models
            var viewModels = new List<TopicViewModel>();
            foreach (var topic in topics)
            {
                var id = topic.Id;
                var permission = permissions[topic.Category];
                var topicPosts = (groupedPosts.Contains(id) ? groupedPosts[id].ToList() : new List<Post>());
                viewModels.Add(CreateTopicViewModel(topic, permission, topicPosts, null, null, null, null, loggedOnUser, settings));
            }
            return viewModels;
        }
Example #18
0
 public Settings Add(Settings settings)
 {
     return _context.Setting.Add(settings);
 }
Example #19
0
 public AdminSpamController(ILoggingService loggingService, IUnitOfWorkManager unitOfWorkManager, IMembershipService membershipService, ILocalizationService localizationService, ISettingsService settingsService, ICacheService cacheService)
     : base(loggingService, unitOfWorkManager, membershipService, localizationService, settingsService)
 {
     _cacheService = cacheService;
     _settings = SettingsService.GetSettings();
 }
Example #20
0
        public static List<TopicViewModel> CreateTopicViewModels(List<Topic> topics, 
                                                                IRoleService roleService, 
                                                                MembershipRole usersRole,
                                                                MembershipUser loggedOnUser,
                                                                Settings settings)
        {
            // Get all topic Ids
            var topicIds = topics.Select(x => x.Id).ToList();

            // Gets posts for topics
            var postService = ServiceFactory.Get<IPostService>();
            var posts = postService.GetPostsByTopics(topicIds);
            var groupedPosts = posts.ToLookup(x => x.Topic.Id);

            // Get all permissions
            var permissions = GetPermissionsForTopics(topics, roleService, usersRole);

            // Create the view models
            var viewModels = new List<TopicViewModel>();

            foreach (var topic in topics)
            {
                if (permissions.Where(perm =>
                    perm.Key.Id == topic.Category.Id).ToList().FirstOrDefault().Value.Where(perm =>
                    perm.Key == "Deny Access").FirstOrDefault().Value.IsTicked != true)
                {
                    var id = topic.Id;
                    var permission = permissions[topic.Category];
                    var topicPosts = (groupedPosts.Contains(id) ? groupedPosts[id].ToList() : new List<Post>());
                    viewModels.Add(CreateTopicViewModel(topic, permission, topicPosts, null, null, null, null, loggedOnUser, settings));
                }
            }
            return viewModels;
        }