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

13 lines
690 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, new {returnTypeFullName}({existingEntityVarName}));
}