Skip to content

Commit

Permalink
SoftDelete V1.1.0 (Bool and DateTime?)
Browse files Browse the repository at this point in the history
  • Loading branch information
fulviocanducci committed Sep 30, 2020
1 parent afc354a commit ddb905f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 deletions.
4 changes: 3 additions & 1 deletion Canducci.SoftDelete/Canducci.SoftDelete.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Canducci</Authors>
<Company>Canducci</Company>
<Description>Version 1.0 SoftDelete</Description>
<Description>Version 1.1.0 SoftDelete (bool and DateTime?)</Description>
<PackageIcon>remove.jpg</PackageIcon>
<RepositoryUrl>https://github.com/fulviocanducci/Canducci.SoftDelete</RepositoryUrl>
<RepositoryType>GIT</RepositoryType>
<PackageTags>EntityFrameworkCore ORM NetCore Entity EntityFramework</PackageTags>
<PackageProjectUrl>https://github.com/fulviocanducci/Canducci.SoftDelete</PackageProjectUrl>
<Version>1.1.0</Version>
<PackageReleaseNotes>Version 1.1.0 SoftDelete (bool and DateTime?)</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
Expand Down
16 changes: 10 additions & 6 deletions Canducci.SoftDelete/Extensions/AddInterceptorMethodsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ namespace Canducci.SoftDelete.Extensions
{
public static class AddInterceptorMethodsExtensions
{
public static DbContextOptionsBuilder AddInterceptorSoftDeleteDateTime(this DbContextOptionsBuilder optionsBuilder)
public static DbContextOptionsBuilder AddInterceptorSoftDeleteDateTime(
this DbContextOptionsBuilder optionsBuilder
)
{
optionsBuilder.AddInterceptors(SoftDeleteDateTimeSaveChangesInterceptor.Create());
return optionsBuilder;
return optionsBuilder
.AddInterceptors(SoftDeleteDateTimeSaveChangesInterceptor.Create());
}
public static DbContextOptionsBuilder AddInterceptorSoftDeleteBool(this DbContextOptionsBuilder optionsBuilder)
public static DbContextOptionsBuilder AddInterceptorSoftDeleteBool(
this DbContextOptionsBuilder optionsBuilder
)
{
optionsBuilder.AddInterceptors(SoftDeleteBoolSaveChangesInterceptor.Create());
return optionsBuilder;
return optionsBuilder
.AddInterceptors(SoftDeleteBoolSaveChangesInterceptor.Create());
}
}
}
16 changes: 10 additions & 6 deletions Canducci.SoftDelete/Extensions/HasQueryFilterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ namespace Canducci.SoftDelete.Extensions
{
public static class HasQueryFilterExtensions
{
public static EntityTypeBuilder<T> HasQueryFilterSoftDeleteDateTime<T>(this EntityTypeBuilder<T> option)
where T : class
public static EntityTypeBuilder<T> HasQueryFilterSoftDeleteDateTime<T>(
this EntityTypeBuilder<T> option
) where T : class
{
return option.HasQueryFilter(x => ((ISoftDeleteDateTime)x).DeletedAt == null);
return option
.HasQueryFilter(x => ((ISoftDeleteDateTime)x).DeletedAt == null);
}
public static EntityTypeBuilder<T> HasQueryFilterSoftDeleteBool<T>(this EntityTypeBuilder<T> option)
where T : class
public static EntityTypeBuilder<T> HasQueryFilterSoftDeleteBool<T>(
this EntityTypeBuilder<T> option
) where T : class
{
return option.HasQueryFilter(x => ((ISoftDeleteBool)x).DeletedAt == false);
return option
.HasQueryFilter(x => ((ISoftDeleteBool)x).DeletedAt == false);
}
}

Expand Down
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,23 @@ PM> Install-Package Canducci.SoftDelete

Declare o namespace `using Canducci.SoftDelete;` and implementation `class`, example:

#### - DateTime?

```csharp
public class Animal: ISoftDeleteDateTime
{
...
public DateTime? DeletedAt { get; }
public DateTime? DeletedAt { get; } = null;
}
```

#### - Bool

```csharp
public class People: ISoftDeleteBool
{
...
public bool DeletedAt { get; } = false;
}
```

Expand All @@ -35,7 +47,8 @@ public class DatabaseContext : DbContext
optionsBuilder.UseSqlite("Data Source = db.db", options =>
{
})
.AddInterceptorSoftDelete(); // <-- this
.AddInterceptorSoftDeleteDateTime() // DateTime?
.AddInterceptorSoftDeleteBool(); // Boolean
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
Expand All @@ -51,7 +64,16 @@ public class DatabaseContext : DbContext
.HasMaxLength(100);
options.Property(x => x.DeletedAt)
.HasColumnName("deleted_at");
options.HasQueryFilter(x => x.DeletedAt == null); // <--this
options.HasQueryFilterSoftDeleteDateTime(); // DateTime?
});
modelBuilder.Entity<People>(options =>
{
options.ToTable("people");
options.HasKey(x => x.Id);
options.Property(x => x.Id).HasColumnName("id");
options.Property(x => x.Name).HasColumnName("name").IsRequired().HasMaxLength(100);
options.Property(x => x.DeletedAt).HasColumnName("deleted_at").HasDefaultValue(false);
options.HasQueryFilterSoftDeleteBool(); // Bool
});
}
}
Expand Down

0 comments on commit ddb905f

Please sign in to comment.