Example #1
0
        public async Task <IActionResult> BatchWebhook(IFormCollection form)
        {
            if (!Request.Form?.Any() ?? true)
            {
                return(BadRequest());
            }

            //try to get already handled batches
            var batchesInfo = _staticCacheManager.Get(_cacheKeyService.PrepareKeyForDefaultCache(MailChimpDefaults.SynchronizationBatchesCacheKey), () => new Dictionary <string, int>());

            //handle batch webhook
            var(id, completedOperationNumber) = await _mailChimpManager.HandleBatchWebhook(Request.Form, batchesInfo);

            if (!string.IsNullOrEmpty(id) && completedOperationNumber.HasValue)
            {
                if (!batchesInfo.ContainsKey(id))
                {
                    //update cached value
                    batchesInfo.Add(id, completedOperationNumber.Value);
                    _staticCacheManager.Set(_cacheKeyService.PrepareKeyForDefaultCache(MailChimpDefaults.SynchronizationBatchesCacheKey), batchesInfo);
                }
                return(Ok());
            }

            return(BadRequest());
        }
        public async Task <IActionResult> BatchWebhook(IFormCollection form)
        {
            if (!this.Request.Form?.Any() ?? true)
            {
                return(BadRequest());
            }

            //try to get already handled batches
            var batchesInfo = _cacheManager.Get <Dictionary <string, int> >(MailChimpDefaults.SynchronizationBatchesCacheKey)
                              ?? new Dictionary <string, int>();

            //handle batch webhook
            var batchInfo = await _mailChimpManager.HandleBatchWebhook(this.Request.Form, batchesInfo);

            if (!string.IsNullOrEmpty(batchInfo.Id) && batchInfo.CompletedOperationNumber.HasValue)
            {
                if (!batchesInfo.ContainsKey(batchInfo.Id))
                {
                    //update cached value
                    batchesInfo.Add(batchInfo.Id, batchInfo.CompletedOperationNumber.Value);
                    _cacheManager.Set(MailChimpDefaults.SynchronizationBatchesCacheKey, batchesInfo, 60);
                }
                return(Ok());
            }

            return(BadRequest());
        }