public static void SendUserNameChanges() { var LogActivity = Carollo.GetApplicationActions(USER_NAME); if (!Carollo.IsLogSetUpForApp(LogActivity)) { return; } var UserNameChanges = Carollo.GetUserNameChanges(); if (UserNameChanges.Count > 0 && LogActivity[0].NotificatonEmailAddresses.Length > 3) { var body = "The following employee user names need to be changed in CEEC :" + Environment.NewLine + Environment.NewLine; foreach (Models.NameChanges userNameChange in UserNameChanges) { body += "Employee: " + userNameChange.EmpName + Environment.NewLine + "\tHCM email address: " + userNameChange.HCMUserId + Environment.NewLine + "\tCurrent CEEC user name: " + userNameChange.CeecUserId + Environment.NewLine + Environment.NewLine; } MailMessage message = new MailMessage(); var emailAddresses = LogActivity[0].NotificatonEmailAddresses.Split(';'); foreach (string address in emailAddresses) { message.To.Add(address); } message.Subject = "CEEC User Names Needing Updating: " + DateTime.Now.ToShortDateString(); message.From = new MailAddress("*****@*****.**"); message.Body = body; var smtp = new SmtpClient(ConfigurationManager.AppSettings["EmailHost"]); smtp.Send(message); } }
public static void SendErrors(string strError, string strApp) { //This code sends emails to whomever is set in the Applications table //Added Nancy Maze, Christian Varella, and Jorge Cano with Roy Hollis var LogActivity = Carollo.GetApplicationActions(USER_NAME); if (!Carollo.IsLogSetUpForApp(LogActivity)) { return; } var body = "The following error was generated by CEEC Data Transfer:" + Environment.NewLine + Environment.NewLine; body += strApp + Environment.NewLine + "Error:" + strError + Environment.NewLine + Environment.NewLine; body += "See Activity Log for more detail."; MailMessage message = new MailMessage(); var emailAddresses = LogActivity[0].NotificatonEmailAddresses.Split(';'); foreach (string address in emailAddresses) { message.To.Add(address); } message.Subject = "CEEC Data Transfer Error: " + DateTime.Now.ToShortDateString(); message.From = new MailAddress("*****@*****.**"); message.Body = body; var smtp = new SmtpClient(ConfigurationManager.AppSettings["EmailHost"]); smtp.Send(message); }
public static void SendCourseShellNotices() { var LogActivity = Carollo.GetApplicationActions(COURSE_SHELL); if (!Carollo.IsLogSetUpForApp(LogActivity)) { return; } try { var courseShells = Carollo.GetMissingCourseShells(); if (courseShells.Count > 0) { var body = "The following course shells need to be created in CEEC :" + Environment.NewLine + Environment.NewLine; foreach (Models.CourseShells shell in courseShells) { body += "Vendor: " + shell.Vendor + Environment.NewLine + "\tCourse External Id: " + shell.CourseId + Environment.NewLine + "\tCourse Title: " + shell.CourseName + Environment.NewLine + "\tCredit Hours: " + shell.CreditHours + Environment.NewLine + Environment.NewLine; } MailMessage message = new MailMessage(); var emailAddresses = LogActivity[0].NotificatonEmailAddresses.Split(';'); foreach (string address in emailAddresses) { message.To.Add(address); } message.Subject = "Course Shells For CEEC: " + DateTime.Now.ToShortDateString(); message.From = new MailAddress("*****@*****.**"); message.Body = body; var smtp = new SmtpClient(ConfigurationManager.AppSettings["EmailHost"]); smtp.Send(message); } } catch (Exception e) { Carollo.WriteToLog("Error at Email.SendCourseShellNotices: " + e.Message + Environment.NewLine + e.InnerException + Environment.NewLine + e.StackTrace, MessageType.Text, "System", ActionType.SetUpLog.ToString(), true, DateTime.Now, ""); } }
public static void Process(string Vendor) { var startDate = DateTime.Now; var processDate = DateTime.Now; int numberOfCoursesReviewed = 0; int numberOfCourseShell = 0; int numberOfEnrollments = 0; var vendorName = Vendor.Replace(" LMS", ""); try { var absorbCourses = new List <Courses>(); var LogActivity = Carollo.GetApplicationActions(Vendor); if (Carollo.IsLogSetUpForApp(LogActivity)) { // Absorb var LMSEmployees = new List <LMSEmployees>(); string token = AbsorbAPI.GetToken(); if (IsToken(token)) { LMSEmployees = AbsorbAPI.GetUsers(token); } else { Carollo.WriteToLog("CEEC token not valid.", MessageType.Text, Vendor, ActionType.SetUpLog.ToString(), true, processDate, vendorName); return; } var Completions = Carollo.GetCourseCompletions(vendorName); if (Completions.Count == 0) { Carollo.WriteToLog("No completion data.", MessageType.Text, Vendor, ActionType.SetUpLog.ToString(), true, processDate, vendorName); return; } // Group users together for user lookups Completions.Sort((x, y) => x.UserName_Email.CompareTo(y.UserName_Email)); var currentUserName = ""; var currentUserHasHCMData = false; var currentUserId = ""; var HCMEmployees = new List <HCMEmployees>(); HCMEmployees = Carollo.GetEmployees(); var userEnrollments = new List <Enrollments>(); var AbsorbUser = new LMSEmployees(); var currentHCMEmployee = new HCMEmployees(); foreach (var completion in Completions) { numberOfCoursesReviewed++; if (completion.UserName_Email != currentUserName) { currentUserHasHCMData = false; currentHCMEmployee = HCMEmployees.Find(item => item.UserName.ToLower() == completion.UserName_Email.ToLower()); if (currentHCMEmployee != null) { AbsorbUser = LMSEmployees.Find(item => item.UserName.ToLower() == completion.UserName_Email.ToLower()); if (AbsorbUser == null) { continue; } userEnrollments = AbsorbAPI.GetUserEnrollments(token, AbsorbUser.Id.Value); currentUserHasHCMData = true; currentUserId = AbsorbUser.Id.ToString(); } else { Carollo.SetCourseCompletionProcessedDate((int)completion.Id); Carollo.WriteToLog("No employee exist in HCM that matches the completion data for user " + completion.UserName_Email + ".", MessageType.Text, Vendor, ActionType.SetUpLog.ToString(), true, processDate, vendorName); continue; } currentUserName = completion.UserName_Email; } if (currentUserHasHCMData) { // fetch data only if needed and only once if (absorbCourses.Count == 0) { absorbCourses = AbsorbAPI.GetCourses(token); } var activityCourse = new Courses(); if (absorbCourses.Exists(item => item.ExternalId.ToUpper() == completion.CourseName.ToUpper())) { activityCourse = absorbCourses.Find(item => item.ExternalId.ToUpper() == completion.CourseName.ToUpper()); } if (activityCourse.ExternalId != null) { var needsUpdate = false; var userEnrollment = new Enrollments(); if (!userEnrollments.Exists(item => item.CourseId == activityCourse.Id && item.DateCompleted == completion.CompletionDate)) { var enrollment = AbsorbAPI.CreateEnrollment(token, currentUserId, activityCourse.Id.ToString()); if (enrollment == "") { continue; } Guid enrollmentGuid; if (Guid.TryParse(enrollment, out enrollmentGuid)) { numberOfEnrollments++; needsUpdate = true; userEnrollment = new Enrollments { Id = enrollmentGuid, CourseId = activityCourse.Id, UserId = (Guid)AbsorbUser.Id, IsActive = true, Progress = 1, Score = completion.Score, DateStarted = DateTime.Now, DateCompleted = completion.CompletionDate, TimeSpentTicks = 0, AcceptedTermsAndConditions = false }; Carollo.WriteToLog("Enrollment succeeded: " + enrollment, MessageType.Text, Carollo.DetermineAction(LogActivity[0], ActionType.UpdateEnrollment.ToString()), true, currentUserId, completion.CourseName, completion.CourseTitle, completion.UserName_Email, vendorName, ""); } else { Carollo.WriteToLog("Enrollment failed.", MessageType.Text, Carollo.DetermineAction(LogActivity[0], ActionType.WriteToLogError.ToString()), true, currentUserId, completion.CourseName, completion.CourseTitle, completion.UserName_Email, vendorName, ""); } } else { userEnrollment = userEnrollments.Find(item => item.CourseId == activityCourse.Id && item.DateCompleted == completion.CompletionDate); if (userEnrollment.Status != Status.Complete) { needsUpdate = true; } } if (needsUpdate) { var CourseEnrollment = ConstructCourseEnrollmentEmployee(userEnrollment); var UpdateResult = AbsorbAPI.UpdateEnrollmentCourse(token, (Guid)AbsorbUser.Id, CourseEnrollment); Carollo.WriteToLog(currentHCMEmployee.NickName + " " + currentHCMEmployee.LastName + " completed " + userEnrollment.CourseName + " results:" + UpdateResult, MessageType.Text, Carollo.DetermineAction(LogActivity[0], ActionType.UpdateEnrollment.ToString()), false, currentHCMEmployee.UserName, userEnrollment.CourseId.ToString(), userEnrollment.CourseName, currentHCMEmployee.EmployeeID, vendorName, ""); } Carollo.SetCourseCompletionProcessedDate((int)completion.Id); } else { numberOfCourseShell++; Carollo.WriteToLog("No course shell exist in CEEC that matches the completion data", MessageType.Text, Carollo.DetermineAction(LogActivity[0], ActionType.CourseShell.ToString()), true, currentUserId, completion.CourseName, completion.CourseTitle, completion.UserName_Email, vendorName, ""); } } else { Carollo.WriteToLog("No employee exist in HCM that matches the completion data for user " + completion.UserName_Email + ".", MessageType.Text, Vendor, ActionType.SetUpLog.ToString(), true, processDate, vendorName); } } Carollo.WriteToLog("External completion Courses to CEEC results: Courses Reviewed = " + numberOfCoursesReviewed + " - Courses Enrolled = " + numberOfEnrollments + " - Course Shells missing = " + numberOfCourseShell, MessageType.Text, Vendor, ActionType.ExecuteCompleted.ToString(), true, startDate, vendorName); } else { Carollo.WriteToLog("The Log Activity is not setup for this application", MessageType.Text, Vendor, ActionType.SetUpLog.ToString(), true, startDate, vendorName); } } catch (Exception ex) { Carollo.WriteToLog(ex.StackTrace, MessageType.Text, Vendor, ActionType.WriteToLogError.ToString(), true, startDate, vendorName); } }