public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Admin, "post", Route = "clearschedule")] ClearScheduleModel clearScheduleModel,
            [DurableClient] IDurableOrchestrationClient starter,
            ILogger log)
        {
            if (!clearScheduleModel.IsValid())
            {
                return(new BadRequestResult());
            }

            // ensure that the team's orchestrators will not execute by disabling them
            await _scheduleConnectorService.UpdateEnabledAsync(clearScheduleModel.TeamId, false).ConfigureAwait(false);

            // get the connection model as we need the time zone information for the team
            var connectionModel = await _scheduleConnectorService.GetConnectionAsync(clearScheduleModel.TeamId).ConfigureAwait(false);

            try
            {
                SetStartAndEndDates(clearScheduleModel, connectionModel.TimeZoneInfoId);
            }
            catch (ArgumentException ex)
            {
                return(new BadRequestObjectResult(ex.Message));
            }

            if (await starter.TryStartSingletonAsync(nameof(ClearScheduleOrchestrator), ClearScheduleOrchestrator.InstanceId(clearScheduleModel.TeamId), clearScheduleModel).ConfigureAwait(false))
            {
                return(new OkResult());
            }
            else
            {
                return(new ConflictResult());
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Admin, "post", Route = "updateschedule")] UpdateScheduleModel updateScheduleModel,
            [DurableClient] IDurableOrchestrationClient starter,
            ILogger log)
        {
            log.LogUpdateSchedule(updateScheduleModel, nameof(UpdateScheduleTrigger));

            if (updateScheduleModel.UpdateAllTeams)
            {
                var connections = await _scheduleConnectorService.ListConnectionsAsync().ConfigureAwait(false);

                var teamIds = new List <string>();
                foreach (var connection in connections)
                {
                    teamIds.Add(connection.TeamId);
                }
                updateScheduleModel.TeamIds = string.Join(",", teamIds);
            }

            if (await starter.TryStartSingletonAsync(nameof(UpdateScheduleOrchestrator), UpdateScheduleOrchestrator.InstanceId, updateScheduleModel).ConfigureAwait(false))
            {
                return(new OkResult());
            }
            else
            {
                return(new ConflictResult());
            }
        }