Exemplo n.º 1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            int updateType;
            int newvalue;
            int idPatient;
            ResponseupdatePatient response = new ResponseupdatePatient();

            try{
                updateType = Int32.Parse(req.Query["updateType"]);
                newvalue   = Int32.Parse(req.Query["newvalue"]);
                idPatient  = Int32.Parse(req.Query["idPatient"]);
                UtilsQuerys utilsQuerys = new UtilsQuerys();
                if (utilsQuerys.updatePatient(updateType, idPatient, newvalue))
                {
                    response.code    = 200;
                    response.message = "success";
                    return(new OkObjectResult(response));
                }
                else
                {
                    response.code    = 109;
                    response.message = "error update";
                    return(new OkObjectResult(response));
                }
            }
            catch (Exception ex)
            {
                return(new ExceptionResult(ex, true));
            }
        }
Exemplo n.º 2
0
        public static async Task RunAsync([TimerTrigger("0 0 */6 * * *")] TimerInfo myTimer, ILogger log)

        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

            UtilsQuerys uq   = new UtilsQuerys();
            int         vent = uq.getVentilators();

            //Missing get ventilators here
            if (vent <= 5)
            {
                UserAdmin user = uq.getUserAdmin();

                var adminEmail = user.email;
                var adminName  = user.fullName;

                string sendgridApi = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
                string fromEmail   = Environment.GetEnvironmentVariable("FROMEMAIL");
                string fromUser    = Environment.GetEnvironmentVariable("FROMUSER");

                var           client  = new SendGridClient(sendgridApi);
                var           from    = new EmailAddress(fromEmail, fromUser);
                var           subject = "Ventilators are running out!";
                var           to      = new EmailAddress(adminEmail, adminName);
                StringBuilder strHtml = uq.getTemplateEmail("low_ventilators");
                //var plainTextContent = "";
                var htmlContent = strHtml.ToString(); //MISSING TEMPLATE
                var msg         = MailHelper.CreateSingleEmail(from, to, subject, "", htmlContent);
                var response    = await client.SendEmailAsync(msg);
            }
            else
            {
                log.LogInformation($"there are enough ventilator");
            }
        }
Exemplo n.º 3
0
        public static void Run([TimerTrigger("0 0 0 * * *")] TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
            List <InventoryAvaible> lowInventor = ReadLowInventoryDB();

            if (lowInventor.Count > 0)
            {
                // send Email
                string json_lowInventor = JsonConvert.SerializeObject(lowInventor);

                UtilsQuerys uq   = new UtilsQuerys();
                UserAdmin   user = uq.getUserAdmin();

                string sendgridApi = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
                string fromEmail   = Environment.GetEnvironmentVariable("FROMEMAIL");
                string fromUser    = Environment.GetEnvironmentVariable("FROMUSER");

                var adminEmail = user.email;
                var adminName  = user.fullName;

                var client  = new SendGridClient(sendgridApi);
                var from    = new EmailAddress(fromEmail, fromUser);
                var subject = "Alarm we need more supplies";
                var to      = new EmailAddress(adminEmail, adminName);
                //var plainTextContent = json_lowInventor;
                StringBuilder   strHtml     = uq.getTemplateEmail("low_supplies", json_lowInventor);
                string          htmlContent = strHtml.ToString();
                var             msg         = MailHelper.CreateSingleEmail(from, to, subject, " ", htmlContent);
                Task <Response> response    = client.SendEmailAsync(msg);
                response.Wait();
                var rep = response.Result;
            }
            else
            {
                log.LogInformation($"We have enough supplies!! ");
            }
        }