/// <summary> /// SendEmail /// </summary> /// <param name="toEmployeeIds"></param> /// <returns></returns> private bool SendEmail(List <int> toEmployeeIds) { var res = false; string subjectEmail = ConfigurationDAL.GetValue(this.SiteUrl, DelegationEmailTemplateSubjectKey); string delegationBodyEmailTemplate = ConfigurationDAL.GetValue(this.SiteUrl, DelegationEmailTemplateKey); DelegationEmailTemplate delegationEmailTemplate = InitDelegationEmailTemplateObject(); string body = BuildBodyEmail(delegationEmailTemplate, delegationBodyEmailTemplate); res = SendEmail(toEmployeeIds, subjectEmail, body); return(res); }
/// <summary> /// BuildBodyEmail /// </summary> /// <param name="DelegationEmailTemplateObject"></param> /// <param name="delegationBodyEmailTemplate"></param> /// <returns></returns> private string BuildBodyEmail(DelegationEmailTemplate DelegationEmailTemplateObject, string delegationBodyEmailTemplate) { var body = string.Empty; try { BasicEvaluationContext basicEvaluationContext = new BasicEvaluationContext(); basicEvaluationContext.Objects["DelegationEmailTemplate"] = DelegationEmailTemplateObject; body = basicEvaluationContext.Eval <string>(delegationBodyEmailTemplate); } catch (Exception ex) { ULSLogging.LogError(ex); } return(body); }
/// <summary> /// InitDelegationEmailTemplateObject /// </summary> /// <returns></returns> private DelegationEmailTemplate InitDelegationEmailTemplateObject() { DelegationEmailTemplate delegationEmailTemplateObject = new DelegationEmailTemplate(); StringBuilder receiversBuilder = new StringBuilder(); foreach (ListItem listItem in this.ddlToEmployee.Items) { if (listItem.Selected) { receiversBuilder.AppendFormat("{0}, ", listItem.Text); } } delegationEmailTemplateObject.Receivers = receiversBuilder.ToString(); delegationEmailTemplateObject.FromEmployee = ddlFromEmployee.SelectedItem.Text; delegationEmailTemplateObject.FromDate = this.dtFromDate.SelectedDate.Date.ToString(DateFormatddMMyyyy2); delegationEmailTemplateObject.ToDate = this.dtToDate.SelectedDate.Date.ToString(DateFormatddMMyyyy2); delegationEmailTemplateObject.AccessLink = string.Format("{0}/_layouts/15/RBVH.Stada.Intranet.WebPages/DelegationManagement/DelegationList.aspx?{1}={2}", this.SiteUrl, DelegationListUserControl.TabParamName, DelegationListUserControl.DelegationsApprovalTabId); return(delegationEmailTemplateObject); }