From b4362789ccbcf54269295bfe282cb65eff6109c3 Mon Sep 17 00:00:00 2001 From: CodeLiturgy Date: Sat, 27 Aug 2022 04:19:30 +0100 Subject: [PATCH] Add template working --- BlueWest.Api/BlueWest.Api.csproj | 8 +++++--- BlueWest.Api/Context/CompanyDbContext.cs | 8 ++++---- BlueWest.Api/EFUpdateMethodsAttribute.cs | 11 ----------- BlueWest.Api/EfAddToListMethodAttribute.cs | 15 --------------- BlueWest.Api/Extensions/AddToEntityTemplate.csx | 14 ++++++++++++++ BlueWest.Frontend | 2 +- 6 files changed, 24 insertions(+), 34 deletions(-) delete mode 100644 BlueWest.Api/EFUpdateMethodsAttribute.cs delete mode 100644 BlueWest.Api/EfAddToListMethodAttribute.cs create mode 100644 BlueWest.Api/Extensions/AddToEntityTemplate.csx diff --git a/BlueWest.Api/BlueWest.Api.csproj b/BlueWest.Api/BlueWest.Api.csproj index 024c4a6..e594f7c 100644 --- a/BlueWest.Api/BlueWest.Api.csproj +++ b/BlueWest.Api/BlueWest.Api.csproj @@ -9,7 +9,6 @@ bin\$(Configuration)\$(AssemblyName).xml true preview - @@ -18,13 +17,16 @@ - + + + + - + diff --git a/BlueWest.Api/Context/CompanyDbContext.cs b/BlueWest.Api/Context/CompanyDbContext.cs index 6b0e8a8..71e909b 100644 --- a/BlueWest.Api/Context/CompanyDbContext.cs +++ b/BlueWest.Api/Context/CompanyDbContext.cs @@ -15,10 +15,10 @@ namespace BlueWest.WebApi.EF /// Companies. /// [EfAddMethods(typeof(CompanyCreate), typeof(CompanyUnique))] - [EFUpdateMethods(typeof(int), + /*[EFUpdateMethods(typeof(int), "Id", typeof(CompanyUpdate), - typeof(CompanyUnique))] + typeof(CompanyUnique))]*/ public DbSet Companies { get; set; } @@ -26,10 +26,10 @@ namespace BlueWest.WebApi.EF /// Industries. /// [EfAddMethods(typeof(IndustryCreate), typeof(IndustryUnique))] - [EFUpdateMethods(typeof(int), + /*[EFUpdateMethods(typeof(int), "Id", typeof(IndustryUpdate), - typeof(IndustryUnique))] + typeof(IndustryUnique))]*/ public DbSet Industries { get; set; } diff --git a/BlueWest.Api/EFUpdateMethodsAttribute.cs b/BlueWest.Api/EFUpdateMethodsAttribute.cs deleted file mode 100644 index 74f83f1..0000000 --- a/BlueWest.Api/EFUpdateMethodsAttribute.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace BlueWest.WebApi -{ - [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] - public class EFUpdateMethodsAttribute : Attribute - { - public EFUpdateMethodsAttribute( Type keyType = null, string keyName = "Id", Type updateDto = null, Type returnType = null) { } - } -} - diff --git a/BlueWest.Api/EfAddToListMethodAttribute.cs b/BlueWest.Api/EfAddToListMethodAttribute.cs deleted file mode 100644 index 1020b9d..0000000 --- a/BlueWest.Api/EfAddToListMethodAttribute.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; - -namespace BlueWest.WebApi -{ - [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] - public class EfAddToListMethodAttribute : Attribute - { - public EfAddToListMethodAttribute( Type keyType = null, string keyName = "Id", Type updateDto = null, Type returnType = null) - { - - } - } - -} - diff --git a/BlueWest.Api/Extensions/AddToEntityTemplate.csx b/BlueWest.Api/Extensions/AddToEntityTemplate.csx new file mode 100644 index 0000000..5c98dcf --- /dev/null +++ b/BlueWest.Api/Extensions/AddToEntityTemplate.csx @@ -0,0 +1,14 @@ +using Microsoft.EntityFrameworkCore; + +namespace {Namespace} +{ + public static partial class {entityTypeName}Extensions { + public static (bool, {readTypeFullName}) Add{entityTypeName}( + this {contextFullName} dbContext, {createTypeFullName} {toCreateVarName}) { + var {newEntityVarName} = new {entityTypeFullName}({toCreateVarName}); + dbContext.{propertyName}.Add({newEntityVarName}); + var success = dbContext.SaveChanges() >= 0; + return (success, new {readTypeFullName}({newEntityVarName})); + } + } +} \ No newline at end of file diff --git a/BlueWest.Frontend b/BlueWest.Frontend index acb9bda..5006902 160000 --- a/BlueWest.Frontend +++ b/BlueWest.Frontend @@ -1 +1 @@ -Subproject commit acb9bdabd148dd2184866b9fd6da4dcc772fe464 +Subproject commit 5006902892221cef14127637b20f6f59ae28a311