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