Created
August 1, 2020 23:15
-
-
Save Cheranga/50580dd1730ecf1459de7c6750fdc8c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SaveSmsRecipientActivityFunction | |
{ | |
private readonly ILogger<SaveSmsRecipientActivityFunction> _logger; | |
public SaveSmsRecipientActivityFunction(ILogger<SaveSmsRecipientActivityFunction> logger) | |
{ | |
_logger = logger; | |
} | |
[FunctionName(nameof(SaveSmsRecipientActivityFunction))] | |
public async Task<bool> SaveRecipientAsync([ActivityTrigger] IDurableActivityContext context, | |
[Table("%SmsRecipientsTable%")] CloudTable smsRecipients) | |
{ | |
var recipient = context.GetInput<SmsRecipient>(); | |
if (recipient == null) | |
{ | |
return false; | |
} | |
var status = await SaveAsync(smsRecipients, recipient); | |
return status; | |
} | |
private async Task<bool> SaveAsync(CloudTable table, SmsRecipient recipient) | |
{ | |
try | |
{ | |
var dataModel = new SmsRecipientDataModel | |
{ | |
PartitionKey = RecipientStatus.ToBeSent.ToString().ToUpper(), | |
RowKey = recipient.Id, | |
Message = recipient.Message | |
}; | |
var tableOperation = TableOperation.InsertOrReplace(dataModel); | |
await table.ExecuteAsync(tableOperation); | |
return true; | |
} | |
catch (Exception exception) | |
{ | |
_logger.LogError(exception, "Error when saving recipient {recipientId}", recipient.Id); | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment