-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bruno de Souza Melo
committed
Feb 27, 2023
1 parent
1484849
commit c77b960
Showing
16 changed files
with
395 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[*.cs] | ||
|
||
# CS1591: Missing XML comment for publicly visible type or member | ||
dotnet_diagnostic.CS1591.severity = none | ||
|
||
# IDE0063: Use simple 'using' statement | ||
dotnet_diagnostic.IDE0063.severity = none |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.3.32929.385 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FFE8529B-55C4-4E15-B937-A6FEE1E9C5BA}" | ||
ProjectSection(SolutionItems) = preProject | ||
docs\Publishing.txt = docs\Publishing.txt | ||
EndProjectSection | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0553FC7C-D8CC-444A-970D-CB3B064020F5}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{3BD96AEC-23A5-44DF-ABBE-82E683AB587E}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NuvTools.AspNetCore", "src\NuvTools.AspNetCore\NuvTools.AspNetCore.csproj", "{77571ABE-3EF7-403F-ACCC-68B539B02AB6}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NuvTools.AspNetCore.EntityFrameworkCore", "src\NuvTools.AspNetCore.EntityFrameworkCore\NuvTools.AspNetCore.EntityFrameworkCore.csproj", "{A4C3BE0D-A233-4026-9AE9-8B1395418E1A}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{77571ABE-3EF7-403F-ACCC-68B539B02AB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{77571ABE-3EF7-403F-ACCC-68B539B02AB6}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{77571ABE-3EF7-403F-ACCC-68B539B02AB6}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{77571ABE-3EF7-403F-ACCC-68B539B02AB6}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{A4C3BE0D-A233-4026-9AE9-8B1395418E1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{A4C3BE0D-A233-4026-9AE9-8B1395418E1A}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{A4C3BE0D-A233-4026-9AE9-8B1395418E1A}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{A4C3BE0D-A233-4026-9AE9-8B1395418E1A}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{77571ABE-3EF7-403F-ACCC-68B539B02AB6} = {0553FC7C-D8CC-444A-970D-CB3B064020F5} | ||
{A4C3BE0D-A233-4026-9AE9-8B1395418E1A} = {0553FC7C-D8CC-444A-970D-CB3B064020F5} | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {BF8E6A9B-D224-46ED-9C99-E6DD796B4CC9} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
# nuvtools-aspnetcore | ||
# Nuv Tools ASP.NET Core Libraries | ||
|
||
Libraries with helpers to use with ASP.NET Aplications. | ||
|
||
## NuvTools.AspNetCore | ||
|
||
Common library with helpers to use with ASP.NET Aplications. | ||
|
||
## NuvTools.AspNetCore.EntityFramework | ||
|
||
EntityFramework Core helper library to use with ASP.NET Aplications. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
nuget.exe push -Source "nuvtools" -ApiKey az NuvTools.AspNetCore.7.0.0.nupkg | ||
nuget.exe push -Source "nuvtools" -ApiKey az NuvTools.AspNetCore.EntityFrameworkCore.7.0.0.nupkg |
20 changes: 20 additions & 0 deletions
20
src/NuvTools.AspNetCore.EntityFrameworkCore/Extensions/ApplicationBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace NuvTools.AspNetCore.EntityFrameworkCore.Extensions; | ||
|
||
public static class ApplicationBuilderExtensions | ||
{ | ||
public static IApplicationBuilder DatabaseMigrate<TContext>(this IApplicationBuilder app) where TContext : DbContext | ||
{ | ||
using var serviceScope = app.ApplicationServices.CreateScope(); | ||
var context = serviceScope.ServiceProvider.GetService<TContext>(); | ||
if (context != null && context.Database != null) | ||
{ | ||
context.Database.Migrate(); | ||
} | ||
|
||
return app; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/NuvTools.AspNetCore.EntityFrameworkCore/Mapper/ServiceWithCrudBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using AutoMapper; | ||
using Microsoft.EntityFrameworkCore; | ||
using NuvTools.AspNetCore.Mapper; | ||
using NuvTools.Common.ResultWrapper; | ||
using NuvTools.Data.EntityFrameworkCore.Extensions; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Threading.Tasks; | ||
|
||
namespace NuvTools.AspNetCore.EntityFrameworkCore.Mapper; | ||
|
||
public abstract class ServiceWithCrudBase<TContext, TForm, TData, TKey> : ServiceWithMapperBase<TForm, TData> | ||
where TForm : class | ||
where TData : class | ||
where TContext : DbContext | ||
{ | ||
protected readonly TContext Context; | ||
|
||
public ServiceWithCrudBase(TContext context, IMapper mapper) : base(mapper) | ||
{ | ||
Context = context; | ||
} | ||
|
||
public DbSet<TData> Dataset { get { return Context.Set<TData>(); } } | ||
|
||
public async Task<TForm> FindAsync(TKey id) | ||
{ | ||
return ConvertToForm(await Context.FindAsync<TData>(id)); | ||
} | ||
|
||
public async Task<TForm> FindAsync(object[] keys) | ||
{ | ||
return ConvertToForm(await Context.FindAsync<TData>(keys)); | ||
} | ||
|
||
public async Task<IEnumerable<TForm>> FindFromExpressionAsync(Expression<Func<IQueryable<TData>>> expression) | ||
{ | ||
return ConvertToForm(await Context.FromExpression(expression).ToListAsync()); | ||
} | ||
|
||
public virtual async Task<IResult<TKey>> AddAndSaveAsync(TForm model) | ||
{ | ||
return await Context.AddAndSaveAsync<TData, TKey>(ConvertToData(model)); | ||
} | ||
|
||
public virtual async Task<IResult> UpdateAndSaveAsync(TKey id, TForm model) | ||
{ | ||
return await Context.UpdateAndSaveAsync(ConvertToData(model), id); | ||
} | ||
|
||
public virtual async Task<IResult> RemoveAndSaveAsync(TKey id) | ||
{ | ||
return await Context.RemoveAndSaveAsync<TData>(id); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/NuvTools.AspNetCore.EntityFrameworkCore/NuvTools.AspNetCore.EntityFrameworkCore.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net6;net7</TargetFrameworks> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<Authors>Nuv Tools</Authors> | ||
<Copyright>Copyright © 2023 Nuv Tools</Copyright> | ||
<PackageProjectUrl>https://nuv.tools</PackageProjectUrl> | ||
<SignAssembly>True</SignAssembly> | ||
<AssemblyOriginatorKeyFile>NuvTools.AspNetCore.EntityFrameworkCore.snk</AssemblyOriginatorKeyFile> | ||
<Description>EntityFramework Core helper library to use with ASP.NET Aplications.</Description> | ||
<Version>7.0.0</Version> | ||
<GenerateDocumentationFile>True</GenerateDocumentationFile> | ||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild> | ||
<PackageIcon>icon.png</PackageIcon> | ||
<DelaySign>False</DelaySign> | ||
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance> | ||
<PackageLicenseFile>LICENSE</PackageLicenseFile> | ||
<RepositoryUrl>https://github.com/nuvtools/nuvtools-aspnetcore</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
<AnalysisLevel>latest</AnalysisLevel> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
<PackageTags>Nuv Tools AspNetCore Entity Framework Core</PackageTags> | ||
<ImplicitUsings>true</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.3" /> | ||
<PackageReference Include="NuvTools.Data.EntityFrameworkCore" Version="7.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\icon.png"> | ||
<Link>icon.png</Link> | ||
<Pack>True</Pack> | ||
<PackagePath></PackagePath> | ||
</None> | ||
<None Include="..\..\LICENSE"> | ||
<Link>LICENSE</Link> | ||
<Pack>True</Pack> | ||
<PackagePath></PackagePath> | ||
</None> | ||
<None Include="..\..\README.md"> | ||
<Pack>True</Pack> | ||
<PackagePath>\</PackagePath> | ||
</None> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\NuvTools.AspNetCore\NuvTools.AspNetCore.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Binary file added
BIN
+596 Bytes
src/NuvTools.AspNetCore.EntityFrameworkCore/NuvTools.AspNetCore.EntityFrameworkCore.snk
Binary file not shown.
Oops, something went wrong.