/// <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); }
/// <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); }