Browse Source

CmsKit - Remove IEqulityComparer from BlogFeature

pull/7955/head
enisn 5 years ago
parent
commit
060c0c2d8d
  1. 13
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogFeature.cs
  2. 17
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogFeatureEqualityComparer.cs
  3. 5
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogFeatureManager.cs

13
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogFeature.cs

@ -5,7 +5,7 @@ using Volo.Abp.Domain.Entities.Auditing;
namespace Volo.CmsKit.Blogs
{
public class BlogFeature : FullAuditedAggregateRoot<Guid>, IEquatable<BlogFeature>
public class BlogFeature : FullAuditedAggregateRoot<Guid>
{
public Guid BlogId { get; protected set; }
@ -19,16 +19,5 @@ namespace Volo.CmsKit.Blogs
FeatureName = Check.NotNullOrWhiteSpace(featureName, nameof(featureName));
IsEnabled = isEnabled;
}
/*
TODO: Overriding Equals is not a good practice for entities (see https://github.com/abpframework/abp/issues/1728)
Also, the implementation is not a true equal implementation. It just special comparison for a specific case
(used in BlogFeatureManager.GetListAsync). Remove Equals and just do the logic in-place, or create a static
method like BlogFeature.IsSameBlogFeature(BlogFeature other).
*/
public bool Equals(BlogFeature other)
{
return BlogId == other?.BlogId && FeatureName == other?.FeatureName;
}
}
}

17
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogFeatureEqualityComparer.cs

@ -0,0 +1,17 @@
using System.Collections.Generic;
namespace Volo.CmsKit.Blogs
{
public class BlogFeatureEqualityComparer : IEqualityComparer<BlogFeature>
{
public bool Equals(BlogFeature x, BlogFeature y)
{
return x?.BlogId == y?.BlogId && x?.FeatureName == y?.FeatureName;
}
public int GetHashCode(BlogFeature obj)
{
return obj.GetHashCode();
}
}
}

5
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogFeatureManager.cs

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Domain.Services;
@ -30,9 +31,9 @@ namespace Volo.CmsKit.Blogs
*/
var defaultFeatures = await DefaultBlogFeatureProvider.GetDefaultFeaturesAsync(blogId);
defaultFeatures.ForEach(x => blogFeatures.AddIfNotContains(x));
defaultFeatures.ForEach(x => blogFeatures.Add(x));
return blogFeatures;
return blogFeatures.Distinct(new BlogFeatureEqualityComparer()).ToList();
}
public async Task SetAsync(Guid blogId, string featureName, bool isEnabled)

Loading…
Cancel
Save