Skip to content

Instantly share code, notes, and snippets.

@Cheranga
Created August 1, 2020 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cheranga/50580dd1730ecf1459de7c6750fdc8c4 to your computer and use it in GitHub Desktop.
Save Cheranga/50580dd1730ecf1459de7c6750fdc8c4 to your computer and use it in GitHub Desktop.
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