/// <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 <APIGatewayProxyResponse> Handler(CustomEventRequest <BasicInput> lambdaEvent, ILambdaContext context) { // - Get environment variable var divisionId = Environment.GetEnvironmentVariable("division"); var division = new Division { Id = divisionId }; var lunchService = new LunchService { HrService = new HrService { EmployeesRepository = new EmployeesRepository() }, MenuRepository = new MenuRepository() }; var menu = await lunchService.CreateBlankMenu(division); var body = new Dictionary <string, string> { { "menu", menu.Id } }; return(new APIGatewayProxyResponse { Body = JsonConvert.SerializeObject(body), StatusCode = 200, Headers = new Dictionary <string, string> { { "Content-Type", "application/json" } } }); }
public IActionResult CreateCustomEvent([FromBody] CustomEventRequest data) { var modelStateErrors = this.ModelState.Values.SelectMany(m => m.Errors); var user = _userManager.GetUserAsync(User).Result; // Initialize database objects var course = new Course() { CourseAbbreviation = data.Name, User = user }; var section = new Section() { Course = course }; var meeting = new Meeting() { IsUnique = true, MeetingType = MeetingType.CustomEvent, Code = "A00", Days = data.Days, StartTime = new DateTime(1, 1, 1, data.StartTime.Hour, data.StartTime.Minute, 0), EndTime = new DateTime(1, 1, 1, data.EndTime.Hour, data.EndTime.Minute, 0), }; // Add back connections section.Meetings.Add(meeting); course.Sections.Add(section); var userSection = new UserSection() { Section = section, User = user, }; // Add to database _context.Courses.Add(course); _context.Sections.Add(section); _context.Meetings.Add(meeting); _context.UserSections.Add(userSection); _context.SaveChanges(); // Return response object var calendarEvents = FormatRepo.PopulateSectionEventsForBase(new List <Section> { section }, course) .Select(d => d.Value).First(); var response = new CustomEventResponse { CourseId = course.Id, SectionId = section.Id, CourseAbbreviation = course.CourseAbbreviation, CalendarEvents = calendarEvents }; return(Json(response)); }
public async Task <APIGatewayProxyResponse> Handler(CustomEventRequest <BasicInput> lambdaEvent, ILambdaContext context) { //var lunchDate = DateTime.Parse(Environment.GetEnvironmentVariable("lunchTime")); // var menuID = Environment.GetEnvironmentVariable("menuID"); var lunchDate = DateTime.Parse("2020-02-09"); var menuID = "5e3c016f214efe00018721ab"; var service = new CodeMashRepository <MenuEntity>(Client); var menuEntity = await service.FindOneByIdAsync( menuID, new DatabaseFindOneOptions() ); var menu = new Menu(DateTime.Now, null, null) { Id = menuID, Division = new Division() { Id = menuEntity.DivisionId } }; var lunchService = new LunchService() { HrService = new HrService() { EmployeesRepository = new EmployeesRepository() }, MenuRepository = new MenuRepository(), NotificationSender = new NotificationSender() }; await lunchService.AdjustMenuLunchTime(lunchDate, menu, menuEntity.Employees); var response = new { lambdaEvent, }; return(new APIGatewayProxyResponse { Body = JsonConvert.SerializeObject(response), StatusCode = 200, Headers = new Dictionary <string, string> { { "Content-Type", "application/json" } } }); }
/// <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 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); }
/// <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); }
/// <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 <APIGatewayProxyResponse> Handler(CustomEventRequest <BasicInput> lambdaEvent, ILambdaContext context) { var menuRepo = new MenuRepository(); var menu = await menuRepo.GetClosestMenu(); var lunchService = new LunchService { MenuRepository = menuRepo, NotificationSender = new NotificationSender() }; var response = await lunchService.SendMessageAboutFoodOrder(menu); return(new APIGatewayProxyResponse { Body = JsonConvert.SerializeObject(response), StatusCode = 200, Headers = new Dictionary <string, string> { { "Content-Type", "application/json" } } }); }
public async Task <APIGatewayProxyResponse> Handler(CustomEventRequest <CollectionTriggerInput> lambdaEvent, ILambdaContext context) { var records = lambdaEvent.Input.NewRecord; DTO items = JsonConvert.DeserializeObject <DTO>(records); if (Environment.GetEnvironmentVariable("ApiKey") != null) { HrApp.Settings.ApiKey = Environment.GetEnvironmentVariable("ApiKey"); } var ImportFileRepo = new ImportFileRepository(); var hrService = new HrService() { FileRepository = new FileRepository(), NoobRepository = new NoobRepository(), EmployeesRepository = new EmployeesRepository(), AbsenceRequestRepository = new AbsenceRepository(), NotificationSender = new NotificationSender() }; await hrService.GenerateFileWithSignatureAndInsert(items.AbsenceRequestId); var response = new { lambdaEvent, }; return(new APIGatewayProxyResponse { Body = JsonConvert.SerializeObject(response), StatusCode = 200, Headers = new Dictionary <string, string> { { "Content-Type", "application/json" } } }); }
/// <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); }
/// <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 <APIGatewayProxyResponse> Handler(CustomEventRequest <CollectionTriggerInput> lambdaEvent, ILambdaContext context) { var response = JsonConvert.DeserializeObject <AbsenceRequest>(lambdaEvent.Input.NewRecord); var requestId = response.Id; #region Initialization const string appSettings = "appsettings.json"; string projectIdString; string apiKey; using (StreamReader reader = new StreamReader(appSettings)) { string jsonString = reader.ReadToEnd(); var dataJson = JObject.Parse(jsonString); apiKey = dataJson["CodeMash"]["ApiKey"].ToString(); projectIdString = dataJson["CodeMash"]["ProjectId"].ToString(); } var projectId = Guid.Parse(projectIdString); // 2. Create a general client for API calls var client = new CodeMashClient(apiKey, projectId); var pushService = new CodeMashPushService(client); // 3. Create a service object List <string> usersThatShouldApprove = new List <string>(); List <string> requiredRoles = new List <string> { "ceo", "accountant", "cto", "hr" }; var employees = new CodeMashRepository <PCEmployee>(client); var requests = new CodeMashRepository <AbsenceRequest>(client); #endregion var membershipService = new CodeMashMembershipService(client); var allUsersList = membershipService.GetUsersList(new GetUsersRequest()); // Employee ID var employeeId = requests.FindOne(x => x.Id == requestId).Employee; // Employee manager ID var employeeManagerId = employees.FindOne(x => x.Id == employeeId).Manager; var employeeManagerUserId = employees.FindOne(x => x.Id == employeeManagerId).AppUserID; // Adding user with required roles to local users that should approve list foreach (var user in allUsersList.Result) { foreach (var userRole in user.Roles) { if (requiredRoles.Contains(userRole.Name)) { usersThatShouldApprove.Add(user.Id); break; } } } // Adding manager to users that should approve list foreach (var user in allUsersList.Result) { if (user.Id == employeeManagerUserId && !usersThatShouldApprove.Contains(user.Id)) { Console.WriteLine(user.FirstName + " " + user.LastName); usersThatShouldApprove.Add(user.Id); break; } } // Adding to should be approved by list foreach (var userId in usersThatShouldApprove) { requests.UpdateOne(x => x.Id == requestId, Builders <AbsenceRequest> .Update.AddToSet("should_be_approved_by", userId)); } List <Guid> userGuids = new List <Guid>(); string templateId = "02dd0ea0-79b2-4a9c-a10b-4009894958b3"; // Convertion to guid list foreach (var userId in usersThatShouldApprove) { userGuids.Add(Guid.Parse(userId)); } // Sending notifications to each user pushService.SendPushNotification(new SendPushNotificationRequest { TemplateId = Guid.Parse(templateId), Users = userGuids } ); return(new APIGatewayProxyResponse { Body = "lol", StatusCode = 200, Headers = new Dictionary <string, string> { { "Content-Type", "application/json" } } }); }
/// <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); }