CodeLiturgy.Dashboard/CodeLiturgy.Views/Templates/UpdateTemplate.csx

16 lines
960 B
Plaintext
Raw Normal View History

2022-09-01 08:54:42 +03:00
/// <summary>
/// Updates {entityTypeName} in the DbSet of <see cref="{contextFullName}"></see>.
/// </summary>
/// <param name="dbContext">Database context</param>
/// <param name="{updateVarName}">The data type with the add data to update {entityTypeName}</param>
2022-09-06 01:37:52 +03:00
/// <param name="{keyVarName}"> The primary key.</param>
2022-09-01 08:54:42 +03:00
/// <returns>Returns the current data.</returns>
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}));
}