public static PageVersion UpdatePage(IScribeDatabase database, User user, PageView view, Action <PageView> action, ApprovalStatus status = ApprovalStatus.None, bool published = false) { var service = new ScribeService(database, null, GetSearchService(), user); action(view); service.SavePage(view); database.SaveChanges(); switch (status) { case ApprovalStatus.Approved: service.UpdatePage(new PageUpdate { Id = view.Id, Type = PageUpdateType.Approve }); break; case ApprovalStatus.Rejected: service.UpdatePage(new PageUpdate { Id = view.Id, Type = PageUpdateType.Reject }); break; } if (published) { service.UpdatePage(new PageUpdate { Id = view.Id, Type = PageUpdateType.Publish }); } database.SaveChanges(); return(database.PageVersions.OrderByDescending(x => x.PageId == view.Id).First()); }
public static SettingsView AddSettings(IScribeDatabase database, SettingsView settings) { var service = SiteSettings.Load(database); service.Apply(settings); service.Save(); database.SaveChanges(); return(settings); }
private User AddOrUpdateUser(string userName, string password, SearchResult result) { result?.GetDirectoryEntry(); var user = new User { EmailAddress = GetProperty(result?.Properties["mail"], string.Empty), DisplayName = $"{GetProperty(result?.Properties["givenname"], string.Empty)} {GetProperty(result?.Properties["sn"], string.Empty)}", IsActiveDirectory = result != null, IsEnabled = true, Tags = string.Empty, UserName = userName }; if (user.DisplayName == " ") { user.DisplayName = userName; } if (user.EmailAddress == string.Empty) { user.EmailAddress = "*****@*****.**"; } user.SetPassword(password); var foundUser = _database.Users.FirstOrDefault(x => x.UserName == userName); if (foundUser != null) { foundUser.EmailAddress = user.EmailAddress; foundUser.DisplayName = user.DisplayName; foundUser.IsActiveDirectory = true; foundUser.SetPassword(password); user = foundUser; } _database.Users.AddOrUpdate(user); _database.SaveChanges(); return(user); }
public static PageVersion AddPage(IScribeDatabase database, string title, string content, User user, ApprovalStatus status = ApprovalStatus.None, bool published = false, bool homepage = false, params string[] tags) { var service = new ScribeService(database, null, GetSearchService(), user); var view = service.SavePage(new PageView { ApprovalStatus = status, Title = title, Text = content, Tags = tags }); switch (status) { case ApprovalStatus.Approved: service.UpdatePage(new PageUpdate { Id = view.Id, Type = PageUpdateType.Approve }); break; case ApprovalStatus.Rejected: service.UpdatePage(new PageUpdate { Id = view.Id, Type = PageUpdateType.Reject }); break; } if (published) { service.UpdatePage(new PageUpdate { Id = view.Id, Type = PageUpdateType.Publish }); } if (homepage) { var settings = SiteSettings.Load(database); settings.FrontPagePrivateId = view.Id; settings.FrontPagePublicId = view.Id; settings.Save(); database.SaveChanges(); } return(database.PageVersions.OrderByDescending(x => x.PageId == view.Id).First()); }
public PageView BeginEditingPage(int id) { VerifyAccess("You must be authenticated to begin editing page."); var page = GetCurrentPagesQuery() .FirstOrDefault(x => x.PageId == id); if (page == null) { throw new PageNotFoundException("Failed to find the page with that ID."); } var timeoutThreshold = DateTime.UtcNow.Subtract(Constants.EditingTimeout); if (page.EditingOn <= timeoutThreshold) { page.EditingBy = _user; page.EditingOn = DateTime.UtcNow; _database.SaveChanges(); } var response = page.ToView(Converter); response.Html = Converter.ToHtml(response.Text); response.Files = GetFiles(new PagedRequest { PerPage = int.MaxValue }).Results; response.Pages = GetPages(new PagedRequest { PerPage = int.MaxValue }).Results.Select(x => new PageReference { Id = x.Id, Title = x.Title, TitleForLink = x.TitleForLink }).ToList(); return(response); }