public async Task <bool> UpdateSubscriberData(SubmitInfo submitInfo)
        {
            string[]       emailSplited = submitInfo.Email.Split("@");
            SubscriberInfo existingInfo = await _subscribersTable.GetTableEntity <SubscriberInfo>(emailSplited[1], emailSplited[0]);

            SubscriberInfo newSubscriberInfo = new SubscriberInfo()
            {
                PartitionKey   = emailSplited[1],
                RowKey         = emailSplited[0],
                Active         = true,
                AlertThreshold = submitInfo.AlertThreshold ?? 0
            };

            if (existingInfo != null)
            {
                newSubscriberInfo.ETag = existingInfo.ETag;
            }

            TableOperation subscribersTableOperation = null;

            if (existingInfo != null)
            {
                if ((submitInfo.AlertThreshold ?? 0) == 0)
                {
                    await DeleteAlertLevelsOperation(existingInfo.AlertThreshold, submitInfo.Email);

                    subscribersTableOperation = TableOperation.Delete(existingInfo);
                }
                else if (submitInfo.AlertThreshold != existingInfo.AlertThreshold)
                {
                    await DeleteAlertLevelsOperation(existingInfo.AlertThreshold, submitInfo.Email);
                    await InsertAlertLevelsOperation(submitInfo.AlertThreshold.Value, submitInfo.Email);

                    subscribersTableOperation = TableOperation.Replace(newSubscriberInfo);
                }
            }
            else
            {
                await InsertAlertLevelsOperation(submitInfo.AlertThreshold.Value, submitInfo.Email);

                subscribersTableOperation = TableOperation.Insert(newSubscriberInfo);
            }

            if (subscribersTableOperation != null)
            {
                await _subscribersTable.ExecuteAsync(subscribersTableOperation);

                return(true);
            }
            return(false);
        }
示例#2
0
        public static async Task <SendGridMessage> SendConfirmationEmail(
            [ActivityTrigger] UpdaterOrchestratorData orchestratorData,
            [Table("Subscribers")] CloudTable subscribersTable,
            [Inject] IEmailComposer emailComposer,
            ILogger log)
        {
            log.LogInformation($"SendConfirmationEmail to: {orchestratorData.SubmitInfo.Email}");

            string[] emailSplited = orchestratorData.SubmitInfo.Email.Split("@");
            if (emailSplited.Length != 2)
            {
                return(null);
            }
            SubscriberInfo subscriberInfo = await subscribersTable.GetTableEntity <SubscriberInfo>(emailSplited[1], emailSplited[0]);

            return(subscriberInfo == null?emailComposer.CreateActivationMessage(orchestratorData) : emailComposer.CreateUpdateMessage(orchestratorData));
        }