/// <inheritdoc /> public async Task <bool> TryCloseAsync(long campaignId, ulong closedById, PromotionCampaignOutcome outcome) { var entity = await ModixContext.PromotionCampaigns .Where(x => x.Id == campaignId) .FirstOrDefaultAsync(); if ((entity == null) || (entity.CloseActionId != null)) { return(false); } entity.Outcome = outcome; entity.CloseAction = new PromotionActionEntity() { GuildId = entity.GuildId, Type = PromotionActionType.CampaignClosed, Created = DateTimeOffset.Now, CreatedById = closedById, CampaignId = entity.Id }; await ModixContext.SaveChangesAsync(); await RaisePromotionActionCreatedAsync(entity.CloseAction); return(true); }
/// <inheritdoc /> public async Task <PromotionActionSummary?> TryCloseAsync(long campaignId, ulong closedById, PromotionCampaignOutcome outcome) { var entity = await ModixContext.PromotionCampaigns .Where(x => x.Id == campaignId) .FirstOrDefaultAsync(); if ((entity == null) || (entity.CloseActionId != null)) { return(null); } entity.Outcome = outcome; entity.CloseAction = new PromotionActionEntity() { GuildId = entity.GuildId, Type = PromotionActionType.CampaignClosed, Created = DateTimeOffset.Now, CreatedById = closedById, CampaignId = entity.Id }; await ModixContext.SaveChangesAsync(); var action = await ModixContext.PromotionActions.AsNoTracking() .Where(x => x.Id == entity.CloseActionId) .AsExpandable() .Select(PromotionActionSummary.FromEntityProjection) .FirstAsync(); return(action); }