Add result wait service
This commit is contained in:
@ -11,12 +11,6 @@ namespace Hcs.WebApp.Services
|
||||
return await context.Campaigns.AnyAsync(x => x.Type == type && !x.EndedAt.HasValue);
|
||||
}
|
||||
|
||||
public async Task<bool> HasActiveOperationsAsync(int campaignId)
|
||||
{
|
||||
using var context = GetNewContext();
|
||||
return await context.Operations.CountAsync(x => x.CampaignId == campaignId && !x.EndedAt.HasValue) > 0;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Campaign>> GetNotEndedCampaignsAsync()
|
||||
{
|
||||
using var context = GetNewContext();
|
||||
@ -33,6 +27,14 @@ namespace Hcs.WebApp.Services
|
||||
select operation).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Operation>> GetOperationsAsync(int campaignId)
|
||||
{
|
||||
using var context = GetNewContext();
|
||||
return await (from operation in context.Operations
|
||||
where operation.CampaignId == campaignId
|
||||
select operation).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<Campaign> InitiateCampaignAsync(Campaign.CampaignType type, string initiatorId)
|
||||
{
|
||||
using var context = GetNewContext();
|
||||
@ -137,12 +139,18 @@ namespace Hcs.WebApp.Services
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SetCampaignStepAsync(HcsDbContext context, int campaignId, int step)
|
||||
public async Task UpdateCampaignStepAsync(Campaign campaign)
|
||||
{
|
||||
var campaign = await context.Campaigns.FirstOrDefaultAsync(x => x.Id == campaignId);
|
||||
if (campaign != null)
|
||||
using var context = GetNewContext();
|
||||
await UpdateCampaignStepAsync(context, campaign);
|
||||
}
|
||||
|
||||
public async Task UpdateCampaignStepAsync(HcsDbContext context, Campaign campaign)
|
||||
{
|
||||
var targetCampaign = await context.Campaigns.FirstOrDefaultAsync(x => x.Id == campaign.Id);
|
||||
if (targetCampaign != null)
|
||||
{
|
||||
campaign.Step = step;
|
||||
targetCampaign.Step = campaign.Step;
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user