ok state before introducing update
This commit is contained in:
parent
13627dbcb6
commit
e702debe48
|
@ -1,5 +1,6 @@
|
|||
|
||||
using BlueWest.Data;
|
||||
using BlueWest.WebApi.Context;
|
||||
using BlueWest.WebApi.EF.Model;
|
||||
using MapTo;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
@ -15,6 +16,11 @@ namespace BlueWest.WebApi.EF
|
|||
/// Companies.
|
||||
/// </summary>
|
||||
[EfAddMethods(typeof(CompanyCreate), typeof(CompanyUnique))]
|
||||
[EfAddUpdateMethods(
|
||||
typeof(CompanyUnique),
|
||||
typeof(CompanyUpdate),
|
||||
"Id", typeof(int))
|
||||
]
|
||||
/*[EFUpdateMethods(typeof(int),
|
||||
"Id",
|
||||
typeof(CompanyUpdate),
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace BlueWest.WebApi.EF
|
|||
/// <summary>
|
||||
/// Country table database extensions
|
||||
/// </summary>
|
||||
public static class CountryDbExtensions
|
||||
public static class CountryExtensions2
|
||||
{
|
||||
|
||||
/// <summary>
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
public static (bool, {readTypeFullName}) Add{entityTypeName}(
|
||||
public static (bool, {returnTypeFullName}) 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}));
|
||||
return (success, new {returnTypeFullName}({newEntityVarName}));
|
||||
}
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
|
||||
public static (bool, string, {ReturnTypeFullyQualifiedType}) Add{ItemListTypeName}(
|
||||
this {PropertyParentType} dbContext,
|
||||
{KeyFullyQualifiedType} {TargetItemPropertyTypeName.ToLowerCase()}{KeyPropertyName},
|
||||
{ItemListCreateFullyQualifiedType} {ItemListCreateTypeName.FirstLower()})
|
||||
{
|
||||
var {TargetItemPropertyTypeName.FirstLower()} = dbContext.{TargetItemPropertyName}.FirstOrDefault(d => d.{KeyPropertyName} == {TargetItemPropertyTypeName.ToLowerCase()}{KeyPropertyName});
|
||||
|
||||
if ({TargetItemPropertyTypeName.FirstLower()} == null) return (false, "{TargetItemPropertyTypeName} Not found.", null);
|
||||
|
||||
var new{ItemListTypeTypeName} = new {ItemListTypeFullyQualifiedType}({ItemListCreateTypeName.FirstLower()});
|
||||
|
||||
country.{ItemListPropertyName}.Add(new{ItemListTypeTypeName});
|
||||
|
||||
var success = dbContext.SaveChanges() >= 0;
|
||||
|
||||
return !success ? (false, "Error saving changes.", null) : (true, string.Empty, new {ReturnTypeFullyQualifiedType}(newCurrency));
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace {Namespace}
|
||||
{
|
||||
{Code}
|
||||
}
|
|
@ -1,14 +1,13 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace {Namespace}
|
||||
public static (bool, {returnTypeFullName}) Update{entityTypeName}(
|
||||
this {contextFullName} dbContext,
|
||||
{updateTypeFullName} {updateVarName},
|
||||
{keyTypeFullName} {keyVarName})
|
||||
{
|
||||
public static partial class {entityTypeName}Extensions {
|
||||
public static (bool, {readTypeFullName}) Update{entityTypeName}(
|
||||
this {contextFullName} dbContext, {updateTypeFullName} {toUpdateVarName}) {
|
||||
var {newEntityVarName} = new {entityTypeFullName}({toUpdateVarName});
|
||||
dbContext.{propertyName}.Add({newEntityVarName});
|
||||
var success = dbContext.SaveChanges() >= 0;
|
||||
return (success, new {readTypeFullName}({newEntityVarName}));
|
||||
}
|
||||
}
|
||||
var {existingEntityVarName} = dbContext.{propertyName}.FirstOrDefault(x => x.{keyPropertyName} == {keyVarName});
|
||||
if ({existingEntityVarName} == null) return (false, null);
|
||||
{existingEntityVarName}.Update({updateVarName});
|
||||
dbContext.{propertyname}.Update({existingEntityVarName});
|
||||
var result = dbContext.SaveChanges() >= 0;
|
||||
return (result, {existingEntityVarName});
|
||||
|
||||
}
|
|
@ -1 +1 @@
|
|||
Subproject commit 12d5839f1660c0cf89be22d391b1f744a37c202e
|
||||
Subproject commit ca95c878399d057ee42007f04e4b3fb032deaab0
|
Loading…
Reference in New Issue