예제 #1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = "appointment/{repo}/{id}")] HttpRequest req,
            string repo,
            string id,
            ILogger log)
        {
            log.LogInformation(string.Format("DeleteAppointment(): Received request to delete appointment with keys {0} {1}", repo, id));

            try
            {
                var table = CosmosTableUtil.GetTableReference("schedule");

                TableEntity appointment = await AppointmentData.GetAppointmentAsync(repo, id);

                if (appointment != null)
                {
                    var result = await table.ExecuteAsync(TableOperation.Delete(appointment));

                    return(new OkObjectResult(result.Result as AppointmentEntity));
                }
                else
                {
                    return(new NotFoundResult());
                }
            }
            catch (Exception ex)
            {
                log.LogError(string.Format("DeleteAppointment(): Exception occurred {0}:{1}", ex.Message, ex));
                return(new InternalServerErrorResult());
            }
        }
        public static async Task UpsertExpertsAsync(IEnumerable <ExpertEntity> experts, string repo)
        {
            var table = CosmosTableUtil.GetTableReference("experts");

            foreach (var item in experts)
            {
                item.Repository = repo;
                var result = await table.ExecuteAsync(TableOperation.InsertOrMerge(item));
            }
        }
예제 #3
0
        private static async Task <IList <AppointmentEntity> > GetAppointmentsAsync(TableQuery <AppointmentEntity> query)
        {
            // Read in schedule for this repo and handle for these dates
            var table = CosmosTableUtil.GetTableReference("schedule");

            var continuationToken = default(TableContinuationToken);
            var result            = new List <AppointmentEntity>();

            do
            {
                var queryResult = await table.ExecuteQuerySegmentedAsync(query, continuationToken);

                result.AddRange(queryResult);
            }while (continuationToken != null);

            return(result);
        }
예제 #4
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "patch", Route = "appointment/{repo}/{id}")] HttpRequest req,
            string repo,
            string id,
            ILogger log)
        {
            log.LogInformation("UpdateAppointment(): Received request");

            using StreamReader reader = new StreamReader(req.Body);
            try
            {
                string            requestBody       = reader.ReadToEnd();
                AppointmentEntity appointmentEntity = JsonConvert.DeserializeObject <AppointmentEntity>(requestBody);

                var table = CosmosTableUtil.GetTableReference("schedule");

                var appointment = await AppointmentData.GetAppointmentAsync(repo, id);

                if (appointment != null)
                {
                    appointment.Status = appointmentEntity.Status;
                    var expert = await ExpertData.GetExpertAsync(appointment.Expert);

                    // Update record
                    var result = await table.ExecuteAsync(TableOperation.InsertOrReplace(appointment));

                    // Send email to expert
                    await EmailUtil.SendEmailAsync(appointment, expert);

                    return(new OkResult());
                }
                else
                {
                    return(new NotFoundResult());
                }
            }
            catch (Exception ex)
            {
                log.LogError(string.Format("UpdateAppointment(): Exception occurred {0}:{1}", ex.Message, ex.InnerException));
                return(new InternalServerErrorResult());
            }
        }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "appointment")] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("CreateAppointment(): Received request");

            using StreamReader reader = new StreamReader(req.Body);
            try
            {
                string            requestBody       = reader.ReadToEnd();
                AppointmentEntity appointmentEntity = JsonConvert.DeserializeObject <AppointmentEntity>(requestBody);

                // Set status for new appointment request
                appointmentEntity.Status   = "requested";
                appointmentEntity.RoomName = await CatNameGenerator.NewCatAsync();

                var table  = CosmosTableUtil.GetTableReference("schedule");
                var result = await table.ExecuteAsync(TableOperation.InsertOrMerge(appointmentEntity));

                var appointment = result.Result as AppointmentEntity;
                var expert      = await ExpertData.GetExpertAsync(appointment.Expert);

                await EmailUtil.SendEmailAsync(appointment, expert);

                return(new OkObjectResult(appointment));
            }
            catch (JsonSerializationException ex)
            {
                log.LogError(string.Format("CreateAppointment(): JsonSerializationException occurred {0}:{1}", ex.Message, ex.InnerException));
                return(new BadRequestObjectResult(ex.Message));
            }
            catch (StorageException ex)
            {
                log.LogError(string.Format("CreateAppointment(): StorageException occurred {0}:{1}", ex.Message, ex.InnerException));
                return(new BadRequestObjectResult(ex.Message));
            }
            catch (Exception ex)
            {
                log.LogError(string.Format("CreateAppointment(): Exception occurred {0}:{1}", ex.Message, ex.InnerException));
                return(new InternalServerErrorResult());
            }
        }
예제 #6
0
        private static async Task <IList <ScheduleEntity> > GetScheduleAsync(TableQuery <ScheduleEntity> query)
        {
            // Read in schedule for this repo and handle for these dates
            var table = CosmosTableUtil.GetTableReference("schedule");

            var continuationToken = default(TableContinuationToken);
            var result            = new List <ScheduleEntity>();

            do
            {
                var queryResult = await table.ExecuteQuerySegmentedAsync(query, continuationToken);

                foreach (var item in queryResult)
                {
                    item.EndDateTime = item.DateTime.AddMinutes(30);
                    result.Add(item);
                }
            }while (continuationToken != null);

            return(result);
        }