|
|
@ -9,6 +9,7 @@ namespace DbServices;
|
|
|
|
|
|
|
|
|
|
|
|
public class DbTacticService(AppContext.AppContext context) : ITacticService
|
|
|
|
public class DbTacticService(AppContext.AppContext context) : ITacticService
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
public Task<IEnumerable<Tactic>> ListTacticsOf(int userId)
|
|
|
|
public Task<IEnumerable<Tactic>> ListTacticsOf(int userId)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Task.FromResult(
|
|
|
|
return Task.FromResult(
|
|
|
@ -111,25 +112,33 @@ public class DbTacticService(AppContext.AppContext context) : ITacticService
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<int?> AddTacticStep(int tacticId, int parentStepId, string initialJson)
|
|
|
|
public async Task<int?> AddTacticStep(int tacticId, int parentStepId, string initialJson)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!context.Tactics.Any(t => t.Id == tacticId))
|
|
|
|
|
|
|
|
|
|
|
|
var tactic = await context.Tactics.FirstOrDefaultAsync(t => t.Id == tacticId);
|
|
|
|
|
|
|
|
if (tactic == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var nextStepId = context.TacticSteps
|
|
|
|
TacticStepEntity entity;
|
|
|
|
.Where(s => s.TacticId == tacticId)
|
|
|
|
int nextStepId;
|
|
|
|
.Max(s => s.StepId) + 1;
|
|
|
|
lock (tactic)
|
|
|
|
|
|
|
|
|
|
|
|
var entity = new TacticStepEntity
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
JsonContent = initialJson,
|
|
|
|
nextStepId = context.TacticSteps
|
|
|
|
ParentId = parentStepId,
|
|
|
|
.Where(s => s.TacticId == tacticId)
|
|
|
|
TacticId = tacticId,
|
|
|
|
.Max(s => s.StepId) + 1;
|
|
|
|
StepId = nextStepId
|
|
|
|
|
|
|
|
};
|
|
|
|
entity = new TacticStepEntity
|
|
|
|
|
|
|
|
{
|
|
|
|
await context.AddAsync(entity);
|
|
|
|
JsonContent = initialJson,
|
|
|
|
await context.SaveChangesAsync();
|
|
|
|
ParentId = parentStepId,
|
|
|
|
|
|
|
|
TacticId = tacticId,
|
|
|
|
|
|
|
|
StepId = nextStepId
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.Add(entity);
|
|
|
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return entity.StepId;
|
|
|
|
return entity.StepId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|