Example #1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Admin, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");
            string email = req.Query["email"];
            string notes = req.Query["notes"];

            log.LogInformation("Email Is" + req.Query["email"]);
            log.LogInformation("Notes Is" + req.Query["notes"]);

            Appointment appointment = null;

            using (CoderDeckPocContext dbContext = new CoderDeckPocContext())
            {
                appointment = dbContext.Appointment.Where(w => w.Email.Equals(email, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
                log.LogInformation("Appointment data is" + JsonConvert.SerializeObject(appointment));
                if (appointment != null)
                {
                    AppointmentNotes appointmentNotes = new AppointmentNotes()
                    {
                        AppointmentId = appointment.Id,
                        Notes         = notes,
                        CreatedBy     = email,
                        CreatedOn     = DateTime.Now
                    };


                    dbContext.Add <AppointmentNotes>(appointmentNotes);
                    dbContext.SaveChanges();
                }
            }
            string webHookResponse = "You dont have any upcoming appointment";

            if (appointment != null)
            {
                webHookResponse = "Appointment notes added \n" + "You have added following notes \n" + notes;
            }
            return(new ContentResult {
                Content = webHookResponse, ContentType = "application/json"
            });
        }
Example #2
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");
            string email = req.Query["email"];

            log.LogInformation("Email Is" + req.Query["email"]);

            Appointment appointment = null;
            string      releaseNote = string.Empty;

            using (CoderDeckPocContext dbContext = new CoderDeckPocContext())
            {
                appointment = dbContext.Appointment.Where(w => w.Email.ToString().Equals(email, StringComparison.InvariantCultureIgnoreCase) && w.AppointmentDate > DateTime.Now).OrderBy(o => o.AppointmentDate).FirstOrDefault();
                var appontmentNotes = dbContext.AppointmentNotes.Where(w => w.AppointmentId == appointment.Id).OrderByDescending(w => w.CreatedOn).FirstOrDefault();

                releaseNote = appontmentNotes?.Notes;
            }
            string webHookResponse = "You dont have any future appointment.Please check with the advisor";

            if (appointment != null)
            {
                if (releaseNote == null)
                {
                    webHookResponse = appointment.Appointment1 + " at" + appointment.AppointmentDate + "\n" + "Do you want to add note to this appointment?";
                }
                else
                {
                    webHookResponse = appointment.Appointment1 + " at" + appointment.AppointmentDate + "\n Latest note on this appointment\n" + releaseNote + "\n" + "Do you want to add more notes to this appointment?";
                }
            }
            return(new ContentResult {
                Content = webHookResponse, ContentType = "application/json"
            });
        }