CodeLiturgy.Dashboard/BlueWest.Api/Extensions/AddToEntityTemplate.csx

14 lines
580 B
Plaintext
Raw Normal View History

2022-08-27 06:19:30 +03:00
using Microsoft.EntityFrameworkCore;
namespace {Namespace}
{
public static partial class {entityTypeName}Extensions {
public static (bool, {readTypeFullName}) 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}));
}
}
}