Skip to content

Commit 0a172d0

Browse files
committed
DELETE resource
1 parent 950d9e6 commit 0a172d0

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

JsonApiDotNetCore/Controllers/JsonApiController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public ObjectResult Patch(string id, Dictionary<PropertyInfo, object> entityPatc
5757

5858
public ObjectResult Delete(string id)
5959
{
60+
_resourceRepository.Delete(id);
61+
_resourceRepository.SaveChanges();
6062
return new OkObjectResult(null);
6163
}
6264

JsonApiDotNetCore/Data/ResourceRepository.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ public void Add(object entity)
7272
dbSetAddMethod.Invoke(dbSet, new [] { entity });
7373
}
7474

75+
public void Delete(string id)
76+
{
77+
var entity = Get(id);
78+
var dbSet = GetDbSetFromContext(_context.Route.BaseRouteDefinition.ContextPropertyName);
79+
var dbSetAddMethod = dbSet.GetType().GetMethod("Remove");
80+
dbSetAddMethod.Invoke(dbSet, new [] { entity });
81+
}
82+
7583
public int SaveChanges()
7684
{
7785
return ((DbContext)_context.DbContext).SaveChanges();

0 commit comments

Comments
 (0)