mirror of
https://github.com/C9Glax/tranga.git
synced 2025-04-15 12:53:17 +02:00
DeleteJob also deletes children
This commit is contained in:
parent
949c0cc16d
commit
9fca2d81ab
@ -174,14 +174,14 @@ public class JobController(PgsqlContext context) : Controller
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Job? ret = context.Jobs.Find(id);
|
Job? ret = context.Jobs.Find(id);
|
||||||
switch (ret is not null)
|
if(ret is null)
|
||||||
{
|
return NotFound();
|
||||||
case true:
|
IQueryable<Job> children = GetChildJobs(id);
|
||||||
context.Remove(ret);
|
|
||||||
context.SaveChanges();
|
context.RemoveRange(children);
|
||||||
return Ok();
|
context.Remove(ret);
|
||||||
case false: return NotFound();
|
context.SaveChanges();
|
||||||
}
|
return Ok();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@ -189,6 +189,15 @@ public class JobController(PgsqlContext context) : Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IQueryable<Job> GetChildJobs(string parentJobId)
|
||||||
|
{
|
||||||
|
IQueryable<Job> children = context.Jobs.Where(j => j.ParentJobId == parentJobId);
|
||||||
|
foreach (Job child in children)
|
||||||
|
foreach (Job grandChild in GetChildJobs(child.JobId))
|
||||||
|
children.Append(grandChild);
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Modify Job with ID
|
/// Modify Job with ID
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user