public void SendDelegationEmail(VehicleManagement model, EmailTemplate EmailTempalte, List <EmployeeInfo> toUsers, string webUrl) { var link = string.Format(@"{0}/Lists/VehicleManagement/EditForm.aspx?subSection=TransportationManagement&ID={1}&Source=/_layouts/15/RBVH.Stada.Intranet.WebPages/DelegationManagement/DelegationList.aspx&Source=Tab=DelegationsApprovalTab", webUrl, model.ID); var department = DepartmentListSingleton.GetDepartmentByID(model.CommonDepartment.LookupId, this.SiteUrl); SendEmailActivity sendMailActivity = new SendEmailActivity(); if (toUsers != null) { foreach (var toUser in toUsers) { try { if (!string.IsNullOrEmpty(toUser.Email)) { var content = HTTPUtility.HtmlDecode(EmailTempalte.MailBody); content = content.Replace("{0}", toUser.FullName); content = content.Replace("{1}", model.Requester.LookupValue); content = content.Replace("{2}", model.From.ToString("dd/MM/yyy hh:mm")); content = content.Replace("{3}", model.ToDate.ToString("dd/MM/yyy hh:mm")); content = content.Replace("{4}", department.Name); content = content.Replace("{5}", department.VietnameseName); content = content.Replace("#link", link); sendMailActivity.SendMail(webUrl, EmailTempalte.MailSubject, toUser.Email, true, false, content); } } catch { } } } }
public void SendEmail(BusinessTripManagement businessTripManagement, EmailTemplate emailTemplate, EmployeeInfo approver, EmployeeInfo toUser, string webUrl, bool isApprovalLink) { if (toUser == null || string.IsNullOrEmpty(toUser.Email) || emailTemplate == null || businessTripManagement == null || string.IsNullOrEmpty(webUrl)) { return; } var content = HTTPUtility.HtmlDecode(emailTemplate.MailBody); content = content.Replace("{0}", toUser.FullName); if (emailTemplate.MailKey.ToLower() == "businesstripmanagement_approve" || emailTemplate.MailKey.ToLower() == "businesstripmanagement_reject") { content = content.Replace("{1}", approver.FullName); content = content.Replace("{2}", businessTripManagement.Requester.LookupValue); content = content.Replace("{3}", businessTripManagement.BusinessTripPurpose); string typeOfBusinessTrip = ""; if (businessTripManagement.Domestic) { typeOfBusinessTrip = ResourceHelper.GetLocalizedString("BusinessTripManagement_BusinessTripTypeInternalTitle", StringConstant.ResourcesFileLists, 1033); content = content.Replace("{4}", typeOfBusinessTrip); typeOfBusinessTrip = ResourceHelper.GetLocalizedString("BusinessTripManagement_BusinessTripTypeInternalTitle", StringConstant.ResourcesFileLists, 1066); content = content.Replace("{5}", typeOfBusinessTrip); } else { typeOfBusinessTrip = ResourceHelper.GetLocalizedString("BusinessTripManagement_BusinessTripTypeExternalTitle", StringConstant.ResourcesFileLists, 1033); content = content.Replace("{4}", typeOfBusinessTrip); typeOfBusinessTrip = ResourceHelper.GetLocalizedString("BusinessTripManagement_BusinessTripTypeExternalTitle", StringConstant.ResourcesFileLists, 1066); content = content.Replace("{5}", typeOfBusinessTrip); } } else { content = content.Replace("{1}", businessTripManagement.Requester.LookupValue); content = content.Replace("{2}", businessTripManagement.BusinessTripPurpose); string typeOfBusinessTrip = ""; if (businessTripManagement.Domestic) { typeOfBusinessTrip = ResourceHelper.GetLocalizedString("BusinessTripManagement_BusinessTripTypeInternalTitle", StringConstant.ResourcesFileLists, 1033); content = content.Replace("{3}", typeOfBusinessTrip); typeOfBusinessTrip = ResourceHelper.GetLocalizedString("BusinessTripManagement_BusinessTripTypeInternalTitle", StringConstant.ResourcesFileLists, 1066); content = content.Replace("{4}", typeOfBusinessTrip); } else { typeOfBusinessTrip = ResourceHelper.GetLocalizedString("BusinessTripManagement_BusinessTripTypeExternalTitle", StringConstant.ResourcesFileLists, 1033); content = content.Replace("{3}", typeOfBusinessTrip); typeOfBusinessTrip = ResourceHelper.GetLocalizedString("BusinessTripManagement_BusinessTripTypeExternalTitle", StringConstant.ResourcesFileLists, 1066); content = content.Replace("{4}", typeOfBusinessTrip); } } var link = GetEmailLinkByUserPosition(webUrl, toUser.EmployeePosition.LookupId, businessTripManagement.ID, isApprovalLink); content = content.Replace("#link", link); SendEmailActivity sendMailActivity = new SendEmailActivity(); sendMailActivity.SendMail(webUrl, emailTemplate.MailSubject, toUser.Email, true, false, content); }
/// <summary> /// Send email to Requester after /// </summary> /// <param name="changeshiftItemId"></param> /// <returns></returns> /// CALL URL: /_vti_bin/Services/Email/EmailService.svc/SendChangeShiftRequestMail/1/BOD public bool SendChangeShiftRequestMail(string changeshiftItemId, string toRole) { try { int idValue; if (int.TryParse(changeshiftItemId, out idValue)) { var changeShiftManagementItem = _changeShiftManagementDAL.GetByID(idValue); var changeshiftRequestMailItem = _emailTemplateDAL.GetByKey("ChangeShift_Request"); if (changeshiftRequestMailItem != null && changeShiftManagementItem != null) { string email = string.Empty; string employeeFullname = string.Empty; string link = string.Empty; if (toRole.Equals("DH")) { var accountDHItem = _employeeDAL.GetByADAccount(changeShiftManagementItem.DepartmentHead.ID); email = accountDHItem.Email; employeeFullname = accountDHItem.FullName; link = $"{WebUrl}/{StringConstant.WebPageLinks.ChangeShiftManager}"; } else if (toRole.Equals("BOD")) { var accountBODItem = _employeeDAL.GetByADAccount(changeShiftManagementItem.BOD.ID); email = accountBODItem.Email; employeeFullname = accountBODItem.FullName; link = $"{WebUrl}/{StringConstant.WebPageLinks.ChangeShiftBOD}"; } if (!string.IsNullOrEmpty(email)) { var shiftTimeList = _shiftTimeDAL.GetShiftTimes(); string emailBody = HTTPUtility.HtmlDecode(changeshiftRequestMailItem.MailBody); //lookup email var fromShiftItem = shiftTimeList.Where(x => x.ID == changeShiftManagementItem.FromShift.LookupId).FirstOrDefault(); var toShiftItem = shiftTimeList.Where(x => x.ID == changeShiftManagementItem.ToShift.LookupId).FirstOrDefault(); emailBody = string.Format(emailBody, employeeFullname, changeShiftManagementItem.Requester.LookupValue, changeShiftManagementItem.FromDate.ToString(StringConstant.DateFormatddMMyyyy2), changeShiftManagementItem.ToDate.ToString(StringConstant.DateFormatddMMyyyy2), changeShiftManagementItem.Reason, fromShiftItem.Code, toShiftItem.Code); emailBody = emailBody.Replace("#link", link); _sendMailActivity.SendMail(SPContext.Current.Web.Url, changeshiftRequestMailItem.MailSubject, email, true, false, emailBody); return(true); } } } return(false); } catch (Exception ex) { ULSLogging.Log(new SPDiagnosticsCategory("STADA - Email Service - SendChangeShiftRequestMail fn", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, string.Format(CultureInfo.InvariantCulture, "{0}:{1}", ex.Message, ex.StackTrace)); return(false); } }
/// <summary> /// /// </summary> /// <param name="notOvertimeItemId"></param> /// <param name="result"></param> /// <returns></returns> /// CALL URL: /_vti_bin/Services/Email/EmailService.svc/SendNotOvertimeRequestResultEmail/1/Approve public bool SendNotOvertimeRequestResultEmail(string notOvertimeItemId, string result) { try { int idValue; if (int.TryParse(notOvertimeItemId, out idValue)) { string key = string.Empty; if (result.Equals("Approve")) { key = "LOAbsence_Approve"; } else if (result.Equals("Reject")) { key = "LOAbsence_Reject"; } if (!string.IsNullOrEmpty(key)) { var notOvertimeRequestMailItem = _emailTemplateDAL.GetByKey(key); var notOvertimeManagementItem = _notOvertimeMangementDAL.GetByID(idValue); if (notOvertimeRequestMailItem != null && notOvertimeManagementItem != null) { var employee = _employeeDAL.GetByID(notOvertimeManagementItem.Requester.LookupId); if (employee != null && !string.IsNullOrEmpty(employee.Email)) { string emailBody = HTTPUtility.HtmlDecode(notOvertimeRequestMailItem.MailBody); //lookup email string link = $"{WebUrl}/{StringConstant.WebPageLinks.LeaveOfAbsenceMember}"; if (employee.EmployeePosition.LookupId == (int)StringConstant.EmployeePosition.Administrator) { link = $"{WebUrl}/{StringConstant.WebPageLinks.LeaveOfAbsenceAdmin}"; } if (employee.EmployeePosition.LookupId == (int)StringConstant.EmployeePosition.DepartmentHead) { link = $"{WebUrl}/{StringConstant.WebPageLinks.LeaveOfAbsenceManager}"; } emailBody = string.Format(emailBody, employee.FullName, notOvertimeManagementItem.Requester.LookupValue, notOvertimeManagementItem.Date.ToString(StringConstant.DateFormatddMMyyyy2), notOvertimeManagementItem.Reason, notOvertimeManagementItem.Comment); emailBody = emailBody.Replace("#link", link); _sendMailActivity.SendMail(SPContext.Current.Web.Url, notOvertimeRequestMailItem.MailSubject, employee.Email, true, false, emailBody); return(true); } } } } return(false); } catch (Exception ex) { ULSLogging.Log(new SPDiagnosticsCategory("STADA - Email Service - SendNotOvertimeRequestResultEmail fn", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, string.Format(CultureInfo.InvariantCulture, "{0}:{1}", ex.Message, ex.StackTrace)); return(false); } }
/// <summary> /// /// </summary> /// <param name="notOvertimeItemId"></param> /// <param name="toRole"></param> /// <returns></returns> /// CALL URL: : /_vti_bin/Services/Email/EmailService.svc/SendNotovertimeRequestRequestEmail/1/BOD public bool SendNotOverTimeRequestEmail(string notOvertimeItemId, string toRole) { try { int idValue; if (int.TryParse(notOvertimeItemId, out idValue)) { var notOvertimeManagementItem = _notOvertimeMangementDAL.GetByID(idValue); var notOvertimeRequestMailItem = _emailTemplateDAL.GetByKey("LOAbsence_Request"); if (notOvertimeRequestMailItem != null && notOvertimeManagementItem != null) { string link = string.Empty; string email = string.Empty; string empployeeFullname = string.Empty; if (toRole.Equals("DH")) { if (notOvertimeManagementItem.DH != null) { var accountDHItem = _employeeDAL.GetByADAccount(notOvertimeManagementItem.DH.ID); email = accountDHItem.Email; empployeeFullname = accountDHItem.FullName; link = $"{WebUrl}/{StringConstant.WebPageLinks.LeaveOfAbsenceManager}#tab2"; } } else if (toRole.Equals("BOD")) { if (notOvertimeManagementItem.DH != null) { var accountBODItem = _employeeDAL.GetByADAccount(notOvertimeManagementItem.DH.ID); email = accountBODItem.Email; empployeeFullname = accountBODItem.FullName; link = $"{WebUrl}/{StringConstant.WebPageLinks.LeaveOfAbsenceBOD}#tab2"; } } if (!string.IsNullOrEmpty(email)) { string emailBody = HTTPUtility.HtmlDecode(notOvertimeRequestMailItem.MailBody); //lookup email emailBody = string.Format(emailBody, empployeeFullname, notOvertimeManagementItem.Requester.LookupValue, notOvertimeManagementItem.Date.ToString(StringConstant.DateFormatddMMyyyy2), notOvertimeManagementItem.Reason); emailBody = emailBody.Replace("#link", link); _sendMailActivity.SendMail(SPContext.Current.Web.Url, notOvertimeRequestMailItem.MailSubject, email, true, false, emailBody); return(true); } } } return(false); } catch (Exception ex) { ULSLogging.Log(new SPDiagnosticsCategory("STADA - Email Service - SendNotOverTimeRequestEmail fn", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, string.Format(CultureInfo.InvariantCulture, "{0}:{1}", ex.Message, ex.StackTrace)); return(false); } }
//public override void ItemUpdated(SPItemEventProperties properties) //{ // base.ItemUpdated(properties); // try // { // //_employeeInfoDAL = new EmployeeInfoDAL(properties.WebUrl); // //var itemId = properties.ListItem.ID; // //string modifiedByName = string.Empty; // //var modifiedByString = Convert.ToString(properties.ListItem["Modified By"]); // //SPFieldUser spUserField = (SPFieldUser)properties.ListItem.Fields.GetField("Modified By"); // //if (spUserField != null) // //{ // // SPFieldUserValue spNewUserFieldValue = (SPFieldUserValue)spUserField.GetFieldValue(modifiedByString); // // SPUser spModifiedByUser = properties.Web.EnsureUser(spNewUserFieldValue.LookupValue); // // var modifiedBy = _employeeInfoDAL.GetByADAccount(spModifiedByUser.ID); // // modifiedByName = modifiedBy != null ? modifiedBy.FullName : string.Empty; // //} // //SendEmailToApprover(properties.Web, itemId, modifiedByName); // } // catch (Exception ex) // { // ULSLogging.Log(new SPDiagnosticsCategory("STADA - Shift Management Event Receiver - ItemUpdated fn", // TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, // string.Format(CultureInfo.InvariantCulture, "{0}:{1}", ex.Message, ex.StackTrace)); // } //} private void SendEmailToApprover(SPWeb web, int itemId, string modifiedBy = "") { EmployeeInfoDAL employeeInfoDAL = new EmployeeInfoDAL(web.Url); EmailTemplateDAL emailTemplateDAL = new EmailTemplateDAL(web.Url); ShiftManagementDAL shiftManagementDAL = new ShiftManagementDAL(web.Url); var shiftManagementItem = shiftManagementDAL.GetByID(itemId); if (shiftManagementItem != null) { SPUser departmentHeadSPUser = web.EnsureUser(shiftManagementItem.ApprovedBy.UserName); var departmentHead = employeeInfoDAL.GetByADAccount(departmentHeadSPUser.ID); if (departmentHead != null) { var requestEmailItem = emailTemplateDAL.GetByKey("ShiftManagement_Request"); if (requestEmailItem != null) { string emailBody = HTTPUtility.HtmlDecode(requestEmailItem.MailBody); if (!string.IsNullOrEmpty(departmentHead.Email) && !string.IsNullOrEmpty(emailBody)) { string link = string.Format("{0}/SitePages/ShiftApproval.aspx?itemId={1}&Source={0}/_layouts/15/RBVH.Stada.Intranet.WebPages/ShiftManagement/ShiftManagementManager.aspx", web.Url, shiftManagementItem.ID); var department = DepartmentListSingleton.GetDepartmentByID(shiftManagementItem.Department.LookupId, web.Url); emailBody = string.Format(emailBody, departmentHead.FullName, string.IsNullOrEmpty(modifiedBy) ? shiftManagementItem.Requester.LookupValue : modifiedBy, shiftManagementItem.Month, shiftManagementItem.Year, shiftManagementItem.Department.LookupValue, department.VietnameseName); emailBody = emailBody.Replace("#link", link); _sendMailActivity.SendMail(web.Url, requestEmailItem.MailSubject, departmentHead.Email, true, false, emailBody); List <EmployeeInfo> toUsers = DelegationPermissionManager.GetListOfDelegatedEmployees(web.Url, departmentHead.ID, StringConstant.ShiftManagementList.ListUrl, shiftManagementItem.ID); link = string.Format("{0}/SitePages/ShiftApproval.aspx?subSection=ShiftManagement&itemId={1}&Source=/_layouts/15/RBVH.Stada.Intranet.WebPages/DelegationManagement/DelegationList.aspx&Source=Tab=DelegationsApprovalTab", web.Url, shiftManagementItem.ID); if (toUsers != null) { foreach (var toUser in toUsers) { try { if (!string.IsNullOrEmpty(toUser.Email)) { emailBody = HTTPUtility.HtmlDecode(requestEmailItem.MailBody); emailBody = string.Format(emailBody, toUser.FullName, string.IsNullOrEmpty(modifiedBy) ? shiftManagementItem.Requester.LookupValue : modifiedBy, shiftManagementItem.Month, shiftManagementItem.Year, shiftManagementItem.Department.LookupValue, department.VietnameseName); emailBody = emailBody.Replace("#link", link); _sendMailActivity.SendMail(web.Url, requestEmailItem.MailSubject, toUser.Email, true, false, emailBody); } } catch { } } } } } } } }
public bool SendDelegationNotOverTimeRequestEmail(string notOvertimeItemId, string toRole) { try { int idValue; if (int.TryParse(notOvertimeItemId, out idValue)) { var notOvertimeManagementItem = _notOvertimeMangementDAL.GetByID(idValue); var notOvertimeRequestMailItem = _emailTemplateDAL.GetByKey("LOAbsence_Request"); if (notOvertimeRequestMailItem != null && notOvertimeManagementItem != null) { var siteUrl = SPContext.Current.Site.Url; string link = string.Format(@"{0}/_layouts/15/RBVH.Stada.Intranet.WebPages/LeaveOfAbsenceManagement/LeaveOfAbsenceApprovalDelegation.aspx?itemId={1}&Source=/_layouts/15/RBVH.Stada.Intranet.WebPages/DelegationManagement/DelegationList.aspx&Source=Tab=DelegationsApprovalTab", siteUrl, notOvertimeManagementItem.ID); var dhUser = _employeeDAL.GetByADAccount(notOvertimeManagementItem.DH.ID); List <EmployeeInfo> toUsers = DelegationPermissionManager.GetListOfDelegatedEmployees(siteUrl, dhUser.ID, StringConstant.NotOvertimeList.ListUrl, notOvertimeManagementItem.ID); if (toUsers != null) { foreach (var toUser in toUsers) { try { if (!string.IsNullOrEmpty(toUser.Email)) { string emailBody = HTTPUtility.HtmlDecode(notOvertimeRequestMailItem.MailBody); emailBody = string.Format(emailBody, toUser.FullName, notOvertimeManagementItem.Requester.LookupValue, notOvertimeManagementItem.Date.ToString(StringConstant.DateFormatddMMyyyy2), notOvertimeManagementItem.Reason); emailBody = emailBody.Replace("#link", link); _sendMailActivity.SendMail(SPContext.Current.Web.Url, notOvertimeRequestMailItem.MailSubject, toUser.Email, true, false, emailBody); } } catch { } } } return(true); } } return(false); } catch (Exception ex) { ULSLogging.Log(new SPDiagnosticsCategory("STADA - Email Service - SendDelegationNotOverTimeRequestEmail fn", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, string.Format(CultureInfo.InvariantCulture, "{0}:{1}", ex.Message, ex.StackTrace)); return(false); } }
private void SendEmail(string webUrl, int changeshiftItemId, string emailKey, string approverFullName) { SendEmailActivity sendMailActity = new SendEmailActivity(); Thread thread = new Thread(delegate() { var _emailTemplateDAL = new EmailTemplateDAL(webUrl); var _employeeDAL = new EmployeeInfoDAL(webUrl); var _shiftTimeDAL = new ShiftTimeDAL(webUrl); var _sendMailActivity = new SendEmailActivity(); var changeShiftManagementItem = _changeShiftManagementDAL.GetByID(changeshiftItemId); var changeshiftRequestMailItem = _emailTemplateDAL.GetByKey(emailKey); if (changeshiftRequestMailItem != null && changeShiftManagementItem != null) { var employee = _employeeDAL.GetByID(changeShiftManagementItem.Requester.LookupId); if (employee != null && !string.IsNullOrEmpty(employee.Email)) { var shiftTimeList = _shiftTimeDAL.GetShiftTimes(); string emailBody = HTTPUtility.HtmlDecode(changeshiftRequestMailItem.MailBody); var fromShiftItem = shiftTimeList.Where(x => x.ID == changeShiftManagementItem.FromShift.LookupId).FirstOrDefault(); var toShiftItem = shiftTimeList.Where(x => x.ID == changeShiftManagementItem.ToShift.LookupId).FirstOrDefault(); //lookup email string link = $"{webUrl}/{StringConstant.WebPageLinks.ChangeShiftMember}"; if (employee.EmployeePosition.LookupId == (int)StringConstant.EmployeePosition.Administrator) { link = $"{webUrl}/{StringConstant.WebPageLinks.ChangeShiftAdmin}"; } if (employee.EmployeePosition.LookupId == (int)StringConstant.EmployeePosition.DepartmentHead) { link = $"{webUrl}/{StringConstant.WebPageLinks.ChangeShiftManager}"; } emailBody = string.Format(emailBody, employee.FullName, changeShiftManagementItem.Requester.LookupValue, changeShiftManagementItem.FromDate.ToString(StringConstant.DateFormatddMMyyyy2), changeShiftManagementItem.ToDate.ToString(StringConstant.DateFormatddMMyyyy2), changeShiftManagementItem.Reason, fromShiftItem.Code, toShiftItem.Code, changeShiftManagementItem.Comment, approverFullName); emailBody = emailBody.Replace("#link", link); _sendMailActivity.SendMail(webUrl, changeshiftRequestMailItem.MailSubject, employee.Email, true, false, emailBody); } } }); thread.IsBackground = true; thread.Start(); }
public void SendEmail(FreightManagement freightManagementItem, EmailTemplate emailTemplate, EmployeeInfo approver, EmployeeInfo toUser, string webUrl, bool isApprovalLink) { if (toUser == null || string.IsNullOrEmpty(toUser.Email) || emailTemplate == null || freightManagementItem == null || string.IsNullOrEmpty(webUrl)) { return; } var content = HTTPUtility.HtmlDecode(emailTemplate.MailBody); var bringerName = string.Empty; var bringerNameInVietnamese = string.Empty; if (freightManagementItem.CompanyVehicle) { bringerName = ResourceHelper.GetLocalizedString("FreightRequest_CompanyVehicle", StringConstant.ResourcesFileWebPages, 1033); bringerNameInVietnamese = ResourceHelper.GetLocalizedString("FreightRequest_CompanyVehicle", StringConstant.ResourcesFileWebPages, 1066); } else { bringerName = bringerNameInVietnamese = freightManagementItem.Bringer.LookupId > 0 ? freightManagementItem.Bringer.LookupValue : freightManagementItem.BringerName; } if (emailTemplate.MailKey.ToLower() == "freightmanagement_approve" || emailTemplate.MailKey.ToLower() == "freightmanagement_reject") { content = content.Replace("{0}", toUser.FullName); content = content.Replace("{1}", approver.FullName); content = content.Replace("{2}", freightManagementItem.Requester.LookupValue); content = content.Replace("{3}", bringerName); content = content.Replace("{4}", freightManagementItem.Receiver); content = content.Replace("{5}", bringerNameInVietnamese); } else { content = content.Replace("{0}", toUser.FullName); content = content.Replace("{1}", freightManagementItem.Requester.LookupValue); content = content.Replace("{2}", bringerName); content = content.Replace("{3}", freightManagementItem.Receiver); content = content.Replace("{4}", bringerNameInVietnamese); } var link = GetEmailLinkByUserPosition(webUrl, toUser.EmployeePosition.LookupId, freightManagementItem.ID, isApprovalLink); content = content.Replace("#link", link); SendEmailActivity sendMailActivity = new SendEmailActivity(); sendMailActivity.SendMail(webUrl, emailTemplate.MailSubject, toUser.Email, true, false, content); }
public void SendDelegationEmail(BusinessTripManagement businessTripManagement, EmailTemplate emailTemplate, List <EmployeeInfo> toUsers, string webUrl) { if (toUsers == null || toUsers.Count == 0 || emailTemplate == null || businessTripManagement == null || string.IsNullOrEmpty(webUrl)) { return; } string typeOfBusinessTripEN = ""; string typeOfBusinessTripVN = ""; if (businessTripManagement.Domestic) { typeOfBusinessTripEN = ResourceHelper.GetLocalizedString("BusinessTripManagement_BusinessTripTypeInternalTitle", StringConstant.ResourcesFileLists, 1033); typeOfBusinessTripVN = ResourceHelper.GetLocalizedString("BusinessTripManagement_BusinessTripTypeInternalTitle", StringConstant.ResourcesFileLists, 1066); } else { typeOfBusinessTripEN = ResourceHelper.GetLocalizedString("BusinessTripManagement_BusinessTripTypeExternalTitle", StringConstant.ResourcesFileLists, 1033); typeOfBusinessTripVN = ResourceHelper.GetLocalizedString("BusinessTripManagement_BusinessTripTypeExternalTitle", StringConstant.ResourcesFileLists, 1066); } var link = string.Format(@"{0}/SitePages/BusinessTripRequest.aspx?subSection=BusinessTripManagement&itemId={1}&Source=/_layouts/15/RBVH.Stada.Intranet.WebPages/DelegationManagement/DelegationList.aspx&Source=Tab=DelegationsApprovalTab", webUrl, businessTripManagement.ID); SendEmailActivity sendMailActivity = new SendEmailActivity(); foreach (var toUser in toUsers) { try { if (!string.IsNullOrEmpty(toUser.Email)) { var content = HTTPUtility.HtmlDecode(emailTemplate.MailBody); content = content.Replace("{0}", toUser.FullName); content = content.Replace("{1}", businessTripManagement.Requester.LookupValue); content = content.Replace("{2}", businessTripManagement.BusinessTripPurpose); content = content.Replace("{3}", typeOfBusinessTripEN); content = content.Replace("{4}", typeOfBusinessTripVN); content = content.Replace("#link", link); sendMailActivity.SendMail(webUrl, emailTemplate.MailSubject, toUser.Email, true, false, content); } } catch { } } }
public void SendDelegationEmail(FreightManagement freightManagementItem, EmailTemplate emailTemplate, List <EmployeeInfo> toUsers, string webUrl) { if (toUsers == null || toUsers.Count == 0 || emailTemplate == null || freightManagementItem == null || string.IsNullOrEmpty(webUrl)) { return; } SendEmailActivity sendMailActivity = new SendEmailActivity(); var link = string.Format(@"{0}/SitePages/FreightRequest.aspx?subSection=FreightManagement&itemId={1}&Source=/_layouts/15/RBVH.Stada.Intranet.WebPages/DelegationManagement/DelegationList.aspx&Source=Tab=DelegationsApprovalTab", webUrl, freightManagementItem.ID); foreach (var toUser in toUsers) { try { if (!string.IsNullOrEmpty(toUser.Email)) { var content = HTTPUtility.HtmlDecode(emailTemplate.MailBody); var bringerName = string.Empty; var bringerNameInVietnamese = string.Empty; if (freightManagementItem.CompanyVehicle) { bringerName = ResourceHelper.GetLocalizedString("FreightRequest_CompanyVehicle", StringConstant.ResourcesFileWebPages, 1033); bringerNameInVietnamese = ResourceHelper.GetLocalizedString("FreightRequest_CompanyVehicle", StringConstant.ResourcesFileWebPages, 1066); } else { bringerName = bringerNameInVietnamese = freightManagementItem.Bringer.LookupId > 0 ? freightManagementItem.Bringer.LookupValue : freightManagementItem.BringerName; } content = content.Replace("{0}", toUser.FullName); content = content.Replace("{1}", freightManagementItem.Requester.LookupValue); content = content.Replace("{2}", bringerName); content = content.Replace("{3}", freightManagementItem.Receiver); content = content.Replace("{4}", bringerNameInVietnamese); content = content.Replace("#link", link); sendMailActivity.SendMail(webUrl, emailTemplate.MailSubject, toUser.Email, true, false, content); } } catch { } } }
public void SendEmail(string webUrl, int notOvertimeItemId, string emailKey, string approverName) { Thread thread = new Thread(delegate () { var _emailTemplateDAL = new EmailTemplateDAL(webUrl); var _employeeDAL = new EmployeeInfoDAL(webUrl); var _shiftTimeDAL = new ShiftTimeDAL(webUrl); var _sendMailActivity = new SendEmailActivity(); var notOvertimeRequestMailItem = _emailTemplateDAL.GetByKey(emailKey); var notOvertimeManagementItem = _notOvertimeManagementDAL.GetByID(notOvertimeItemId); if (notOvertimeRequestMailItem != null && notOvertimeManagementItem != null) { var employee = _employeeDAL.GetByID(notOvertimeManagementItem.Requester.LookupId); if (employee != null && !string.IsNullOrEmpty(employee.Email)) { string emailBody = HTTPUtility.HtmlDecode(notOvertimeRequestMailItem.MailBody); //lookup email string link = $"{webUrl}/{StringConstant.WebPageLinks.LeaveOfAbsenceMember}"; if (employee.EmployeePosition.LookupId == (int)StringConstant.EmployeePosition.Administrator) { link = $"{webUrl}/{StringConstant.WebPageLinks.LeaveOfAbsenceAdmin}"; } if (employee.EmployeePosition.LookupId == (int)StringConstant.EmployeePosition.DepartmentHead) { link = $"{webUrl}/{StringConstant.WebPageLinks.LeaveOfAbsenceManager}"; } emailBody = string.Format(emailBody, employee.FullName, notOvertimeManagementItem.Requester.LookupValue, notOvertimeManagementItem.Date.ToString(StringConstant.DateFormatddMMyyyy2), notOvertimeManagementItem.Reason, notOvertimeManagementItem.Comment, approverName); emailBody = emailBody.Replace("#link", link); _sendMailActivity.SendMail(webUrl, notOvertimeRequestMailItem.MailSubject, employee.Email, true, false, emailBody); } } }); thread.IsBackground = true; thread.Start(); }
public bool SendDelegationChangeShiftRequestMail(string changeshiftItemId, string toRole) { try { int idValue; if (int.TryParse(changeshiftItemId, out idValue)) { var changeShiftManagementItem = _changeShiftManagementDAL.GetByID(idValue); var changeshiftRequestMailItem = _emailTemplateDAL.GetByKey("ChangeShift_Request"); if (changeshiftRequestMailItem != null && changeShiftManagementItem != null) { var siteUrl = SPContext.Current.Site.Url; var link = string.Format(@"{0}/_layouts/15/RBVH.Stada.Intranet.WebPages/ChangeShiftManagement/ChangeShiftApprovalDelegation.aspx?itemId={1}&Source=/_layouts/15/RBVH.Stada.Intranet.WebPages/DelegationManagement/DelegationList.aspx&Source=Tab=DelegationsApprovalTab", siteUrl, idValue); List <EmployeeInfo> toUsers = new List <EmployeeInfo>(); if (toRole.Equals("DH")) { var dhUser = _employeeDAL.GetByADAccount(changeShiftManagementItem.DepartmentHead.ID); toUsers = DelegationPermissionManager.GetListOfDelegatedEmployees(siteUrl, dhUser.ID, StringConstant.ChangeShiftList.ListUrl, idValue); } else if (toRole.Equals("BOD")) { var bodUser = _employeeDAL.GetByADAccount(changeShiftManagementItem.BOD.ID); toUsers = DelegationPermissionManager.GetListOfDelegatedEmployees(siteUrl, bodUser.ID, StringConstant.ChangeShiftList.ListUrl, idValue); } var shiftTimeList = _shiftTimeDAL.GetShiftTimes(); //lookup email var fromShiftItem = shiftTimeList.Where(x => x.ID == changeShiftManagementItem.FromShift.LookupId).FirstOrDefault(); var toShiftItem = shiftTimeList.Where(x => x.ID == changeShiftManagementItem.ToShift.LookupId).FirstOrDefault(); if (toUsers != null) { foreach (var toUser in toUsers) { try { if (!string.IsNullOrEmpty(toUser.Email)) { string emailBody = HTTPUtility.HtmlDecode(changeshiftRequestMailItem.MailBody); emailBody = string.Format(emailBody, toUser.FullName, changeShiftManagementItem.Requester.LookupValue, changeShiftManagementItem.FromDate.ToString(StringConstant.DateFormatddMMyyyy2), changeShiftManagementItem.ToDate.ToString(StringConstant.DateFormatddMMyyyy2), changeShiftManagementItem.Reason, fromShiftItem.Code, toShiftItem.Code); emailBody = emailBody.Replace("#link", link); _sendMailActivity.SendMail(siteUrl, changeshiftRequestMailItem.MailSubject, toUser.Email, true, false, emailBody); } } catch { } } } return(true); } } return(false); } catch (Exception ex) { ULSLogging.Log(new SPDiagnosticsCategory("STADA - Email Service - SendDelegationChangeShiftRequestMail fn", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, string.Format(CultureInfo.InvariantCulture, "{0}:{1}", ex.Message, ex.StackTrace)); return(false); } }
public void SendEmail(VehicleManagement model, EmailTemplate EmailTempalte, EmployeeInfo approver, EmployeeInfo toUser, VehicleTypeOfEmail typeOfEmail, string webUrl) { var sendToEmail = string.Empty; var receiverName = string.Empty; var link = string.Empty; var approveLinkFormat = "{0}/Lists/VehicleManagement/EditForm.aspx?subSection=TransportationManagement&ID={1}&Source={2}"; switch (toUser.EmployeePosition.LookupId) { case (int)StringConstant.EmployeePosition.Administrator: link = string.Format(LINK_MAIL, webUrl, "TransportationManagementAdmin"); break; case (int)StringConstant.EmployeePosition.DepartmentHead: link = string.Format(LINK_MAIL, webUrl, "TransportationManagementManager"); break; case (int)StringConstant.EmployeePosition.BOD: link = string.Format(LINK_MAIL, webUrl, "TransportationManagementBOD"); break; default: link = string.Format(LINK_MAIL, webUrl, "TransportationManagementMember"); break; } if (typeOfEmail == VehicleTypeOfEmail.Request) { link = string.Format(approveLinkFormat, webUrl, model.ID, HttpUtility.UrlEncode(link + "#tab2")); } else { link = string.Format(approveLinkFormat, webUrl, model.ID, HttpUtility.UrlEncode(link)); } sendToEmail = toUser.Email; receiverName = toUser.FullName; var content = HTTPUtility.HtmlDecode(EmailTempalte.MailBody); var department = DepartmentListSingleton.GetDepartmentByID(model.CommonDepartment.LookupId, this.SiteUrl); switch (typeOfEmail) { case VehicleTypeOfEmail.Request: content = content.Replace("{0}", receiverName); content = content.Replace("{1}", model.Requester.LookupValue); content = content.Replace("{2}", model.From.ToString("dd/MM/yyy hh:mm")); content = content.Replace("{3}", model.ToDate.ToString("dd/MM/yyy hh:mm")); content = content.Replace("{4}", department.Name); content = content.Replace("{5}", department.VietnameseName); break; case VehicleTypeOfEmail.Approve: case VehicleTypeOfEmail.Reject: content = content.Replace("{0}", model.Requester.LookupValue); content = content.Replace("{1}", approver.FullName); content = content.Replace("{2}", model.From.ToString("dd/MM/yyy hh:mm")); content = content.Replace("{3}", model.ToDate.ToString("dd/MM/yyy hh:mm")); break; default: break; } content = content.Replace("#link", link); SendEmailActivity sendMailActivity = new SendEmailActivity(); sendMailActivity.SendMail(webUrl, EmailTempalte.MailSubject, sendToEmail, true, false, content); }