public IHttpActionResult EditMultipleProjects(PostEditProjects postEditProjects) { if (postEditProjects.EditProjects.Count > 0) { using (TransactionScope tranScope = new TransactionScope()) { var projectId = postEditProjects.ProjectId; var parentCode = postEditProjects.EditProjects[0].ParentCode; var projects = ProjectInfo.Search(pi => pi.ProjectId == projectId).ToList(); var usCode = projects[0].USCode; var store = StoreBasicInfo.GetStorInfo(usCode); var minExecuteSequence = postEditProjects.EditProjects.Min(p => p.ExecuteSequence); var maxExecuteSequance = postEditProjects.EditProjects.Max(p => p.ExecuteSequence); foreach (TopNavigator nav in postEditProjects.EditProjects) { var workflow = BaseWFEntity.GetWorkflowEntity(postEditProjects.ProjectId, nav.Code); workflow.Edit(); } string[] cancelWorkflowCodes = FlowInfo.Search(f => f.ParentCode == parentCode && f.ExecuteSequence <= maxExecuteSequance + 1).Select(f => f.Code).ToArray(); TaskWork.Cancel(t => cancelWorkflowCodes.Contains(t.TypeCode) && t.RefID == postEditProjects.ProjectId && t.Status != TaskWorkStatus.Finished); postEditProjects.EditProjects.Where(n => n.ExecuteSequence == minExecuteSequence).ToList().ForEach(n => { var project = projects.FirstOrDefault(pi => pi.FlowCode == n.Code); var originator = Employee.GetSimpleEmployeeByCode(project.CreateUserAccount); var source = FlowInfo.Get(n.ParentCode); var taskType = FlowInfo.Get(n.Code); TaskWork task = new TaskWork(); task.Id = Guid.NewGuid(); task.SourceCode = source.Code; task.SourceNameENUS = source.NameENUS; task.SourceNameZHCN = source.NameZHCN; task.Status = TaskWorkStatus.UnFinish; task.StatusNameZHCN = "任务"; task.StatusNameENUS = "任务"; task.Title = TaskWork.BuildTitle(postEditProjects.ProjectId, store.NameZHCN, store.NameENUS); task.RefID = postEditProjects.ProjectId; task.StoreCode = usCode; task.ReceiverAccount = originator.Code; task.ReceiverNameENUS = originator.NameENUS; task.ReceiverNameZHCN = originator.NameZHCN; task.TypeCode = taskType.Code; task.TypeNameENUS = taskType.NameENUS; task.TypeNameZHCN = taskType.NameZHCN; task.Url = TaskWork.BuildUrl(n.Code, projectId, ""); task.CreateTime = DateTime.Now; task.CreateUserAccount = ClientCookie.UserCode; task.Sequence = 0; task.ActivityName = "Start"; task.Add(); }); tranScope.Complete(); } return(Ok()); } else { return(BadRequest("you must select projects to be edited!")); } }
public static List <EmailSendingResultType> SendPackageApprovalEmail(TempClosureInfo tempClosureInfo, TempClosurePackage entity, ApproveUsers approvers) { var project = ProjectInfo.Get(entity.ProjectId, FlowCode.TempClosure_ClosurePackage); var storeBasic = StoreBasicInfo.GetStorInfo(project.USCode); var storeContract = StoreContractInfo.Search(c => c.StoreCode == project.USCode).OrderByDescending(c => c.CreatedTime).FirstOrDefault(); var assetMgr = ProjectUsers.FirstOrDefault(pu => pu.ProjectId == entity.ProjectId && pu.RoleCode == ProjectUserRoleCode.AssetManager); var assetActor = ProjectUsers.FirstOrDefault(pu => pu.ProjectId == entity.ProjectId && pu.RoleCode == ProjectUserRoleCode.AssetActor); var assetRep = ProjectUsers.FirstOrDefault(pu => pu.ProjectId == entity.ProjectId && pu.RoleCode == ProjectUserRoleCode.AssetRep); var results = new List <EmailSendingResultType>(); using (EmailServiceClient emailClient = new EmailServiceClient()) { List <SimpleEmployee> approveEmps = new List <SimpleEmployee> { approvers.MarketMgr, approvers.GM, approvers.MDD, approvers.FC, approvers.VPGM //approvers.MCCLAssetMgr, //approvers.MCCLAssetDtr }; if (approvers.RegionalMgr != null) { approveEmps.Add(approvers.RegionalMgr); } //邮件模板中的数据 Dictionary <string, string> bodyValues = new Dictionary <string, string>(); //邮件内容中的键值对 bodyValues.Add("ApplicantName", ClientCookie.UserNameENUS);//--提交人 bodyValues.Add("StoreCode", storeBasic.StoreCode); bodyValues.Add("StoreName", storeBasic.NameENUS + @" \ " + storeBasic.NameZHCN); bodyValues.Add("Actor", assetActor.UserNameENUS); ////--呈递人 //bodyValues.Add("WorkflowName", Constants.TempClosure_Package);////--流程名称 bodyValues.Add("ProjectName", Constants.TempClosure); //项目名称 var viewPage = string.Format("{0}/TempClosure/Main#/ClosurePackage/View/param?projectId={1}", HttpContext.Current.Request.Url.Authority, entity.ProjectId); bodyValues.Add("FormUrl", viewPage); Dictionary <string, string> templateFileds = new Dictionary <string, string>(); var flowInfo = FlowInfo.Get(FlowCode.TempClosure); templateFileds.Add("WorkflowName", flowInfo.NameENUS); templateFileds.Add("ProjectID", entity.ProjectId); templateFileds.Add("USCode", storeBasic.StoreCode); templateFileds.Add("City", storeBasic.CityZHCN); templateFileds.Add("Region", storeBasic.Region); templateFileds.Add("StoreNameEN", storeBasic.NameENUS); templateFileds.Add("Market", storeBasic.Market); templateFileds.Add("StoreNameCN", storeBasic.NameZHCN); templateFileds.Add("StoreAge", Math.Floor((DateTime.Now - storeBasic.OpenDate).TotalDays / 365D).ToString()); templateFileds.Add("OpenDate", storeBasic.OpenDate.ToString("yyyy-MM-dd")); var storeInfo = StoreBasicInfo.GetStore(project.USCode); if (!string.IsNullOrEmpty(storeInfo.StoreContractInfo.EndYear)) { templateFileds.Add("CurrentLeaseENDYear", (int.Parse(storeInfo.StoreContractInfo.EndYear) - storeInfo.CurrentYear).ToString()); } else { templateFileds.Add("CurrentLeaseENDYear", ""); } if (assetMgr != null) { templateFileds.Add("AssetsManager", assetMgr.UserNameENUS); } templateFileds.Add("AssetsActor", assetActor.UserNameENUS); templateFileds.Add("AssetsRep", assetRep.UserNameENUS); templateFileds.Add("ClosureDate", tempClosureInfo.ActualTempClosureDate.ToString("yyyy-MM-dd")); templateFileds.Add("LeaseExpireDate", tempClosureInfo.LeaseExpireDate.HasValue ? tempClosureInfo.LeaseExpireDate.Value.ToString("yyyy-MM-dd") : ""); templateFileds.Add("ReOpenDate", tempClosureInfo.ActualReopenDate.ToString("yyyy-MM-dd")); templateFileds.Add("RentFreeTerm", string.IsNullOrEmpty(entity.RentReliefClause) ? "否" : "是"); templateFileds.Add("RentFreeStartDate", entity.RentReliefStartDate.HasValue ? entity.RentReliefStartDate.Value.ToString("yyyy-MM-dd") : ""); templateFileds.Add("RentFreeEndDate", entity.RentReliefEndDate.HasValue ? entity.RentReliefEndDate.Value.ToString("yyyy-MM-dd") : ""); templateFileds.Add("FreeRentTerm", entity.RentReliefClause); var approveRecords = ProjectComment.GetList("TempClosurePackage", entity.Id, ProjectCommentStatus.Submit).Select(pc => new SubmissionApprovalRecord { OperatorID = pc.UserAccount, OperatorName = pc.UserNameENUS, OperatorTitle = pc.TitleNameENUS, OperationDate = pc.CreateTime.HasValue ? pc.CreateTime.Value : DateTime.Now, ActionName = pc.ActivityName, Comments = pc.Content }).ToList(); string imgPath = HtmlConversionUtility.HtmlConvertToPDF(HtmlTempalteType.TempClosure, templateFileds, approveRecords); approveEmps.ForEach(e => { EmailMessage email = new EmailMessage(); List <string> emailAddresses = new List <string> { e.Mail, "*****@*****.**", "*****@*****.**", "*****@*****.**" }; if (bodyValues.ContainsKey("ApproverName")) { bodyValues["ApproverName"] = e.NameENUS; } else { bodyValues.Add("ApproverName", e.NameENUS);//--提交人 } email.EmailBodyValues = bodyValues; email.To = string.Join(";", emailAddresses); email.Attachments = imgPath; //var result = emailClient.SendEmail(email); results.Add(new EmailSendingResultType()); }); approvers.NoticeUsers.ForEach(e => { EmailMessage email = new EmailMessage(); List <string> emailAddresses = new List <string> { e.Mail, "*****@*****.**", "*****@*****.**", "*****@*****.**" }; if (bodyValues.ContainsKey("ApproverName"))//--提交人 { bodyValues["ApproverName"] = e.NameENUS; } else { bodyValues.Add("ApproverName", e.NameENUS); } email.EmailBodyValues = bodyValues; email.To = string.Join(";", emailAddresses); email.Attachments = imgPath; //var result = emailClient.SendEmail(email); results.Add(new EmailSendingResultType()); }); } return(results); }
public IHttpActionResult SendMsg(NotificationMsg msg) { using (var scope = new TransactionScope()) { Notification.Send(msg); if (msg.IsSendEmail) { //邮件模板中的数据 Dictionary <string, string> bodyValues = new Dictionary <string, string>(); if (string.IsNullOrEmpty(msg.UsCode)) { var projectInfo = ProjectInfo.FirstOrDefault(e => e.ProjectId == msg.ProjectId); if (projectInfo != null) { msg.UsCode = projectInfo.USCode; } } var stor = StoreBasicInfo.GetStorInfo(msg.UsCode); bodyValues.Add("ApplicantName", ClientCookie.UserNameENUS);//--提交人 bodyValues.Add("StoreCode", stor.StoreCode); bodyValues.Add("StoreName", stor.NameENUS); bodyValues.Add("Comments", msg.Message); var actor = ProjectUsers.GetProjectUser(msg.ProjectId, ProjectUserRoleCode.AssetActor); bodyValues.Add("Actor", actor.RoleNameENUS);////--呈递人 var flow = FlowInfo.Get(msg.FlowCode); if (flow != null) { bodyValues.Add("WorkflowName", flow.NameENUS); ////--流程名称 } if (msg.ProjectId.ToLower().IndexOf("rebuild") >= 0) { bodyValues.Add("ProjectName", Constants.Rebuild); //项目名称 } else if (msg.ProjectId.ToLower().IndexOf("reimage") >= 0) { bodyValues.Add("ProjectName", Constants.Reimage); //项目名称 } else if (msg.ProjectId.ToLower().IndexOf("closure") >= 0) { bodyValues.Add("ProjectName", Constants.Closure); //项目名称 } else if (msg.ProjectId.ToLower().IndexOf("renewal") >= 0) { bodyValues.Add("ProjectName", "Renewal"); //项目名称 } else if (msg.ProjectId.ToLower().IndexOf("majorlease") >= 0) { bodyValues.Add("ProjectName", "MajorLease"); //项目名称 } else { bodyValues.Add("ProjectName", Constants.TempClosure);//项目名称 } string viewPage = ""; if (!string.IsNullOrEmpty(msg.FlowCode)) { var tmp = msg.FlowCode.Split('_'); if (tmp[0] == "Rebuild" && tmp[1] == "Package") { tmp[1] = "RebuildPackage"; } viewPage = string.Format("{0}/{1}/Main#/{2}/Process/View?projectId={3}", ConfigurationManager.AppSettings["webHost"], tmp[0], tmp[1], msg.ProjectId); } bodyValues.Add("FormUrl", viewPage); var Receivers = Employee.GetSimpleEmployeeByCodes(msg.ReceiverCodeList.ToArray()); //调用邮件服务发送邮件 EmailSendingResultType result; using (EmailServiceClient client = new EmailServiceClient()) { EmailMessage message = new EmailMessage(); StringBuilder sbTo = new StringBuilder(); Dictionary <string, string> attachments = new Dictionary <string, string>(); foreach (var emp in 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; message.To = sbTo.ToString(); message.TemplateCode = EmailTemplateCode.Notification; result = client.SendNotificationEmail(message); } if (!result.Successful) { return(BadRequest(result.ErrorMessage)); } } scope.Complete(); } return(Ok()); }