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);
        }
Beispiel #2
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 <Contact> Handler(CustomEventRequest <BasicInput> lambdaEvent, ILambdaContext context)
        {
            string  userId;
            Contact contact = null;

            if (lambdaEvent.Input.Data != null)
            {
                ProcessDTO items = JsonConvert.DeserializeObject <ProcessDTO>(lambdaEvent.Input.Data);
                userId  = items.UserId;
                contact = items.Contact;
                if (items.ApiKey != null)
                {
                    HrApp.Settings.ApiKey = items.ApiKey;
                }
            }
            else
            {
                userId = Environment.GetEnvironmentVariable("userId");
                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(userId) || contact == null)
            {
                throw new BusinessException("userId and contact fields is required");
            }
            if (string.IsNullOrEmpty(contact.GivenName) || string.IsNullOrEmpty(contact.Surname) ||
                contact.EmailAddresses == null)
            {
                throw new BusinessException("Contact should have: GivenName, Surname, EmailAddresses fields filled");
            }

            GraphContactRepository graphContactRepo = new GraphContactRepository();

            //making name and surname first letters upper
            contact.GivenName = contact.GivenName.First().ToString().ToUpper() + contact.GivenName.Substring(1);
            contact.Surname   = contact.Surname.First().ToString().ToUpper() + contact.Surname.Substring(1);

            var createdContact = await graphContactRepo.CreateUserContact(userId, contact);

            return(createdContact);
        }
Beispiel #3
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 userId, contactId;

            if (lambdaEvent.Input.Data != null)
            {
                ProcessDTO items = JsonConvert.DeserializeObject <ProcessDTO>(lambdaEvent.Input.Data);
                userId    = items.UserId;
                contactId = items.ContactId;
                if (items.ApiKey != null)
                {
                    HrApp.Settings.ApiKey = items.ApiKey;
                }
            }
            else
            {
                userId    = Environment.GetEnvironmentVariable("userId");
                contactId = Environment.GetEnvironmentVariable("contactId");
                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(userId) || string.IsNullOrEmpty(contactId))
            {
                throw new BusinessException("All fields must be filled with data");
            }

            GraphContactRepository graphContactRepo = new GraphContactRepository();

            var isDeletedSuccessfully = await graphContactRepo.DeleteUserContact(
                userId, contactId);

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

            return(response);
        }
Beispiel #4
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        subject, organizerId, roomName, eventId;
            DateTime      startTime, endTime;
            List <string> participantsIds;

            if (lambdaEvent.Input.Data != "")
            {
                ProcessDTO items = JsonConvert.DeserializeObject <ProcessDTO>(lambdaEvent.Input.Data);
                subject         = items.Subject;
                organizerId     = items.OrganizerId;
                startTime       = items.StartTime;
                endTime         = items.EndTime;
                participantsIds = items.ParticipantsIds;
                roomName        = items.RoomName;
                eventId         = items.EventId;
                if (items.ApiKey != null)
                {
                    HrApp.Settings.ApiKey = items.ApiKey;
                }
            }
            else
            {
                subject         = Environment.GetEnvironmentVariable("subject");
                organizerId     = Environment.GetEnvironmentVariable("organizerId");
                startTime       = DateTime.Parse(Environment.GetEnvironmentVariable("startTime"));
                endTime         = DateTime.Parse(Environment.GetEnvironmentVariable("endTime"));
                participantsIds = Environment.GetEnvironmentVariable("participantsIds").Split(',').ToList();
                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(subject) ||
                string.IsNullOrEmpty(organizerId) || string.IsNullOrEmpty(eventId) ||
                participantsIds == null || participantsIds.Count == 0)
            {
                throw new BusinessException("All fields must be filled with data");
            }

            var roomService = new RoomBookerService()
            {
                GraphRepository      = new GraphRepository(),
                GraphEventRepository = new GraphEventsRepository(),
                GraphUserRepository  = new GraphUserRepository()
            };

            var newBooking =
                new Booking(roomName, organizerId, startTime, endTime, participantsIds, subject);

            var isEditedSuccessfully = await roomService.EditBooking(eventId, newBooking);

            var respopnse = new Dictionary <string, bool>
            {
                { "isEditedSuccessfully", isEditedSuccessfully }
            };

            return(respopnse);
        }
Beispiel #5
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 <GraphUser> Handler(CustomEventRequest <BasicInput> lambdaEvent, ILambdaContext context)
        {
            string displayName, password, email;

            if (lambdaEvent.Input.Data != null)
            {
                ProcessDTO items = JsonConvert.DeserializeObject <ProcessDTO>(lambdaEvent.Input.Data);
                displayName = items.DisplayName;
                email       = items.Email;
                password    = items.Password;
                if (items.ApiKey != null)
                {
                    HrApp.Settings.ApiKey = items.ApiKey;
                }
            }
            else
            {
                displayName = Environment.GetEnvironmentVariable("displayName");
                email       = Environment.GetEnvironmentVariable("email");
                password    = Environment.GetEnvironmentVariable("password");
                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(email) || string.IsNullOrEmpty(displayName) ||
                string.IsNullOrEmpty(password))
            {
                throw new BusinessException("All fields must be filled with data");
            }

            try
            {
                var addr = new System.Net.Mail.MailAddress(email);
                if (addr.Address != email)
                {
                    throw new BusinessException("Your email is invalid");
                }
            }
            catch
            {
                throw new BusinessException("Your email is invalid");
            }
            if (password.Length < 8)
            {
                throw new BusinessException("Password must contain at least 8 characters");
            }
            if (!password.Any(char.IsUpper))
            {
                throw new BusinessException("Password must contain at least one upper char");
            }
            if (!password.Any(char.IsDigit))
            {
                throw new BusinessException("Password must contain at least one digit");
            }

            var user = new GraphUser
            {
                AccountEnabled    = true,
                DisplayName       = displayName,
                UserPrincipalName = email,
                MailNickname      = email.Split('@')[0],
                PasswordProfile   = new PasswordProfile
                {
                    ForceChangePasswordNextSignIn = true,
                    Password = password
                }
            };

            GraphUserRepository graphUserRepo = new GraphUserRepository();
            var createdUser = await graphUserRepo.CreateGraphUser(user);

            return(createdUser);
        }