Beispiel #1
0
        /// <summary>
        /// (Required) Entry method of your Lambda function.
        /// </summary>
        /// <param name="lambdaEvent">Type returned from CodeMash</param>
        /// <param name="context">Context data of a function (function config)</param>
        /// <returns></returns>
        public async Task <Dictionary <string, bool> > Handler(CustomEventRequest <BasicInput> lambdaEvent, ILambdaContext context)
        {
            string roomName, eventId;

            if (lambdaEvent.Input.Data != "")
            {
                ProcessDTO items = JsonConvert.DeserializeObject <ProcessDTO>(lambdaEvent.Input.Data);
                roomName = items.RoomName;
                eventId  = items.EventId;
                if (items.ApiKey != null)
                {
                    HrApp.Settings.ApiKey = items.ApiKey;
                }
            }
            else
            {
                roomName = Environment.GetEnvironmentVariable("roomName");
                eventId  = Environment.GetEnvironmentVariable("eventId");
                if (Environment.GetEnvironmentVariable("apiKey") != null)
                {
                    HrApp.Settings.ApiKey = Environment.GetEnvironmentVariable("apiKey");
                }
            }
            if (HrApp.Settings.ApiKey == null)
            {
                throw new BusinessException("ApiKey not set");
            }
            if (string.IsNullOrEmpty(roomName) || string.IsNullOrEmpty(eventId))
            {
                throw new BusinessException("All fields must be filled with data");
            }

            var roomService = new RoomBookerService()
            {
                GraphRepository      = new GraphRepository(),
                GraphEventRepository = new GraphEventsRepository(),
                GraphUserRepository  = new GraphUserRepository()
            };
            var isCanceled = await roomService.CancelBooking(eventId, roomName);

            var response = new Dictionary <string, bool>
            {
                { "isCanceled", isCanceled }
            };

            return(response);
        }