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

15 lines
698 B
Plaintext
Raw Normal View History

2022-09-01 08:54:42 +03:00
/// <summary>
/// Adds a new {entityTypeName} to <see cref="{contextFullName}"></see> DbSet.
/// </summary>
/// <param name="dbContext">The database context.</param>
/// <param name="{toCreateVarName}">The data type with the add data to create {entityTypeName}</param>
/// <returns>The added data.</returns>
2022-09-01 08:54:42 +03:00
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 {returnTypeFullName}({newEntityVarName}));
2022-08-28 20:00:09 +03:00
}