public bool RecallLeave(string pkleaveInfoID, string employeeID) { Log.Info(GlobalParams.StartRecallLeave); bool result = false; try { EmailConfig.SetRootPath(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath); LeaveInfo leaveInfo = LeaveBLL.GetLeaveInfoByID(pkleaveInfoID); result = LeaveBLL.RecallLeave(pkleaveInfoID); Employee employee = EmployeeBLL.GetEmployeeByID(employeeID); if (result && EmailConfig.EmailTemplates.ContainsKey(EmailType.ApplyLeave.ToString())) { Log.Info(GlobalParams.StartMail); EmailContent ec = EmailConfig.EmailTemplates[EmailType.RecallLeave.ToString()]; // {0} - Manager First Name // {1} - First Name // {2} - Hours // {3} - Leave Type // {4} - Reason // {5} - Description // {6} - Start // {7} - End // {8} - CARSAddress string emailBody = string.Format(ec.Body, employee.Manager.FirstName, employee.FirstName, leaveInfo.Hours, leaveInfo.Type.Name + " Leave", leaveInfo.Reason, leaveInfo.Description, leaveInfo.FirstStartTime.ToString(EmailConfig.TimeFormatInEmail), leaveInfo.LastEndTime.ToString(EmailConfig.TimeFormatInEmail), EmailConfig.CARSAddress); // {0} - First Name // {1} - Hours // {2} - Leave Type string emailTitle = string.Format(ec.Title, employee.FirstName, leaveInfo.Hours, leaveInfo.Type.Name + " Leave"); string employeeEmail = GetEmail(employee.Email); string managerEmail = GetEmail(employee.Manager.Email); List <string> ccList = new List <string>(); ccList.Add(employeeEmail); #if DEBUG managerEmail = "*****@*****.**"; #endif SendMail sender = new SendMail(managerEmail, ccList, EmailConfig.EmailAccount, emailBody, emailTitle, EmailConfig.Password, EmailConfig.Host); sender.Send(); Log.Info(GlobalParams.EndMail); } else { Log.Warn(GlobalParams.MailError); throw new Exception(GlobalParams.MailError); } } catch (Exception ex) { Log.Exception(ex.StackTrace); Log.Exception(ex.Message); throw ex; } Log.Info(GlobalParams.EndRecallLeave); return(result); }
static void Main(string[] args) { debugMode = File.Exists(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "debug.txt")); EmailConfig.SetRootPath(Environment.CurrentDirectory); EmailConfig.RefreshData(); ec = EmailConfig.EmailTemplates[EmailType.ReminderEmail.ToString()]; List <Employee> managers = EmployeeBLL.GetManagers(); foreach (Employee m in managers) { #if DEBUG //if (m.Email.ToLower() != "*****@*****.**") // continue; #endif if (m.IsActive) { //Console.WriteLine(m.FirstName + " " + m.LastName); if (SendReminderEmail(m)) { Info("Email sent out!"); #if DEBUG //break; #endif } } } #if DEBUG Console.WriteLine("Done"); Console.ReadKey(); #endif }
/// <summary> /// Register a new employee in system and send an email to hime/her with default password. /// </summary> /// <param name="email">This email should be a valid email address as system will send register email to it.</param> /// <param name="firstName">Not null in database.</param> /// <param name="middleName">Could be null in database.</param> /// <param name="lastName">Not null in database.</param> /// <param name="gender">Not null in database.</param> /// <param name="serviceYear">Count how many years the worker works.</param> /// <param name="dateOfHire">Hired date in our company.</param> /// <param name="supervisorEmail">Could be null in database. The email of his/her manager.</param> /// <returns>Return type is Employee. Returns the employee who is registered just now.</returns> public Employee AddEmployee(string email, string firstName, string middleName, string lastName, string legalName, Sex gender, float serviceYear, DateTime dateOfHire, string supervisorEmail, string costCenterCode, int employeeNum) { Log.Info(GlobalParams.StartAddEmpl); Employee newEmployee = null; try { newEmployee = EmployeeBLL.AddEmployee(email, firstName, middleName, lastName, gender, serviceYear, dateOfHire, supervisorEmail, costCenterCode, employeeNum, legalName); EmailConfig.SetRootPath(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath); // If add new employee, send a notification email to user. if (newEmployee != null && EmailConfig.EmailTemplates.ContainsKey(EmailType.Register_ToEmployeeSelf.ToString())) { Log.Info(GlobalParams.StartMail); string mEmail = GetEmail(newEmployee.Email); string firstNmae = newEmployee.FirstName; string userName = newEmployee.Email.Replace(GlobalParams.AdventMail, "").ToLower(); EmailContent ec = EmailConfig.EmailTemplates[EmailType.Register_ToEmployeeSelf.ToString()]; // {0} - First Name // {1} - Account (User Name) // {2} - Password // {3} - CARSAddress string emailBody = string.Format(ec.Body, firstName, userName, CryptographyStuff.AES_DecryptString(newEmployee.Password), EmailConfig.CARSAddress); SendMail sender = new SendMail(mEmail, null, EmailConfig.EmailAccount, emailBody, ec.Title, EmailConfig.Password, EmailConfig.Host); sender.Send(); Log.Info(GlobalParams.EndMail); } else { Log.Warn(GlobalParams.MailError); throw new Exception(GlobalParams.MailError); } } catch (SqlException sqlEx) { if (sqlEx.Message.Contains("UniqueKeyEmail")) // try to add duplicate account { Log.Warn("Try to register a duplicate account." + Environment.NewLine + email); throw new Exception(email + " was registered already." + Environment.NewLine + "Try another email account or contact with Administrator."); } else { throw sqlEx; } } catch (Exception ex) { Log.Exception(ex.StackTrace); Log.Exception(ex.Message); throw ex; } Log.Info(GlobalParams.EndAddEmpl); return(newEmployee); }
/// <summary> /// Approve leave /// </summary> /// <param name="managerID">GUID of supervisor</param> /// <param name="leaveID">GUID of leave</param> /// <param name="status">Leave status</param> /// <returns>Approved leave</returns> public LeaveInfo ApproveLeave(string managerID, string leaveID, LeaveStatus status) { Log.Info(GlobalParams.StartApproveLeave); LeaveInfo result = null; try { result = LeaveBLL.ApproveLeave(managerID, leaveID, status); Employee employee = EmployeeBLL.GetEmployeeByID(result.FKSubmitEmployeeID.ToString()); Employee manager = EmployeeBLL.GetEmployeeByID(result.FKReportManagerID.ToString()); if (result != null) { Log.Info(GlobalParams.StartMail); EmailConfig.SetRootPath(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath); EmailContent ec = EmailConfig.EmailTemplates[EmailType.ApproveLeave.ToString()]; // {0} - First Name // {1} - Manager First Name // {2} - Hours // {3} - Leave Type // {4} - Reason // {5} - Description // {6} - Start // {7} - End // {8} - "Approved" // {9} - "" // {10} - CARSAddress string emailBody = string.Format(ec.Body, employee.FirstName, manager.FirstName, result.Hours, result.Type.Name + " Leave", result.Reason, result.Description, result.FirstStartTime.ToString(EmailConfig.TimeFormatInEmail), result.LastEndTime.ToString(EmailConfig.TimeFormatInEmail), "Approved", "", EmailConfig.CARSAddress); // {0} - First Name // {1} - Hours // {2} - Leave Type // {3} - Manager First Name // {4} - "Approved" string emailTitle = string.Format(ec.Title, employee.FirstName, result.Hours, result.Type.Name + " Leave", manager.FirstName, "Approved"); string employeeEmail = GetEmail(employee.Email); string managerEmail = GetEmail(employee.Manager.Email); #if DEBUG managerEmail = "*****@*****.**"; #endif List <string> ccList = new List <string>(); ccList.Add(managerEmail); SendMail sender = new SendMail(employeeEmail, ccList, EmailConfig.EmailAccount, emailBody, emailTitle, EmailConfig.Password, EmailConfig.Host); sender.Send(); Log.Info(GlobalParams.EndMail); } } catch (Exception ex) { Log.Exception(ex.StackTrace); Log.Exception(ex.Message); throw ex; } Log.Info(GlobalParams.EndApproveLeave); return(result); }
/// <summary> /// Forget password /// </summary> /// <param name="email">Email address to receive password</param> /// <returns>True or false</returns> public bool ForgetPassword(string email) { Log.Info(GlobalParams.StartForgetPwd); try { EmailConfig.SetRootPath(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath); Employee employee = EmployeeBLL.GetEmployeeByEmail(email); if (employee != null && EmailConfig.EmailTemplates.ContainsKey(EmailType.ForgetPassword.ToString())) { email = GetEmail(email); EmailContent emailContent = EmailConfig.EmailTemplates[EmailType.ForgetPassword.ToString()]; // {0} - First Name // {1} - Password // {2} - CARSAddress string emailBody = string.Format(emailContent.Body, employee.FirstName, CryptographyStuff.AES_DecryptString(employee.Password), EmailConfig.CARSAddress); SendMail sender = new SendMail(email, null, EmailConfig.EmailAccount, emailBody, emailContent.Title, EmailConfig.Password, EmailConfig.Host); sender.Send(); } else { Log.Warn(GlobalParams.PwdError); return(false); } } catch (Exception ex) { Log.Exception(ex.StackTrace); Log.Exception(ex.Message); throw ex; } Log.Info(GlobalParams.EndForgetPwd); return(true); }