|
|
|
@ -9,7 +9,6 @@ namespace DbServices;
|
|
|
|
|
|
|
|
|
|
public class DbTacticService(AppContext.AppContext context) : ITacticService
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public Task<IEnumerable<Tactic>> ListTacticsOf(int userId)
|
|
|
|
|
{
|
|
|
|
|
return Task.FromResult(
|
|
|
|
@ -44,7 +43,6 @@ public class DbTacticService(AppContext.AppContext context) : ITacticService
|
|
|
|
|
|
|
|
|
|
var stepEntity = new TacticStepEntity
|
|
|
|
|
{
|
|
|
|
|
StepId = 1,
|
|
|
|
|
ParentId = null,
|
|
|
|
|
TacticId = tacticEntity.Id,
|
|
|
|
|
JsonContent = "{\"components\": []}"
|
|
|
|
@ -69,7 +67,7 @@ public class DbTacticService(AppContext.AppContext context) : ITacticService
|
|
|
|
|
public async Task<bool> SetTacticStepContent(int tacticId, int stepId, string json)
|
|
|
|
|
{
|
|
|
|
|
var entity = await context.TacticSteps
|
|
|
|
|
.FirstOrDefaultAsync(t => t.TacticId == tacticId && t.StepId == stepId);
|
|
|
|
|
.FirstOrDefaultAsync(t => t.TacticId == tacticId && t.Id == stepId);
|
|
|
|
|
if (entity == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
@ -81,7 +79,7 @@ public class DbTacticService(AppContext.AppContext context) : ITacticService
|
|
|
|
|
{
|
|
|
|
|
return (await context
|
|
|
|
|
.TacticSteps
|
|
|
|
|
.FirstOrDefaultAsync(t => t.TacticId == tacticId && t.StepId == stepId)
|
|
|
|
|
.FirstOrDefaultAsync(t => t.TacticId == tacticId && t.Id == stepId)
|
|
|
|
|
)?.JsonContent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -112,35 +110,24 @@ public class DbTacticService(AppContext.AppContext context) : ITacticService
|
|
|
|
|
|
|
|
|
|
public async Task<int?> AddTacticStep(int tacticId, int parentStepId, string initialJson)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var tactic = await context.Tactics.FirstOrDefaultAsync(t => t.Id == tacticId);
|
|
|
|
|
if (tactic == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TacticStepEntity entity;
|
|
|
|
|
int nextStepId;
|
|
|
|
|
lock (tactic)
|
|
|
|
|
var entity = new TacticStepEntity
|
|
|
|
|
{
|
|
|
|
|
nextStepId = context.TacticSteps
|
|
|
|
|
.Where(s => s.TacticId == tacticId)
|
|
|
|
|
.Max(s => s.StepId) + 1;
|
|
|
|
|
|
|
|
|
|
entity = new TacticStepEntity
|
|
|
|
|
{
|
|
|
|
|
JsonContent = initialJson,
|
|
|
|
|
ParentId = parentStepId,
|
|
|
|
|
TacticId = tacticId,
|
|
|
|
|
StepId = nextStepId
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
context.Add(entity);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
JsonContent = initialJson,
|
|
|
|
|
ParentId = parentStepId,
|
|
|
|
|
TacticId = tacticId,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await context.AddAsync(entity);
|
|
|
|
|
await context.SaveChangesAsync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return entity.StepId;
|
|
|
|
|
return entity.Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<bool> RemoveTacticStep(int tacticId, int stepId)
|
|
|
|
@ -149,7 +136,7 @@ public class DbTacticService(AppContext.AppContext context) : ITacticService
|
|
|
|
|
|
|
|
|
|
var beginStep = await context
|
|
|
|
|
.TacticSteps
|
|
|
|
|
.FirstOrDefaultAsync(t => t.TacticId == tacticId && t.StepId == stepId);
|
|
|
|
|
.FirstOrDefaultAsync(t => t.TacticId == tacticId && t.Id == stepId);
|
|
|
|
|
|
|
|
|
|
if (beginStep == null)
|
|
|
|
|
return false;
|
|
|
|
@ -158,9 +145,8 @@ public class DbTacticService(AppContext.AppContext context) : ITacticService
|
|
|
|
|
|
|
|
|
|
while (toRemove.TryPop(out var step))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
await context.TacticSteps
|
|
|
|
|
.Where(s => s.TacticId == tacticId && s.ParentId == step.StepId)
|
|
|
|
|
.Where(s => s.TacticId == tacticId && s.ParentId == step.Id)
|
|
|
|
|
.ForEachAsync(toRemove.Push);
|
|
|
|
|
|
|
|
|
|
context.Remove(step);
|
|
|
|
|