Skip to content

Commit

Permalink
Added DeleteById in Repository. This deletes without any checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix-CodingClimber committed Aug 15, 2024
1 parent 862fc7e commit d8423da
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/DotNetElements.Core/Core/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,21 @@ public virtual async Task<CrudResult> DeleteAsync<TEntityToDelete>(TEntityToDele
return CrudResult.Ok();
}

public async Task<CrudResult> DeleteByIdAsync(TKey id)
{
TEntity? entityToDelete = await Entities.FirstOrDefaultAsync(WithId(id));

if (entityToDelete is null)
return CrudResult.NotFound(id);

Entities.Remove(entityToDelete);

await DbContext.SaveChangesAsync();

return CrudResult.Ok();
}


public virtual async Task ClearTable()
{
await Entities.ExecuteDeleteAsync();
Expand Down

0 comments on commit d8423da

Please sign in to comment.