Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

WebhookSubscriptionService.cs 1.2KB

123456789101112131415161718192021222324252627282930313233343536
  1. namespace Diligent.WebAPI.Business.Services
  2. {
  3. public class WebhookSubscriptionService : IWebhookSubscriptionService
  4. {
  5. private readonly DatabaseContext _context;
  6. private readonly IMapper _mapper;
  7. public WebhookSubscriptionService(DatabaseContext context, IMapper mapper)
  8. {
  9. _context = context;
  10. _mapper = mapper;
  11. }
  12. public async Task<WebhookSubscription> CreateWebhookSubscription(WebhookSubscriptionCreateDto dto)
  13. {
  14. // map dto to db model
  15. WebhookSubscription subscription = _mapper.Map<WebhookSubscription>(dto);
  16. subscription.CreatedAtUtc = DateTime.UtcNow;
  17. subscription.IsActive = true;
  18. // add to db
  19. await _context.WebhookSubscriptions.AddAsync(subscription);
  20. await _context.SaveChangesAsync();
  21. return subscription;
  22. }
  23. public async Task<List<WebhookSubscription>> GetAllSubscriptionsAsync(string webhookName)
  24. {
  25. return await _context.WebhookSubscriptions
  26. .Where(x => x.WebhookDefinition.Name == webhookName)
  27. .Include(x => x.WebhookDefinition)
  28. .ToListAsync();
  29. }
  30. }
  31. }