CodeLiturgy.Dashboard/BlueWest.Api/Context/Templates/UpdateEntityTemplate.csx

13 lines
664 B
C#

public static (bool, {returnTypeFullName}) Update{entityTypeName}(
this {contextFullName} dbContext,
{updateTypeFullName} {updateVarName},
{keyTypeFullName} {keyVarName})
{
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});
}