Esempio n. 1
0
        public static async Task SaveClaimToDb(
            [ActivityTrigger] WhatIfDemoDbDataContext.Claim claim,
            ILogger log)
        {
            var ctx = new WhatIfDemoDbDataContext();

            ctx.Claims.Add(claim);

            await ctx.SaveChangesIdempotentlyAsync(ex => {
                // Explicitly handling the case of duplicated execution.
                // Which might happen, if the process crashes or restarts.
                log.LogError($"Failed to add policy {claim.id} from userId {claim.userId}: {ex.Message}");
            });

            log.LogWarning($"Saved claim {claim.id} from userId {claim.userId}");
        }
Esempio n. 2
0
        public static async Task <WhatIfDemoDbDataContext.Policy> SavePolicyToDb(
            [ActivityTrigger] WhatIfDemoDbDataContext.Policy policy,
            ILogger log)
        {
            // Saving the policy to Azure SQL DB
            var ctx = new WhatIfDemoDbDataContext();

            ctx.Policies.Add(policy);

            await ctx.SaveChangesIdempotentlyAsync(ex => {
                // Explicitly handling the case of duplicated execution.
                // Which might happen, if the process crashes or restarts.
                log.LogError($"Failed to add policy {policy.id} from userId {policy.userId}: {ex.Message}");
            });

            log.LogWarning($"Saved policy {policy.id} from userId {policy.userId}");

            // Returning the Policy object back, just to show this context propagation mechanism
            return(policy);
        }