namespace Diligent.WebAPI.Business.Services { public class WebhookSubscriptionService : IWebhookSubscriptionService { private readonly DatabaseContext _context; private readonly IMapper _mapper; public WebhookSubscriptionService(DatabaseContext context, IMapper mapper) { _context = context; _mapper = mapper; } public async Task CreateWebhookSubscription(WebhookSubscriptionCreateDto dto) { // map dto to db model WebhookSubscription subscription = _mapper.Map(dto); subscription.CreatedAtUtc = DateTime.Now; subscription.IsActive = true; // add to db await _context.WebhookSubscriptions.AddAsync(subscription); await _context.SaveChangesAsync(); return subscription; } public async Task> GetAllSubscriptionsAsync(string webhookName) { return await _context.WebhookSubscriptions .Where(x => x.WebhookDefinition.Name == webhookName) .Include(x => x.WebhookDefinition) .ToListAsync(); } } }