public IHttpActionResult Send(PostClosureMemoModel model) { var actor = ProjectUsers.GetProjectUser(model.Entity.ProjectId, ProjectUserRoleCode.AssetActor); using (TransactionScope tranScope = new TransactionScope()) { Save(model.Entity); ClosureTool closureTool = ClosureTool.FirstOrDefault(ct => ct.ProjectId == model.Entity.ProjectId); string compensationAwards = ""; string compensation = "暂无数据"; if (closureTool != null && closureTool.Compensation.HasValue) { compensationAwards = closureTool.Compensation.Value > 0 ? "Yes" : "No"; compensation = closureTool.Compensation.Value.ToString("N"); } Dictionary <string, string> pdfData = new Dictionary <string, string>(); pdfData.Add("WorkflowName", "Closure"); pdfData.Add("ProjectID", model.Entity.ProjectId); pdfData.Add("RegionNameENUS", model.Entity.RegionNameENUS); pdfData.Add("RegionNameZHCN", model.Entity.RegionNameZHCN); pdfData.Add("MarketNameENUS", model.Entity.MarketNameENUS); pdfData.Add("MarketNameZHCN", model.Entity.MarketNameZHCN); pdfData.Add("ProvinceNameENUS", model.Entity.ProvinceNameENUS); pdfData.Add("ProvinceNameZHCN", model.Entity.ProvinceNameZHCN); pdfData.Add("CityNameENUS", model.Entity.CityNameENUS); pdfData.Add("CityNameZHCN", model.Entity.CityNameZHCN); pdfData.Add("StoreNameENUS", model.Entity.StoreNameENUS); pdfData.Add("StoreNameZHCN", model.Entity.StoreNameZHCN); pdfData.Add("StoreAddressENUS", model.Entity.StoreAddressENUS); pdfData.Add("StoreAddressZHCN", model.Entity.StoreAddressZHCN); pdfData.Add("USCode", model.Entity.USCode); pdfData.Add("OpenDate", model.Entity.OpenDate.Value.ToString("yyyy-MM-dd")); pdfData.Add("ClosureDate", model.Entity.ClosureDate.Value.ToString("yyyy-MM-dd")); pdfData.Add("ClosureNature", model.Entity.ClosureNature.ToString()); if (model.Entity.BecauseOfReimaging.HasValue) { pdfData.Add("BecauseOfReimaging", model.Entity.BecauseOfReimaging.Value ? "Yes" : "No"); } else { pdfData.Add("BecauseOfReimaging", ""); } if (model.Entity.BecauseOfRemodel.HasValue) { pdfData.Add("BecauseOfRemodel", model.Entity.BecauseOfRemodel.Value ? "Yes" : "No"); } else { pdfData.Add("BecauseOfRemodel", ""); } if (model.Entity.BecauseOfDespute.HasValue) { pdfData.Add("BecauseOfDespute", model.Entity.BecauseOfDespute.Value ? "Yes" : "No"); } else { pdfData.Add("BecauseOfDespute", ""); } if (model.Entity.BecauseOfRedevelopment.HasValue) { pdfData.Add("BecauseOfRedevelopment", model.Entity.BecauseOfRedevelopment.Value ? "Yes" : "No"); } else { pdfData.Add("BecauseOfRedevelopment", ""); } if (model.Entity.BecauseOfPlanedClosure.HasValue) { pdfData.Add("BecauseOfPlanedClosure", model.Entity.BecauseOfPlanedClosure.Value ? "Yes" : "No"); } else { pdfData.Add("BecauseOfPlanedClosure", ""); } if (model.Entity.BecauseOfRebuild.HasValue) { pdfData.Add("BecauseOfRebuild", model.Entity.BecauseOfRebuild.Value ? "Yes" : "No"); } else { pdfData.Add("BecauseOfRebuild", ""); } pdfData.Add("BecauseOfOthers", model.Entity.BecauseOfOthers); if (model.Entity.PermanentCloseOpportunity.HasValue) { pdfData.Add("PermanentCloseOpportunity", model.Entity.PermanentCloseOpportunity.Value ? "Yes" : "No"); } else { pdfData.Add("PermanentCloseOpportunity", ""); } if (model.Entity.HasRelocationPlan.HasValue) { pdfData.Add("HasRelocationPlan", model.Entity.HasRelocationPlan.Value ? "Yes" : "No"); } else { pdfData.Add("HasRelocationPlan", ""); } pdfData.Add("PipelineName", model.Entity.PipelineName); pdfData.Add("CompensationAwarded", compensationAwards); pdfData.Add("Compensation", compensation); string pdfPath = HtmlConversionUtility.HtmlConvertToPDF(HtmlTempalteType.ClosureMemo, pdfData, null); EmailSendingResultType result; //邮件模板中的数据 Dictionary <string, string> bodyValues = new Dictionary <string, string>(); //邮件内容中的键值对 //bodyValues.Add("ApplicantName", ClientCookie.UserNameENUS);//--提交人 bodyValues.Add("StoreCode", model.Entity.USCode); bodyValues.Add("StoreName", model.Entity.StoreNameENUS); bodyValues.Add("Actor", actor.RoleNameENUS); ////--呈递人 bodyValues.Add("WorkflowName", Constants.Closure_Memo); ////--流程名称 bodyValues.Add("ProjectName", Constants.Closure); //项目名称 var webRootUrl = ConfigurationManager.AppSettings["webHost"]; var viewPage = string.Format("{0}Closure/Main#/ClosureMemo/ClosureMemoView?projectId={1}", webRootUrl, model.Entity.ProjectId); bodyValues.Add("FormUrl", viewPage); //调用邮件服务发送邮件 using (EmailServiceClient client = new EmailServiceClient()) { EmailMessage message = new EmailMessage(); StringBuilder sbTo = new StringBuilder(); Dictionary <string, string> attachments = new Dictionary <string, string>(); foreach (Employee emp in model.Receivers) { if (sbTo.Length > 0) { sbTo.Append(";"); } if (!string.IsNullOrEmpty(emp.Mail)) { sbTo.Append(emp.Mail); } } if (sbTo.Length > 0) { sbTo.Append(";"); } message.EmailBodyValues = bodyValues; attachments.Add(pdfPath, model.Entity.USCode + " " + FlowCode.Closure_Memo + ".pdf"); message.AttachmentsDict = attachments; message.To = sbTo.ToString(); message.TemplateCode = EmailTemplateCode.GBMemoNotification; result = client.SendNotificationEmail(message); } if (!result.Successful) { return(BadRequest(result.ErrorMessage + " " + pdfPath)); } //store关闭不在这里设置,需要判断project状态和closuredata //var store = StoreBasicInfo.GetStorInfo(model.Entity.USCode); //store.StoreStatus = "suoya301003"; //store.statusName = "Closed"; //store.Update(); if (model.Entity.ClosureNature == ClosureNatureType.Permanent) { //选项为永久关闭并且发送成功后关闭任务 McdAMEntities _db = new McdAMEntities(); var task = _db.TaskWork.FirstOrDefault(e => e.ReceiverAccount == ClientCookie.UserCode && e.Status == 0 && e.SourceCode == FlowCode.Closure && e.TypeCode == FlowCode.Closure_Memo && e.RefID == model.Entity.ProjectId); if (task != null) { task.Status = TaskWorkStatus.K2ProcessApproved; task.FinishTime = DateTime.Now; task.Url = SiteInfo.GetProjectViewPageUrl(FlowCode.Closure_Memo, task.RefID); //var enableExecutiveSummary = handler.EnableExecutiveSummary(entity.ProjectId.Value); _db.TaskWork.Attach(task); _db.Entry(task).State = EntityState.Modified; _db.SaveChanges(); ProjectInfo.FinishNode(model.Entity.ProjectId, FlowCode.Closure_Memo, NodeCode.Closure_ClosureMemo_Input); ProjectInfo.FinishNode(model.Entity.ProjectId, FlowCode.Closure_Memo, NodeCode.Closure_ClosureMemo_SendMemo, ProjectStatus.Finished); #region Memo完成后,设定计划任务 var closureConsInvtChecking = new ClosureConsInvtChecking(); closureConsInvtChecking.GenerateConsInvtCheckingTask(model.Entity.ProjectId); if (model.Entity.ClosureDate.HasValue) { ScheduleLog.UpdateStoreStatusSchedule(model.Entity.USCode, model.Entity.ProjectId, model.Entity.ClosureDate.Value, ClientCookie.UserCode); } #endregion } ProjectInfo.CompleteMainIfEnable(model.Entity.ProjectId); } tranScope.Complete(); return(Ok()); } }
public IHttpActionResult Send(PostMemo <TempClosureMemo> postData) { var actor = ProjectUsers.FirstOrDefault(pu => pu.ProjectId == postData.Entity.ProjectId && pu.RoleCode == ProjectUserRoleCode.AssetActor); Dictionary <string, string> pdfData = new Dictionary <string, string>(); if (postData.Entity.ProjectId.ToLower().IndexOf("rebuild") != -1) { pdfData.Add("WorkflowName", "Rebuild"); pdfData.Add("ClosureNature", "Temporary"); } else if (postData.Entity.ProjectId.ToLower().IndexOf("majorlease") != -1) { pdfData.Add("WorkflowName", "MajorLease"); pdfData.Add("ClosureNature", "Temporary"); } else if (postData.Entity.ProjectId.ToLower().IndexOf("reimage") != -1) { pdfData.Add("WorkflowName", "Reimage"); pdfData.Add("ClosureNature", "Temporary"); } else if (postData.Entity.ProjectId.ToLower().IndexOf("renewal") != -1) { pdfData.Add("WorkflowName", "Renewal"); pdfData.Add("ClosureNature", "Temporary"); } else { pdfData.Add("WorkflowName", "TempClosure"); pdfData.Add("ClosureNature", postData.Entity.ClosureNature.ToString()); } pdfData.Add("ProjectID", postData.Entity.ProjectId); pdfData.Add("RegionNameENUS", postData.Entity.RegionNameENUS); pdfData.Add("RegionNameZHCN", postData.Entity.RegionNameZHCN); pdfData.Add("MarketNameENUS", postData.Entity.MarketNameENUS); pdfData.Add("MarketNameZHCN", postData.Entity.MarketNameZHCN); pdfData.Add("ProvinceNameENUS", postData.Entity.ProvinceNameENUS); pdfData.Add("ProvinceNameZHCN", postData.Entity.ProvinceNameZHCN); pdfData.Add("CityNameENUS", postData.Entity.CityNameENUS); pdfData.Add("CityNameZHCN", postData.Entity.CityNameZHCN); pdfData.Add("StoreNameENUS", postData.Entity.StoreNameENUS); pdfData.Add("StoreNameZHCN", postData.Entity.StoreNameZHCN); pdfData.Add("StoreAddressENUS", postData.Entity.StoreAddressENUS); pdfData.Add("StoreAddressZHCN", postData.Entity.StoreAddressZHCN); pdfData.Add("USCode", postData.Entity.USCode); pdfData.Add("OpenDate", postData.Entity.OpenDate.HasValue ? postData.Entity.OpenDate.Value.ToString("yyyy-MM-dd") : ""); pdfData.Add("ClosureDate", postData.Entity.ClosureDate.HasValue ? postData.Entity.ClosureDate.Value.ToString("yyyy-MM-dd") : ""); pdfData.Add("BecauseOfReimaging", postData.Entity.BecauseOfReimaging ? "Yes" : "No"); pdfData.Add("BecauseOfRemodel", postData.Entity.BecauseOfRemodel ? "Yes" : "No"); pdfData.Add("BecauseOfDespute", postData.Entity.BecauseOfDespute ? "Yes" : "No"); pdfData.Add("BecauseOfRedevelopment", postData.Entity.BecauseOfRedevelopment ? "Yes" : "No"); pdfData.Add("BecauseOfPlanedClosure", postData.Entity.BecauseOfPlanedClosure ? "Yes" : "No"); pdfData.Add("BecauseOfRebuild", postData.Entity.BecauseOfRebuild ? "Yes" : "No"); pdfData.Add("BecauseOfOthers", postData.Entity.BecauseOfOthers); pdfData.Add("PermanentCloseOpportunity", postData.Entity.PermanentCloseOpportunity ? "Yes" : "No"); pdfData.Add("HasRelocationPlan", postData.Entity.HasRelocationPlan ? "Yes" : "No"); pdfData.Add("PipelineName", postData.Entity.PipelineName); pdfData.Add("CompensationAwarded", postData.Entity.CompensationAwarded ? "Yes" : "No"); pdfData.Add("Compensation", postData.Entity.Compensation.HasValue ? postData.Entity.Compensation.Value.ToString("N") : ""); string pdfPath = HtmlConversionUtility.HtmlConvertToPDF(HtmlTempalteType.ClosureMemo, pdfData, null); EmailSendingResultType result; //邮件模板中的数据 Dictionary <string, string> bodyValues = new Dictionary <string, string>(); //邮件内容中的键值对 bodyValues.Add("ApplicantName", ClientCookie.UserNameENUS);//--提交人 bodyValues.Add("StoreCode", postData.Entity.USCode); bodyValues.Add("StoreName", postData.Entity.StoreNameENUS); bodyValues.Add("Actor", actor.UserNameENUS);////--呈递人 string viewPage = string.Format("{0}/TempClosure/Main#/ClosureMemo/Process/View?projectId={1}", ConfigurationManager.AppSettings["webHost"], postData.Entity.ProjectId); if (postData.Entity.ProjectId.ToLower().IndexOf("rebuild") != -1) { bodyValues.Add("WorkflowName", Constants.TempClosure_Memo); ////--流程名称 bodyValues.Add("ProjectName", Constants.Rebuild); //项目名称 viewPage = string.Format("{0}/Rebuild/Main#/TempClosureMemo/View?projectId={1}", ConfigurationManager.AppSettings["webHost"], postData.Entity.ProjectId); } else if (postData.Entity.ProjectId.ToLower().IndexOf("majorlease") != -1) { bodyValues.Add("WorkflowName", Constants.Closure_Memo); ////--流程名称 bodyValues.Add("ProjectName", Constants.MajorLease); //项目名称 viewPage = string.Format("{0}/MajorLease/Main#/ClosureMemo/View?projectId={1}", ConfigurationManager.AppSettings["webHost"], postData.Entity.ProjectId); } else if (postData.Entity.ProjectId.ToLower().IndexOf("reimage") != -1) { bodyValues.Add("WorkflowName", Constants.TempClosure_Memo); ////--流程名称 bodyValues.Add("ProjectName", Constants.Reimage); //项目名称 viewPage = string.Format("{0}/Reimage/Main#/TempClosureMemo/View?projectId={1}", ConfigurationManager.AppSettings["webHost"], postData.Entity.ProjectId); } else if (postData.Entity.ProjectId.ToLower().IndexOf("renewal") != -1) { bodyValues.Add("WorkflowName", Constants.Closure_Memo); ////--流程名称 bodyValues.Add("ProjectName", Constants.Renewal); //项目名称 viewPage = string.Format("{0}/Renewal/Main#/ClosureMemo/View?projectId={1}", ConfigurationManager.AppSettings["webHost"], postData.Entity.ProjectId); } else if (postData.Entity.ProjectId.ToLower().IndexOf("closure") != -1) { bodyValues.Add("WorkflowName", Constants.Closure_Memo); ////--流程名称 bodyValues.Add("ProjectName", Constants.Closure); //项目名称 } else { bodyValues.Add("WorkflowName", Constants.Closure_Memo); ////--流程名称 bodyValues.Add("ProjectName", Constants.TempClosure); //项目名称 } bodyValues.Add("FormUrl", viewPage); if (postData.Entity.ProjectId.ToLower().Contains("tpcls")) { //调用邮件服务发送邮件 using (EmailServiceClient client = new EmailServiceClient()) { EmailMessage message = new EmailMessage(); StringBuilder sbTo = new StringBuilder(); StringBuilder sbCC = new StringBuilder(); Dictionary <string, string> attachments = new Dictionary <string, string>(); //主送人 var actorEmployee = Employee.GetEmployeeByCode(actor.UserAccount); if (actorEmployee != null) { sbTo.Append(actorEmployee.Mail + ";"); } var cooList = Employee.GetStoreEmployeesByRole(postData.Entity.USCode, RoleCode.Coordinator); foreach (var coo in cooList) { sbTo.Append(coo.Mail + ";"); } var mamList = Employee.GetStoreEmployeesByRole(postData.Entity.USCode, RoleCode.Market_Asset_Mgr); foreach (var mam in mamList) { sbTo.Append(mam.Mail + ";"); } var ramList = Employee.GetStoreEmployeesByRole(postData.Entity.USCode, RoleCode.Regional_Asset_Mgr); foreach (var ram in ramList) { sbTo.Append(ram.Mail + ";"); } var mcamList = Employee.GetStoreEmployeesByRole(postData.Entity.USCode, RoleCode.MCCL_Asset_Mgr); foreach (var mcam in mcamList) { sbTo.Append(mcam.Mail + ";"); } //抄送人 if (postData.Receivers != null) { foreach (Employee emp in postData.Receivers) { if (sbCC.Length > 0) { sbCC.Append(";"); } if (!string.IsNullOrEmpty(emp.Mail)) { sbCC.Append(emp.Mail); } } } if (sbCC.Length > 0) { sbCC.Append(";"); } message.EmailBodyValues = bodyValues; attachments.Add(pdfPath, postData.Entity.USCode + " " + Constants.TempClosure_Memo + ".pdf"); message.AttachmentsDict = attachments; message.To = sbTo.ToString(); message.CC = sbCC.ToString(); message.TemplateCode = EmailTemplateCode.GBMemoNotification; result = client.SendNotificationEmail(message); } } else { using (EmailServiceClient client = new EmailServiceClient()) { EmailMessage message = new EmailMessage(); StringBuilder sbTo = new StringBuilder(); StringBuilder sbCC = new StringBuilder(); Dictionary <string, string> attachments = new Dictionary <string, string>(); if (postData.Receivers != null) { foreach (Employee emp in postData.Receivers) { if (sbCC.Length > 0) { sbTo.Append(";"); } if (!string.IsNullOrEmpty(emp.Mail)) { sbTo.Append(emp.Mail); } } } if (sbCC.Length > 0) { sbCC.Append(";"); } message.EmailBodyValues = bodyValues; string strTitle = FlowCode.TempClosure_ClosureMemo; if (postData.Entity.ProjectId.ToLower().IndexOf("rebuild") >= 0) { strTitle = FlowCode.Rebuild_TempClosureMemo; } else if (postData.Entity.ProjectId.ToLower().IndexOf("reimage") >= 0) { strTitle = FlowCode.Reimage_TempClosureMemo; } else if (postData.Entity.ProjectId.ToLower().IndexOf("majorlease") >= 0) { strTitle = "MajorLease_ClosureMemo"; } attachments.Add(pdfPath, postData.Entity.USCode + " " + strTitle + ".pdf"); message.AttachmentsDict = attachments; message.To = sbTo.ToString(); message.TemplateCode = EmailTemplateCode.GBMemoNotification; result = client.SendNotificationEmail(message); } } if (!result.Successful) { return(BadRequest(result.ErrorMessage + " " + pdfPath)); } using (TransactionScope tranScope = new TransactionScope()) { postData.Entity.Save(); ProjectInfo projectInfo = null; if (postData.Entity.ProjectId.ToLower().IndexOf("rebuild") >= 0) { projectInfo = ProjectInfo.Get(postData.Entity.ProjectId, FlowCode.Rebuild_TempClosureMemo); } else if (postData.Entity.ProjectId.ToLower().IndexOf("reimage") >= 0) { projectInfo = ProjectInfo.Get(postData.Entity.ProjectId, FlowCode.Reimage_TempClosureMemo); } else if (postData.Entity.ProjectId.ToLower().IndexOf("majorlease") >= 0 || postData.Entity.ProjectId.ToLower().IndexOf("renewal") >= 0) { postData.Entity.Submit(); } else { projectInfo = ProjectInfo.Get(postData.Entity.ProjectId, FlowCode.TempClosure_ClosureMemo); var tempClosure = TempClosureInfo.Get(postData.Entity.ProjectId); if (postData.Entity.ClosureDate != null) { tempClosure.ActualTempClosureDate = postData.Entity.ClosureDate.Value; } tempClosure.Update(); } if (projectInfo != null && projectInfo.Status == ProjectStatus.UnFinish) { postData.Entity.Submit(); if (postData.Entity.ProjectId.ToLower().Contains("tpcls")) { if (postData.Entity.ClosureDate.HasValue) { ScheduleLog.UpdateStoreStatusSchedule(postData.Entity.USCode, postData.Entity.ProjectId, postData.Entity.ClosureDate.Value, ClientCookie.UserCode); } } } tranScope.Complete(); } return(Ok()); }