diff --git a/BlogEngine/BlogEngine.Core/Data/BlogRepository.cs b/BlogEngine/BlogEngine.Core/Data/BlogRepository.cs index e786769c3..7187b845b 100644 --- a/BlogEngine/BlogEngine.Core/Data/BlogRepository.cs +++ b/BlogEngine/BlogEngine.Core/Data/BlogRepository.cs @@ -52,7 +52,7 @@ public Models.Blog FindById(Guid id) if (!(Blog.CurrentInstance.IsPrimary && Security.IsAdministrator)) throw new UnauthorizedAccessException(); - var blog = Blog.Blogs.Where(b => b.Id == id).FirstOrDefault(); + var blog = Blog.Blogs.FirstOrDefault(b => b.Id == id); return ToJson(blog); } @@ -92,7 +92,7 @@ public bool Update(Models.Blog blog) throw new UnauthorizedAccessException(); try { - var coreBlog = Blog.Blogs.Where(b => b.Id == blog.Id).FirstOrDefault(); + var coreBlog = Blog.Blogs.FirstOrDefault(b => b.Id == blog.Id); return Save(coreBlog, blog); } catch (Exception) @@ -113,7 +113,7 @@ public bool Remove(Guid id) throw new UnauthorizedAccessException(); try { - var blog = Blog.Blogs.Where(b => b.Id == id).FirstOrDefault(); + var blog = Blog.Blogs.FirstOrDefault(b => b.Id == id); blog.Delete(); blog.Save(); return true; diff --git a/BlogEngine/BlogEngine.Core/Data/CategoryRepository.cs b/BlogEngine/BlogEngine.Core/Data/CategoryRepository.cs index 199cb1b07..840eaa826 100644 --- a/BlogEngine/BlogEngine.Core/Data/CategoryRepository.cs +++ b/BlogEngine/BlogEngine.Core/Data/CategoryRepository.cs @@ -42,7 +42,7 @@ public IEnumerable Find(int take = 10, int skip = 0, string filter // add categories without posts foreach (var c in Category.Categories) { - var x = items.Where(i => i.Id == c.Id).FirstOrDefault(); + var x = items.FirstOrDefault(i => i.Id == c.Id); if (x == null) items.Add(new CategoryItem { Id = c.Id, Parent = OptionById(c.Parent), Title = c.Title, Description = c.Description, Count = 0 }); } @@ -87,11 +87,11 @@ public CategoryItem FindById(Guid id) // add categories without posts foreach (var c in Category.Categories) { - var x = items.Where(i => i.Id == c.Id).FirstOrDefault(); + var x = items.FirstOrDefault(i => i.Id == c.Id); if (x == null) items.Add(new CategoryItem { Id = c.Id, Parent = OptionById(c.Parent), Title = c.Title, Description = c.Description, Count = 0 }); } - return items.Where(c => c.Id == id).FirstOrDefault(); + return items.FirstOrDefault(c => c.Id == id); } /// /// Add new item diff --git a/BlogEngine/BlogEngine.Core/Data/CommentsRepository.cs b/BlogEngine/BlogEngine.Core/Data/CommentsRepository.cs index 7b52074d5..0aa5b4c69 100644 --- a/BlogEngine/BlogEngine.Core/Data/CommentsRepository.cs +++ b/BlogEngine/BlogEngine.Core/Data/CommentsRepository.cs @@ -82,7 +82,7 @@ public CommentItem Add(CommentDetail item) var c = new Comment(); try { - var post = Post.Posts.Where(p => p.Id == item.PostId).FirstOrDefault(); + var post = Post.Posts.FirstOrDefault(p => p.Id == item.PostId); c.Id = Guid.NewGuid(); c.ParentId = item.ParentId; @@ -104,7 +104,7 @@ public CommentItem Add(CommentDetail item) post.AddComment(c); post.Save(); - var newComm = post.Comments.Where(cm => cm.Content == c.Content).FirstOrDefault(); + var newComm = post.Comments.FirstOrDefault(cm => cm.Content == c.Content); return Json.GetComment(newComm, post.Comments); } catch (Exception ex) diff --git a/BlogEngine/BlogEngine.Core/Data/CustomFieldRepository.cs b/BlogEngine/BlogEngine.Core/Data/CustomFieldRepository.cs index 8cccea620..f6752c682 100644 --- a/BlogEngine/BlogEngine.Core/Data/CustomFieldRepository.cs +++ b/BlogEngine/BlogEngine.Core/Data/CustomFieldRepository.cs @@ -49,7 +49,7 @@ public CustomField FindById(string type, string id, string key) if (!Security.IsAuthorizedTo(Rights.AccessAdminPages)) throw new UnauthorizedAccessException(); - var cf = Find("").Where(f => f.CustomType == type && f.ObjectId == id && f.Key == key).FirstOrDefault(); + var cf = Find("").FirstOrDefault(f => f.CustomType == type && f.ObjectId == id && f.Key == key); return cf; } @@ -157,10 +157,10 @@ public void ClearCustomFields(string type, string id) bool AlreadyExists(CustomField item) { - var field = CustomFieldsParser.CachedFields.Where(f => f.BlogId == item.BlogId + var field = CustomFieldsParser.CachedFields.FirstOrDefault(f => f.BlogId == item.BlogId && f.CustomType == item.CustomType && f.ObjectId == item.ObjectId - && f.Key == item.Key).FirstOrDefault(); + && f.Key == item.Key); return field != null; } diff --git a/BlogEngine/BlogEngine.Core/Data/PageRepository.cs b/BlogEngine/BlogEngine.Core/Data/PageRepository.cs index f9ba9a24d..994bab443 100644 --- a/BlogEngine/BlogEngine.Core/Data/PageRepository.cs +++ b/BlogEngine/BlogEngine.Core/Data/PageRepository.cs @@ -189,8 +189,8 @@ static string GetUniqueSlug(string slug) private static bool IsUniqueSlug(string slug) { - return Page.Pages.Where(p => p.Slug != null && p.Slug.ToLower() == slug.ToLower()) - .FirstOrDefault() == null ? true : false; + return Page.Pages + .FirstOrDefault(p => p.Slug != null && p.Slug.ToLower() == slug.ToLower()) == null ? true : false; } // if description not set, use first 100 chars in the post diff --git a/BlogEngine/BlogEngine.Core/Data/PostRepository.cs b/BlogEngine/BlogEngine.Core/Data/PostRepository.cs index 71939f525..df347e25e 100644 --- a/BlogEngine/BlogEngine.Core/Data/PostRepository.cs +++ b/BlogEngine/BlogEngine.Core/Data/PostRepository.cs @@ -172,7 +172,7 @@ static void UpdatePostCategories(Post post, List categories) foreach (var cat in categories) { // add if category does not exist - var existingCat = Category.Categories.Where(c => c.Title == cat.Title).FirstOrDefault(); + var existingCat = Category.Categories.FirstOrDefault(c => c.Title == cat.Title); if (existingCat == null) { var repo = new CategoryRepository(); @@ -208,7 +208,7 @@ static List FilterTags(List tags) foreach (var t in tags) { - if (!uniqueTags.Any(u => u.TagName == t.TagName)) + if (uniqueTags.All(u => u.TagName != t.TagName)) { uniqueTags.Add(t); } @@ -233,8 +233,8 @@ static string GetUniqueSlug(string slug) static bool IsUniqueSlug(string slug) { - return Post.ApplicablePosts.Where(p => p.Slug != null && p.Slug.ToLower() == slug.ToLower()) - .FirstOrDefault() == null ? true : false; + return Post.ApplicablePosts + .FirstOrDefault(p => p.Slug != null && p.Slug.ToLower() == slug.ToLower()) == null ? true : false; } // if description not set, use first 100 chars in the post diff --git a/BlogEngine/BlogEngine.Core/Data/RolesRepository.cs b/BlogEngine/BlogEngine.Core/Data/RolesRepository.cs index 26fe15ce8..da4bca1eb 100644 --- a/BlogEngine/BlogEngine.Core/Data/RolesRepository.cs +++ b/BlogEngine/BlogEngine.Core/Data/RolesRepository.cs @@ -53,7 +53,7 @@ public RoleItem FindById(string id) var roles = new List(); roles.AddRange(System.Web.Security.Roles.GetAllRoles().Select(r => new Data.Models.RoleItem { RoleName = r, IsSystemRole = Security.IsSystemRole(r) })); - return roles.Where(r => r.RoleName.ToLower() == id.ToLower()).FirstOrDefault(); + return roles.FirstOrDefault(r => r.RoleName.ToLower() == id.ToLower()); } /// @@ -101,7 +101,7 @@ public bool Update(RoleItem role, string oldRole) if (!Security.IsAuthorizedTo(Rights.EditRoles)) throw new System.UnauthorizedAccessException(); - var updateRole = System.Web.Security.Roles.GetAllRoles().Where(r => r.ToString() == oldRole).FirstOrDefault(); + var updateRole = Roles.GetAllRoles().FirstOrDefault(r => r.ToString() == oldRole); if (updateRole == null) throw new ApplicationException("Role not found"); @@ -172,7 +172,7 @@ public IEnumerable GetRoleRights(string role) var category = rightDetails == null ? RightCategory.General : rightDetails.Category; - var group = groups.Where(g => g.Title == category.ToString()).FirstOrDefault(); + var group = groups.FirstOrDefault(g => g.Title == category.ToString()); var prm = new Permission(); var rt = Right.GetRightByName(right.ToString()); diff --git a/BlogEngine/BlogEngine.Core/Data/Services/CustomFieldsParser.cs b/BlogEngine/BlogEngine.Core/Data/Services/CustomFieldsParser.cs index f92f8e838..92e4debf0 100644 --- a/BlogEngine/BlogEngine.Core/Data/Services/CustomFieldsParser.cs +++ b/BlogEngine/BlogEngine.Core/Data/Services/CustomFieldsParser.cs @@ -117,8 +117,8 @@ static string ReplaceCustomFields(string html) if (s[1] == "POST") { - var cf = postFields.Where(f => f.Key.ToLower() == key.ToLower() - && f.ObjectId.ToLower() == id.ToLower()).FirstOrDefault(); + var cf = postFields.FirstOrDefault(f => f.Key.ToLower() == key.ToLower() + && f.ObjectId.ToLower() == id.ToLower()); if (cf != null) val = cf.Value; @@ -126,8 +126,8 @@ static string ReplaceCustomFields(string html) if (s[1] == "THEME") { - var cf = themeFields.Where(f => f.Key.ToLower() == key.ToLower() - && f.ObjectId.ToLower() == id.ToLower()).FirstOrDefault(); + var cf = themeFields.FirstOrDefault(f => f.Key.ToLower() == key.ToLower() + && f.ObjectId.ToLower() == id.ToLower()); if (cf != null) val = cf.Value; diff --git a/BlogEngine/BlogEngine.Core/Data/Services/Json.cs b/BlogEngine/BlogEngine.Core/Data/Services/Json.cs index c89006bee..e23501d19 100644 --- a/BlogEngine/BlogEngine.Core/Data/Services/Json.cs +++ b/BlogEngine/BlogEngine.Core/Data/Services/Json.cs @@ -141,7 +141,7 @@ public static CommentItem GetComment(Comment c, List postComments) jc.Title = c.Teaser.Length < 80 ? c.Teaser : c.Teaser.Substring(0, 80) + "..."; jc.DateCreated = c.DateCreated.ToString("yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture); jc.RelativeLink = c.RelativeLink; - jc.HasChildren = postComments.Where(pc => pc.ParentId == c.Id).FirstOrDefault() != null; + jc.HasChildren = postComments.FirstOrDefault(pc => pc.ParentId == c.Id) != null; jc.Avatar = Gravatar(c); return jc; } @@ -223,7 +223,7 @@ static SelectOption ItemParent(Guid? id) if (id == null || id == Guid.Empty) return null; - var item = Category.Categories.Where(c => c.Id == id).FirstOrDefault(); + var item = Category.Categories.FirstOrDefault(c => c.Id == id); return new SelectOption { OptionName = item.Title, OptionValue = item.Id.ToString() }; } diff --git a/BlogEngine/BlogEngine.Core/Data/StatsRepository.cs b/BlogEngine/BlogEngine.Core/Data/StatsRepository.cs index d4b027922..3612d5607 100644 --- a/BlogEngine/BlogEngine.Core/Data/StatsRepository.cs +++ b/BlogEngine/BlogEngine.Core/Data/StatsRepository.cs @@ -26,11 +26,11 @@ public Stats Get() if (!Security.IsAuthorizedTo(Rights.EditOtherUsersPosts)) postList = postList.Where(p => p.Author.ToLower() == Security.CurrentUser.Identity.Name.ToLower()).ToList(); - stats.PublishedPostsCount = postList.Where(p => p.IsPublished == true).Count(); - stats.DraftPostsCount = postList.Where(p => p.IsPublished == false).Count(); + stats.PublishedPostsCount = postList.Count(p => p.IsPublished == true); + stats.DraftPostsCount = postList.Count(p => p.IsPublished == false); - stats.PublishedPagesCount = Page.Pages.Where(p => p.IsPublished == true && p.IsDeleted == false).Count(); - stats.DraftPagesCount = Page.Pages.Where(p => p.IsPublished == false && p.IsDeleted == false).Count(); + stats.PublishedPagesCount = Page.Pages.Count(p => p.IsPublished == true && p.IsDeleted == false); + stats.DraftPagesCount = Page.Pages.Count(p => p.IsPublished == false && p.IsDeleted == false); CountComments(stats); @@ -70,9 +70,9 @@ void CountComments(Stats stats) if (post.Author.ToLower() != Security.CurrentUser.Identity.Name.ToLower()) continue; - stats.PublishedCommentsCount += post.Comments.Where(c => c.IsPublished == true && c.IsDeleted == false).Count(); - stats.UnapprovedCommentsCount += post.Comments.Where(c => c.IsPublished == false && c.IsSpam == false && c.IsDeleted == false).Count(); - stats.SpamCommentsCount += post.Comments.Where(c => c.IsPublished == false && c.IsSpam == true && c.IsDeleted == false).Count(); + stats.PublishedCommentsCount += post.Comments.Count(c => c.IsPublished == true && c.IsDeleted == false); + stats.UnapprovedCommentsCount += post.Comments.Count(c => c.IsPublished == false && c.IsSpam == false && c.IsDeleted == false); + stats.SpamCommentsCount += post.Comments.Count(c => c.IsPublished == false && c.IsSpam == true && c.IsDeleted == false); } } diff --git a/BlogEngine/BlogEngine.Core/Data/TrashRepository.cs b/BlogEngine/BlogEngine.Core/Data/TrashRepository.cs index 9ebc34525..b2f50165f 100644 --- a/BlogEngine/BlogEngine.Core/Data/TrashRepository.cs +++ b/BlogEngine/BlogEngine.Core/Data/TrashRepository.cs @@ -152,11 +152,11 @@ public bool Restore(string trashType, Guid id) } break; case "Post": - var delPost = Post.DeletedPosts.Where(p => p.Id == id).FirstOrDefault(); + var delPost = Post.DeletedPosts.FirstOrDefault(p => p.Id == id); if (delPost != null) delPost.Restore(); break; case "Page": - var delPage = Page.DeletedPages.Where(pg => pg.Id == id).FirstOrDefault(); + var delPage = Page.DeletedPages.FirstOrDefault(pg => pg.Id == id); if (delPage != null) delPage.Restore(); break; default: @@ -189,11 +189,11 @@ public bool Purge(string trashType, Guid id) } break; case "Post": - var delPost = Post.DeletedPosts.Where(p => p.Id == id).FirstOrDefault(); + var delPost = Post.DeletedPosts.FirstOrDefault(p => p.Id == id); if (delPost != null) delPost.Purge(); break; case "Page": - var delPage = Page.DeletedPages.Where(pg => pg.Id == id).FirstOrDefault(); + var delPage = Page.DeletedPages.FirstOrDefault(pg => pg.Id == id); if (delPage != null) delPage.Purge(); break; default: diff --git a/BlogEngine/BlogEngine.Core/Data/ViewModels/DashboardVM.cs b/BlogEngine/BlogEngine.Core/Data/ViewModels/DashboardVM.cs index bee28943b..a12909082 100644 --- a/BlogEngine/BlogEngine.Core/Data/ViewModels/DashboardVM.cs +++ b/BlogEngine/BlogEngine.Core/Data/ViewModels/DashboardVM.cs @@ -123,9 +123,9 @@ private void LoadPosts() foreach (var p in posts) { - ApprovedCommentsCnt += p.Comments.Where(c => c.IsPublished && !c.IsDeleted).Count(); - PendingCommentsCnt += p.Comments.Where(c => !c.IsPublished && !c.IsSpam && !c.IsDeleted).Count(); - SpamCommentsCnt += p.Comments.Where(c => !c.IsPublished && c.IsSpam && !c.IsDeleted).Count(); + ApprovedCommentsCnt += p.Comments.Count(c => c.IsPublished && !c.IsDeleted); + PendingCommentsCnt += p.Comments.Count(c => !c.IsPublished && !c.IsSpam && !c.IsDeleted); + SpamCommentsCnt += p.Comments.Count(c => !c.IsPublished && c.IsSpam && !c.IsDeleted); _comments.AddRange(p.Comments); } } @@ -146,7 +146,7 @@ private void LoadTrash() { var posts = Post.DeletedPosts; _trash = new List(); - if (posts.Count() > 0) + if (posts.Any()) { foreach (var p in posts) { @@ -162,7 +162,7 @@ private void LoadTrash() } } var pages = Page.DeletedPages; - if (pages.Count() > 0) + if (pages.Any()) { foreach (var page in pages) { @@ -187,7 +187,7 @@ private void LoadTrash() comms.AddRange(p.DeletedComments); } - if (comms.Count() > 0) + if (comms.Any()) { foreach (var c in comms) { diff --git a/BlogEngine/BlogEngine.Core/Helpers/BlogGenerator.cs b/BlogEngine/BlogEngine.Core/Helpers/BlogGenerator.cs index d17ef1838..8f1bc8f32 100644 --- a/BlogEngine/BlogEngine.Core/Helpers/BlogGenerator.cs +++ b/BlogEngine/BlogEngine.Core/Helpers/BlogGenerator.cs @@ -116,7 +116,7 @@ public static bool ValidateProperties(string blogName, string userName, string e return false; } - if (Blog.Blogs.Where(b => b.Name.ToLower() == blogName.ToLower()).FirstOrDefault() != null) + if (Blog.Blogs.FirstOrDefault(b => b.Name.ToLower() == blogName.ToLower()) != null) { message = "Blog with this name already exists; Please select different name."; return false; diff --git a/BlogEngine/BlogEngine.Core/Providers/DbProvider/DbBlogProvider.cs b/BlogEngine/BlogEngine.Core/Providers/DbProvider/DbBlogProvider.cs index 6b45e81ca..5ad88a68e 100644 --- a/BlogEngine/BlogEngine.Core/Providers/DbProvider/DbBlogProvider.cs +++ b/BlogEngine/BlogEngine.Core/Providers/DbProvider/DbBlogProvider.cs @@ -707,7 +707,7 @@ public override bool SetupNewBlog(Blog newBlog, string userName, string email, s { if (conn.HasConnection) { - Blog existingBlog = Blog.Blogs.Where(b => b.Name == "Template").FirstOrDefault(); + Blog existingBlog = Blog.Blogs.FirstOrDefault(b => b.Name == "Template"); if (existingBlog == null) existingBlog = Blog.Blogs[0]; diff --git a/BlogEngine/BlogEngine.Core/Providers/FileSystemProviders/DbFileSystemProvider.cs b/BlogEngine/BlogEngine.Core/Providers/FileSystemProviders/DbFileSystemProvider.cs index b6552a96e..040f64b4c 100644 --- a/BlogEngine/BlogEngine.Core/Providers/FileSystemProviders/DbFileSystemProvider.cs +++ b/BlogEngine/BlogEngine.Core/Providers/FileSystemProviders/DbFileSystemProvider.cs @@ -189,7 +189,7 @@ public override void DeleteDirectory(string VirtualPath) public override bool DirectoryExists(string VirtualPath) { VirtualPath = VirtualPath.VirtualPathToDbPath(); - return new FileSystem.FileStoreDb(this.connectionString).FileStoreDirectories.Where(x => x.FullPath.ToLower() == VirtualPath.ToLower() && x.BlogID == Blog.CurrentInstance.Id).Count() > 0; + return new FileSystem.FileStoreDb(this.connectionString).FileStoreDirectories.Any(x => x.FullPath.ToLower() == VirtualPath.ToLower() && x.BlogID == Blog.CurrentInstance.Id); } /// diff --git a/BlogEngine/BlogEngine.Core/Providers/XmlProvider/Settings.cs b/BlogEngine/BlogEngine.Core/Providers/XmlProvider/Settings.cs index 6fb7c0001..a9b5f9872 100644 --- a/BlogEngine/BlogEngine.Core/Providers/XmlProvider/Settings.cs +++ b/BlogEngine/BlogEngine.Core/Providers/XmlProvider/Settings.cs @@ -57,7 +57,7 @@ public override void SaveSettings(StringDictionary settings) throw new ArgumentNullException("settings"); } - var filename = string.Format("{0}settings.xml", Folder); + var filename = $"{Folder}settings.xml"; var writerSettings = new XmlWriterSettings { Indent = true }; // ------------------------------------------------------------ diff --git a/BlogEngine/BlogEngine.Core/Services/Packaging/FileSystem.cs b/BlogEngine/BlogEngine.Core/Services/Packaging/FileSystem.cs index 4a86736f8..458bf7698 100644 --- a/BlogEngine/BlogEngine.Core/Services/Packaging/FileSystem.cs +++ b/BlogEngine/BlogEngine.Core/Services/Packaging/FileSystem.cs @@ -449,7 +449,7 @@ static string PackageType(List files) /// Version number public static string GetInstalledVersion(string pkgId) { - var pkg = BlogService.InstalledFromGalleryPackages().Where(p => p.PackageId == pkgId).FirstOrDefault(); + var pkg = BlogService.InstalledFromGalleryPackages().FirstOrDefault(p => p.PackageId == pkgId); return pkg == null ? "" : pkg.Version; } diff --git a/BlogEngine/BlogEngine.Core/Services/Packaging/Gallery.cs b/BlogEngine/BlogEngine.Core/Services/Packaging/Gallery.cs index e5a455514..49af32b8f 100644 --- a/BlogEngine/BlogEngine.Core/Services/Packaging/Gallery.cs +++ b/BlogEngine/BlogEngine.Core/Services/Packaging/Gallery.cs @@ -48,9 +48,9 @@ public static void Load(List packages) if (string.IsNullOrEmpty(jp.IconUrl)) jp.IconUrl = DefaultThumbnail(""); - if (extras != null && extras.Count() > 0) + if (extras != null && extras.Any()) { - var extra = extras.Where(e => e.Id.ToLower() == pkg.Id.ToLower() + "." + pkg.Version).FirstOrDefault(); + var extra = extras.FirstOrDefault(e => e.Id.ToLower() == pkg.Id.ToLower() + "." + pkg.Version); if (extra != null) { diff --git a/BlogEngine/BlogEngine.Core/Services/Security/Security.cs b/BlogEngine/BlogEngine.Core/Services/Security/Security.cs index 46359c46c..5959efbc4 100644 --- a/BlogEngine/BlogEngine.Core/Services/Security/Security.cs +++ b/BlogEngine/BlogEngine.Core/Services/Security/Security.cs @@ -371,7 +371,7 @@ public static bool IsAuthorizedTo(Rights right) /// public static bool IsAuthorizedTo(AuthorizationCheck authCheck, IEnumerable rights) { - if (rights.Count() == 0) + if (!rights.Any()) { // Always return false for this. If there's a mistake where authorization // is being checked for on an empty collection, we don't want to return diff --git a/BlogEngine/BlogEngine.Core/Services/Syndication/BlogML/BlogReader.cs b/BlogEngine/BlogEngine.Core/Services/Syndication/BlogML/BlogReader.cs index 5357ed705..8d81ad0ce 100644 --- a/BlogEngine/BlogEngine.Core/Services/Syndication/BlogML/BlogReader.cs +++ b/BlogEngine/BlogEngine.Core/Services/Syndication/BlogML/BlogReader.cs @@ -344,7 +344,7 @@ private void LoadBlogExtendedPosts(BlogMLBlog blog) if (post.PostType == BlogPostTypes.Normal) { BlogMLPost p = post; - blogsExtended.Where(b => b.PostUrl == p.PostUrl).FirstOrDefault().BlogPost = post; + blogsExtended.FirstOrDefault(b => b.PostUrl == p.PostUrl).BlogPost = post; } } } diff --git a/BlogEngine/BlogEngine.Core/Web/Extensions/ExtensionManager.cs b/BlogEngine/BlogEngine.Core/Web/Extensions/ExtensionManager.cs index d89f5d54c..6d02aee2a 100644 --- a/BlogEngine/BlogEngine.Core/Web/Extensions/ExtensionManager.cs +++ b/BlogEngine/BlogEngine.Core/Web/Extensions/ExtensionManager.cs @@ -168,17 +168,15 @@ public static ExtensionSettings GetSettings(string extensionName, string setting if (!Blog.CurrentInstance.IsPrimary && extension.SubBlogEnabled) { - return extension.Settings.Where( - setting => setting != null + return extension.Settings.FirstOrDefault(setting => setting != null && setting.Name == settingName - && setting.BlogId == Blog.CurrentInstance.Id).FirstOrDefault(); + && setting.BlogId == Blog.CurrentInstance.Id); } var primId = Blog.Blogs.FirstOrDefault(b => b.IsPrimary).BlogId; - return extension.Settings.Where( - setting => setting != null + return extension.Settings.FirstOrDefault(setting => setting != null && setting.Name == settingName - && (setting.BlogId == primId || setting.BlogId == null)).FirstOrDefault(); + && (setting.BlogId == primId || setting.BlogId == null)); } /// diff --git a/BlogEngine/BlogEngine.Core/Web/Extensions/ManagedExtension.cs b/BlogEngine/BlogEngine.Core/Web/Extensions/ManagedExtension.cs index 0d6fc8495..ea9aa0e5d 100644 --- a/BlogEngine/BlogEngine.Core/Web/Extensions/ManagedExtension.cs +++ b/BlogEngine/BlogEngine.Core/Web/Extensions/ManagedExtension.cs @@ -121,7 +121,7 @@ public List Settings { if (!Blog.CurrentInstance.IsPrimary && SubBlogEnabled) { - if (!settings.Any(xset => xset.BlogId == Blog.CurrentInstance.Id)) + if (settings.All(xset => xset.BlogId != Blog.CurrentInstance.Id)) { var primId = Blog.Blogs.FirstOrDefault(b => b.IsPrimary).BlogId; @@ -155,7 +155,7 @@ public List BlogSettings if (!Blog.CurrentInstance.IsPrimary && SubBlogEnabled) { - if (!settings.Any(xset => xset.BlogId == Blog.CurrentInstance.Id)) + if (settings.All(xset => xset.BlogId != Blog.CurrentInstance.Id)) { List newSets = GenericHelper>.Copy( settings.Where(setItem => setItem.BlogId == primId || setItem.BlogId == null).ToList()); diff --git a/BlogEngine/BlogEngine.Tests/WebApi/BlogControllerTests.cs b/BlogEngine/BlogEngine.Tests/WebApi/BlogControllerTests.cs index 082036841..f1000303f 100644 --- a/BlogEngine/BlogEngine.Tests/WebApi/BlogControllerTests.cs +++ b/BlogEngine/BlogEngine.Tests/WebApi/BlogControllerTests.cs @@ -37,7 +37,7 @@ public void Init() public void BlogControllerGet() { var results = _ctrl.Get(0, 0); - Assert.IsTrue(results.Count() > 0); + Assert.IsTrue(results.Any()); } [TestMethod] diff --git a/BlogEngine/BlogEngine.Tests/WebApi/CategoryControllerTests.cs b/BlogEngine/BlogEngine.Tests/WebApi/CategoryControllerTests.cs index 26c4d677b..ac4500d46 100644 --- a/BlogEngine/BlogEngine.Tests/WebApi/CategoryControllerTests.cs +++ b/BlogEngine/BlogEngine.Tests/WebApi/CategoryControllerTests.cs @@ -38,7 +38,7 @@ public void Init() public void CategoryControllerGet() { var results = _ctrl.Get(0, 0); - Assert.IsTrue(results.Count() > 0); + Assert.IsTrue(results.Any()); } [TestMethod] diff --git a/BlogEngine/BlogEngine.Tests/WebApi/CommentControllerTests.cs b/BlogEngine/BlogEngine.Tests/WebApi/CommentControllerTests.cs index fc020adb6..e7bd77039 100644 --- a/BlogEngine/BlogEngine.Tests/WebApi/CommentControllerTests.cs +++ b/BlogEngine/BlogEngine.Tests/WebApi/CommentControllerTests.cs @@ -38,7 +38,7 @@ public void Init() public void CommentsControllerGet() { var results = _ctrl.Get(); - Assert.IsTrue(results.Items.Count() > 0); + Assert.IsTrue(results.Items.Any()); } //[TestMethod] diff --git a/BlogEngine/BlogEngine.Tests/WebApi/CustomFieldsControllerTests.cs b/BlogEngine/BlogEngine.Tests/WebApi/CustomFieldsControllerTests.cs index 8643a63c2..7969fef43 100644 --- a/BlogEngine/BlogEngine.Tests/WebApi/CustomFieldsControllerTests.cs +++ b/BlogEngine/BlogEngine.Tests/WebApi/CustomFieldsControllerTests.cs @@ -38,7 +38,7 @@ public void Init() public void CustomFieldsControllerGet() { var results = _ctrl.Get(); - Assert.IsTrue(results.Count() > 0); + Assert.IsTrue(results.Any()); } //[TestMethod] diff --git a/BlogEngine/BlogEngine.Tests/WebApi/PackagesControllerTests.cs b/BlogEngine/BlogEngine.Tests/WebApi/PackagesControllerTests.cs index 9c9689cfe..26f3b69f1 100644 --- a/BlogEngine/BlogEngine.Tests/WebApi/PackagesControllerTests.cs +++ b/BlogEngine/BlogEngine.Tests/WebApi/PackagesControllerTests.cs @@ -38,7 +38,7 @@ public void Init() public void PackagesControllerGet() { var results = _ctrl.Get(0, 0); - Assert.IsTrue(results.Count() > 0); + Assert.IsTrue(results.Any()); } [TestMethod] diff --git a/BlogEngine/BlogEngine.Tests/WebApi/PageControllerTests.cs b/BlogEngine/BlogEngine.Tests/WebApi/PageControllerTests.cs index 87eed29b3..44ccbcb8c 100644 --- a/BlogEngine/BlogEngine.Tests/WebApi/PageControllerTests.cs +++ b/BlogEngine/BlogEngine.Tests/WebApi/PageControllerTests.cs @@ -38,7 +38,7 @@ public void Init() public void PageControllerGet() { var results = _ctrl.Get(0, 0); - Assert.IsTrue(results.Count() > 0); + Assert.IsTrue(results.Any()); } [TestMethod] diff --git a/BlogEngine/BlogEngine.Tests/WebApi/PostControllerTests.cs b/BlogEngine/BlogEngine.Tests/WebApi/PostControllerTests.cs index 8e770c153..a9e564034 100644 --- a/BlogEngine/BlogEngine.Tests/WebApi/PostControllerTests.cs +++ b/BlogEngine/BlogEngine.Tests/WebApi/PostControllerTests.cs @@ -38,7 +38,7 @@ public void Init() public void PostControllerGet() { var results = _ctrl.Get(0, 0); - Assert.IsTrue(results.Count() > 0); + Assert.IsTrue(results.Any()); } [TestMethod] diff --git a/BlogEngine/BlogEngine.Tests/WebApi/RoleControllerTests.cs b/BlogEngine/BlogEngine.Tests/WebApi/RoleControllerTests.cs index 1bcbfcee6..a69859988 100644 --- a/BlogEngine/BlogEngine.Tests/WebApi/RoleControllerTests.cs +++ b/BlogEngine/BlogEngine.Tests/WebApi/RoleControllerTests.cs @@ -37,7 +37,7 @@ public void Init() public void RoleControllerGet() { var results = _ctrl.Get(0, 0); - Assert.IsTrue(results.Count() > 0); + Assert.IsTrue(results.Any()); } [TestMethod]