/// <summary> /// Send email vendor evaluation report. /// </summary> /// <param name="id">The evaluation identity.</param> private void SendEmailToApproval(int id) { var data = _unitOfWork.GetRepository <Data.Pocos.Evaluation>().GetById(id); var vendor = _unitOfWork.GetRepository <Data.Pocos.Vendor>().GetCache(x => x.VendorNo == data.VendorNo).FirstOrDefault(); var company = _unitOfWork.GetRepository <Hrcompany>().GetCache(x => x.SapcomCode == data.ComCode).FirstOrDefault(); var purchaseOrg = _unitOfWork.GetRepository <PurchaseOrg>().GetCache(x => x.PurchaseOrg1 == data.PurchasingOrg).FirstOrDefault(); var valueHelp = _unitOfWork.GetRepository <ValueHelp>().GetCache(x => x.ValueType == ConstantValue.ValueTypeWeightingKey && x.ValueKey == data.WeightingKey).FirstOrDefault(); var emailTemplate = _unitOfWork.GetRepository <EmailTemplate>().GetCache(x => x.EmailType == ConstantValue.EmailTypeEvaluationApproveNotice).FirstOrDefault(); var evaluationTemplate = _unitOfWork.GetRepository <EvaluationTemplate>().GetCache(x => x.Id == data.Id).FirstOrDefault(); string[] periodInfo = this.GetPeriodName(data.PeriodItemId.Value); var approvalInfo = this.GetApprovalInfo(id); string[] grade = this.GetGrade(evaluationTemplate.GradeId.Value, data.TotalScore.Value); string subject = emailTemplate.Subject; string content = emailTemplate.Content; subject = subject.Replace("%PERIOD%", periodInfo[0]); subject = subject.Replace("%PERIODITEM%", periodInfo[1]); content = content.Replace("%TO%", string.Format($"คุณ{ConstantValue.EmpTemplate}", approvalInfo?.FirstnameTh, approvalInfo?.LastnameTh)); content = content.Replace("%DOCNO%", data.DocNo); content = content.Replace("%VENDOR%", vendor?.VendorName); content = content.Replace("%WEIGTHNIGKEY%", valueHelp?.ValueText); content = content.Replace("%COMNAME%", company?.LongText); content = content.Replace("%PURCHASEORG%", purchaseOrg?.PurchaseName); content = content.Replace("%TOTALSCORE%", data.TotalScore.Value.ToString()); content = content.Replace("%GRADE%", grade[0]); content = content.Replace("%URL%", _config.TaskUrl + "Inbox"); _emailService.SendEmail(new EmailModel { Body = content, Receiver = approvalInfo.Email, Subject = subject, }); _emailTask.Save(new Email.Bll.Models.EmailTaskViewModel { DocNo = data.DocNo, Content = $"{content}", Subject = subject, TaskCode = ConstantValue.EmailEvaluationApproveNotice, Receivers = new List <Email.Bll.Models.EmailTaskReceiveViewModel> { new Email.Bll.Models.EmailTaskReceiveViewModel { Email = vendor.Email, FullName = vendor.VendorName, ReceiverType = ConstantValue.ReceiverTypeTo } }, TaskBy = _token.AdUser, TaskDate = DateTime.Now, Status = ConstantValue.EmailTaskStatusSending }); }
/// <summary> /// Save evaluation reject task to email task. /// </summary> /// <param name="model">The evaluation reject task collection.</param> private void SaveEvaRejectToEmailTask(Dictionary <string, List <SummaryEvaRejectModel> > model) { var emailTemplate = _unitOfWork.GetRepository <EmailTemplate>().GetCache(x => x.EmailType == ConstantValue.EmailTypeSummaryTaskReject).FirstOrDefault(); foreach (var item in model) { string rows = this.GenerateContentData(item.Value); var emailTask = this.InitialSummaryEvaReject(item.Key, rows, emailTemplate); //Save email task status waiting. _emailTask.Save(emailTask); } }
/// <summary> /// Send email vendor evaluation report. /// </summary> /// <param name="id">The evaluation identity.</param> /// <param name="file">The directory report file.</param> private void SendEmailToVendor(int id, string file) { var data = _unitOfWork.GetRepository <Data.Pocos.Evaluation>().GetById(id); var vendor = _unitOfWork.GetRepository <Data.Pocos.Vendor>().GetCache(x => x.VendorNo == data.VendorNo).FirstOrDefault(); var emailTemplate = _unitOfWork.GetRepository <EmailTemplate>().GetCache(x => x.EmailType == ConstantValue.EmailTypeVendorEvaluationReportNotice).FirstOrDefault(); var company = _unitOfWork.GetRepository <Hrcompany>().GetCache(x => x.SapcomCode == data.ComCode).FirstOrDefault(); string[] periodInfo = this.GetPeriodName(data.PeriodItemId.Value); string subject = emailTemplate.Subject; string content = emailTemplate.Content; subject = subject.Replace("%PERIOD%", periodInfo[0]); subject = subject.Replace("%PERIODITEM%", periodInfo[1]); content = content.Replace("%VENDOR%", vendor?.VendorName); content = content.Replace("%COMNAME%", company?.LongText); _emailService.SendEmail(new EmailModel { AttachmentPathFile = file, Body = content, Receiver = vendor.Email, Subject = subject, }); _emailTask.Save(new Email.Bll.Models.EmailTaskViewModel { DocNo = data.DocNo, Content = $"{content} Attachment file name : {Path.GetFileName(file)}", Subject = subject, TaskCode = ConstantValue.EmailVendorEvaluationReportNoticeCode, Receivers = new List <Email.Bll.Models.EmailTaskReceiveViewModel> { new Email.Bll.Models.EmailTaskReceiveViewModel { Email = vendor.Email, FullName = vendor.VendorName, ReceiverType = ConstantValue.ReceiverTypeTo } }, TaskBy = _token.AdUser, TaskDate = DateTime.Now, Status = ConstantValue.EmailTaskStatusSending }); }
/// <summary> /// Send email to user vendor filter information. /// </summary> /// <param name="model">The vendor filter collection.</param> private void SendEmail(VendorFilterCollectionRequestViewModel model) { var vendorList = _unitOfWork.GetRepository <Data.Pocos.Vendor>().GetCache(); var assignList = model.VendorFilterItems.Select(x => x.AssignTo).Distinct(); var empList = _unitOfWork.GetRepository <Hremployee>().GetCache(x => assignList.Contains(x.Aduser)); var periodItem = _unitOfWork.GetRepository <PeriodItem>().GetCache(x => x.Id == model.PeriodItemId).FirstOrDefault(); var companyInfo = _unitOfWork.GetRepository <Hrcompany>().GetCache(x => x.SapcomCode == model.CompanyCode).FirstOrDefault(); string weightingKey = _unitOfWork.GetRepository <ValueHelp>().GetCache(x => x.ValueType == ConstantValue.ValueTypeWeightingKey && x.ValueKey == model.WeightingKey).FirstOrDefault()?.ValueText; var purchaseInfo = _unitOfWork.GetRepository <PurchaseOrg>().GetCache(x => x.PurchaseOrg1 == model.PurchasingOrg).FirstOrDefault(); var emailTemplate = _unitOfWork.GetRepository <EmailTemplate>().GetCache(x => x.EmailType == ConstantValue.EmailTypeVendorFilterNotice).FirstOrDefault(); foreach (var item in assignList) { var vendorFilters = model.VendorFilterItems.Where(x => x.AssignTo == item); var empInfo = empList.FirstOrDefault(x => x.Aduser == item); string rows = this.GenerateContentData(vendorList, vendorFilters); string subject = emailTemplate.Subject; string content = emailTemplate.Content; subject = subject.Replace("%PERIODNAME%", periodItem.PeriodName); content = content.Replace("%EMPNAME%", string.Format(ConstantValue.EmpTemplate, empInfo?.FirstnameTh, empInfo?.LastnameTh)); content = content.Replace("%PERIODITEMNAME%", periodItem.PeriodName); content = content.Replace("%COMNAME%", companyInfo?.LongText); content = content.Replace("%PURCHASENAME%", purchaseInfo?.PurchaseName); content = content.Replace("%WEIGHTINGKEY%", weightingKey); content = content.Replace("%TABLE%", this.GenerateTable(rows)); string status = ConstantValue.EmailTaskStatusSending; try { _emailService.SendEmail(new EmailModel { Body = content, Receiver = empInfo.Email, Subject = subject, }); } catch (Exception ex) { status = ConstantValue.EmailTaskStatusError; _logger.LogError(ex, "Vendor filter is sending email error :"); } _emailTask.Save(new Email.Bll.Models.EmailTaskViewModel { DocNo = "-", Content = $"{content}", Subject = subject, TaskCode = ConstantValue.EmailVendorFilterNoticeCode, Receivers = new List <Email.Bll.Models.EmailTaskReceiveViewModel> { new Email.Bll.Models.EmailTaskReceiveViewModel { Email = empInfo.Email, FullName = string.Format(ConstantValue.EmpTemplate, empInfo?.FirstnameTh, empInfo?.LastnameTh), ReceiverType = ConstantValue.ReceiverTypeTo } }, TaskBy = _token.AdUser, TaskDate = DateTime.Now, Status = status }); } }