Example #1
0
        private static async Task SendMail(ILogger log, Shared.Models.UserInformation userToInform)
        {
            //Mail sending process
            var sendGridSender = new SendGridSender();
            var response       = await sendGridSender
                                 .SendMail("*****@*****.**", new List <string>() { userToInform.Email },
                                           "CoronaTestPlattform - Your CoViD19 test appointment has been scheduled",
                                           $"Hi {userToInform.Name} </ br> your test was scheduled at the testcenter: <b> {userToInform.Location} </b>.",
                                           $"Hi {userToInform.Name} your test was scheduled at the testcenter: {userToInform.Location}.",
                                           SendGridConfigBuilder.GetConfigFromEnvVars().sendGridApiKey);

            if (response != HttpStatusCode.Accepted)
            {
                log.LogError($"Error while trying to send mail to user. Got response code {response} from sendmail");
            }
            else
            {
                log.LogInformation($"We have send an appointment mail to {userToInform.Email}");
            }
        }
Example #2
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            [CosmosDB(
                 databaseName: "UserInformation",
                 collectionName: "UserInformation",
                 ConnectionStringSetting = "UserInformationDBConnection")] DocumentClient outputTable,
            [Queue("NewUserInformations")] IAsyncCollector <KeyValuePair <string, string> > outputQueue,
            ILogger log)
        {
            log.LogInformation("Try to add a new question.");
            Shared.Models.UserInformation userToSave = null;
            try
            {
                userToSave = await System.Text.Json.JsonSerializer.DeserializeAsync <Shared.Models.UserInformation>(req.Body,
                                                                                                                    new JsonSerializerOptions()
                {
                    AllowTrailingCommas = true,
                }
                                                                                                                    );
            }
            catch (System.Text.Json.JsonException ex)
            {
                return(new BadRequestObjectResult($"There was an error in the provided json: {ex.Message} -> {ex.InnerException.Message}"));
            }
            if (userToSave.RiskScore != null)
            {
                userToSave.RiskScore = null;
            }
            userToSave.Token  = TokenGenerator.GenerateToken();
            userToSave.Source = "covapp.charite";
            await outputTable.CreateDatabaseIfNotExistsAsync(new Database()
            {
                Id = "UserInformation"
            });

            await outputTable.CreateDocumentCollectionIfNotExistsAsync(UriFactory.CreateDatabaseUri("UserInformation"), new DocumentCollection()
            {
                Id           = "UserInformation",
                PartitionKey = new PartitionKeyDefinition()
                {
                    Paths = new Collection <string>()
                    {
                        "/Source"
                    }
                },
                UniqueKeyPolicy = new UniqueKeyPolicy()
                {
                    UniqueKeys = new Collection <UniqueKey>()
                    {
                        new UniqueKey()
                        {
                            Paths = new Collection <string>()
                            {
                                "/Token"
                            }
                        }
                    }
                }
            });

            await outputTable.CreateDocumentAsync("dbs/UserInformation/colls/UserInformation", userToSave);

            await outputQueue.AddAsync(userToSave.GetIdentifier());

            return(new OkObjectResult(userToSave.Token));
        }