Exemplo n.º 1
0
        public static EmailSendingResultType SendLegalReviewEmail(TempClosureLegalReview entity)
        {
            var project    = ProjectInfo.Get(entity.ProjectId, FlowCode.TempClosure_ClosurePackage);
            var storeBasic = StoreBasicInfo.GetStorInfo(project.USCode);
            var legal      = ProjectUsers.GetProjectUser(entity.ProjectId, ProjectUserRoleCode.Legal);
            var actor      = ProjectUsers.GetProjectUser(entity.ProjectId, ProjectUserRoleCode.AssetActor);

            using (EmailServiceClient emailClient = new EmailServiceClient())
            {
                EmailMessage email = new EmailMessage();
                //邮件模板中的数据
                Dictionary <string, string> bodyValues = new Dictionary <string, string>();
                //邮件内容中的键值对
                bodyValues.Add("ApproverName", legal.UserNameENUS);
                bodyValues.Add("ApplicantName", ClientCookie.UserNameENUS);//--提交人
                bodyValues.Add("StoreCode", storeBasic.StoreCode);
                bodyValues.Add("StoreName", storeBasic.NameENUS + @" \ " + storeBasic.NameZHCN);
                bodyValues.Add("Actor", actor.UserNameENUS);                       ////--呈递人
                bodyValues.Add("WorkflowName", Constants.TempClosure_LegalReview); ////--流程名称
                bodyValues.Add("ProjectName", Constants.TempClosure);              //项目名称
                var viewPage = string.Format("{0}/TempClosure/Main#/ClosurePackage/View/param?projectId={1}",
                                             HttpContext.Current.Request.Url.AbsolutePath, entity.ProjectId);
                bodyValues.Add("FormUrl", viewPage);
                email.EmailBodyValues = bodyValues;
                List <string> emailAddresses = Employee.Search(e => e.Code == legal.UserAccount).Select(e => e.Mail).ToList();
                emailAddresses.Add("*****@*****.**");
                emailAddresses.Add("*****@*****.**");
                emailAddresses.Add("*****@*****.**");
                email.To = string.Join(";", emailAddresses);
                //return emailClient.SendNotificationEmail(email);
                return(new EmailSendingResultType());
            }
        }
Exemplo n.º 2
0
        public IHttpActionResult Authority(string usCode)
        {
            bool enableView = false;
            bool enableEdit = false;

            var adminUsers = Employee.GetEmployeesByRole(RoleCode.System_Admin);

            if (adminUsers.Any(i => i.Code == ClientCookie.UserCode))
            {
                enableView = true;
                enableEdit = true;
            }
            else
            {
                var storeInfo = StoreBasicInfo.GetStorInfo(usCode);
                using (var amdb = new McdAMEntities())
                {
                    var org = amdb.Organization.FirstOrDefault(i => i.Code == storeInfo.RegionCode && i.Type == 102);
                    if (org.DL.HasValue && org.DL.Value)
                    {
                        enableView = true;
                        var repUsers = Employee.GetStoreAssetRepByStoreCode(usCode);
                        if (repUsers.Any(i => i.Code == ClientCookie.UserCode))
                        {
                            enableEdit = true;
                        }
                    }
                }
            }
            return(Ok(new
            {
                EnableView = enableView,
                EnableEdit = enableEdit
            }));
        }
Exemplo n.º 3
0
 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!"));
     }
 }
Exemplo n.º 4
0
        public IHttpActionResult CheckStoreFlow(string code, string flowCode)
        {
            var store = StoreBasicInfo.GetStorInfo(code);

            return(Ok(new
            {
                Store = store,
                StoreValid = ProjectInfo.CheckIfExistStore(code, flowCode),
                //StoreValid = true,
            }));
        }
Exemplo n.º 5
0
        /// <summary>
        /// 更新店面状态
        /// </summary>
        /// <param name="info"></param>
        private void UpdateStore(ScheduleLog info)
        {
            var storeInfo = StoreBasicInfo.GetStorInfo(info.USCode);

            if (storeInfo == null)
            {
                return;
            }

            try
            {
                if (info.ProjectId.ToLower().Contains("closure"))
                {
                    storeInfo.StoreStatus = "suoya301003";
                    storeInfo.statusName  = "Closed";
                    storeInfo.CloseDate   = info.ExecuteDate;
                    storeInfo.Update();
                }
                else if (info.ProjectId.ToLower().Contains("tpcls"))
                {
                    storeInfo.StoreStatus = "suoya301005";
                    storeInfo.statusName  = "TempClosed";
                    //storeInfo.CloseDate = info.UpdateDate;
                    storeInfo.Update();
                }
                else if (info.ProjectId.ToLower().Contains("reimage"))
                {
                    storeInfo.StoreStatus = "suoya301001";
                    storeInfo.statusName  = "Reimaging";
                    storeInfo.ReImageDate = info.ExecuteDate;
                    storeInfo.Update();
                }
                else if (info.ProjectId.ToLower().Contains("renewal"))
                {
                    storeInfo.StoreStatus = "suoya301002";
                    storeInfo.statusName  = "Renewal";
                    storeInfo.Update();
                }
                info.IsExecuted = true;
                Log.WriteLog(storeInfo.NameZHCN + "(" + info.USCode + ")状态更新成功");
            }
            catch (Exception ex)
            {
                Log.WriteErrorMessage(ex);
                Log.WriteLog(storeInfo.NameZHCN + "(" + info.USCode + ")状态更新失败");
            }
        }
Exemplo n.º 6
0
        public static List <EmailSendingResultType> SendPackageApprovalEmail(RenewalInfo info, RenewalPackage entity, ApproveUsers approvers)
        {
            var project       = ProjectInfo.Get(entity.ProjectId, FlowCode.Renewal_Package);
            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.MCCLAssetDtr
                };
                if (approvers.RegionalMgr != null)
                {
                    approveEmps.Add(approvers.RegionalMgr);
                }
                if (approvers.CDO != null)
                {
                    approveEmps.Add(approvers.CDO);
                }
                if (approvers.ManagingDirector != null)
                {
                    approveEmps.Add(approvers.ManagingDirector);
                }
                //邮件模板中的数据
                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}/Renewal/Main#/Package/View/param?projectId={1}",
                                             HttpContext.Current.Request.Url.Authority, entity.ProjectId);
                bodyValues.Add("FormUrl", viewPage);
                Dictionary <string, string> templateFileds = entity.GetPrintTemplateFields();
                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.Renewal, 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);
        }
Exemplo n.º 7
0
        public IHttpActionResult Upload(string projectId, string refTableName, Guid?requirementId = null)
        {
            using (TransactionScope tranScope = new TransactionScope())
            {
                var refTableId = Attachment.GetRefTableId(refTableName, projectId);
                if (refTableId == Guid.Empty.ToString())
                {
                    var newId = Guid.NewGuid();
                    refTableId = newId.ToString();
                    switch (refTableName)
                    {
                    case "MajorLeaseChangePackage":
                    {
                        var entity = new MajorLeaseChangePackage();
                        entity.ProjectId         = projectId;
                        entity.Id                = newId;
                        entity.CreateTime        = DateTime.Now;
                        entity.CreateUserAccount = ClientCookie.UserCode;
                        entity.IsHistory         = false;
                        entity.Add();
                    }
                    break;

                    case "ReimageSummary":
                    {
                        var entity = new ReimageSummary();
                        entity.ProjectId         = projectId;
                        entity.Id                = newId;
                        entity.CreateTime        = DateTime.Now;
                        entity.CreateUserAccount = ClientCookie.UserCode;
                        entity.IsHistory         = false;
                        entity.Add();
                    }
                    break;

                    case "ReimageConsInfo":
                    {
                        var entity = new ReimageConsInfo();
                        entity.ProjectId         = projectId;
                        entity.Id                = newId;
                        entity.CreateTime        = DateTime.Now;
                        entity.CreateUserAccount = ClientCookie.UserCode;
                        entity.IsHistory         = false;
                        entity.Add();
                    }
                    break;

                    case "ReimagePackage":
                    {
                        var entity = new ReimagePackage();
                        entity.ProjectId         = projectId;
                        entity.Id                = newId;
                        entity.CreateTime        = DateTime.Now;
                        entity.CreateUserAccount = ClientCookie.UserCode;
                        entity.IsHistory         = false;
                        entity.Add();
                    }
                    break;

                    case "RebuildLegalReview":
                    {
                        var entity = new RebuildLegalReview();
                        entity.ProjectId         = projectId;
                        entity.Id                = newId;
                        entity.CreateTime        = DateTime.Now;
                        entity.CreateUserAccount = ClientCookie.UserCode;
                        entity.IsHistory         = false;
                        entity.Add();
                    }
                    break;

                    case "ClosureLegalReview":
                    {
                        var entity = new ClosureLegalReview();
                        entity.ProjectId         = projectId;
                        entity.Id                = newId;
                        entity.CreateTime        = DateTime.Now;
                        entity.CreateUserAccount = ClientCookie.UserCode;
                        entity.IsHistory         = false;
                        entity.Add();
                    }
                    break;

                    case "ClosureExecutiveSummary":
                    {
                        var entity = new ClosureExecutiveSummary();
                        entity.ProjectId      = projectId;
                        entity.Id             = newId;
                        entity.CreateTime     = DateTime.Now;
                        entity.CreatorAccount = ClientCookie.UserCode;
                        entity.IsHistory      = false;
                        entity.Add();
                    }
                    break;

                    case "ClosurePackage":
                    {
                        var entity = new ClosurePackage();
                        entity.ProjectId         = projectId;
                        entity.Id                = newId;
                        entity.CreateTime        = DateTime.Now;
                        entity.CreateUserAccount = ClientCookie.UserCode;
                        entity.IsHistory         = false;
                        entity.Add();
                    }
                    break;
                    }
                }
                var userRole = ProjectUsers.Get(ClientCookie.UserCode, projectId);
                var files    = HttpContext.Current.Request.Files;
                if (requirementId.HasValue)
                {
                    var attReq      = AttachmentRequirement.Get(requirementId.Value);
                    var projectInfo = ProjectInfo.Get(projectId, attReq.FlowCode);
                    var store       = StoreBasicInfo.GetStorInfo(projectInfo.USCode);
                    var attachNode  = NodeInfo.FirstOrDefault(n => n.FlowCode == attReq.FlowCode && n.Code == attReq.NodeCode);
                    if (attachNode != null)
                    {
                        ProjectInfo.FinishNode(projectId, attReq.FlowCode, attReq.NodeCode);
                    }
                    var    file          = files[0];
                    string fileName      = Path.GetFileName(file.FileName);
                    string fileExtension = Path.GetExtension(file.FileName);
                    var    current       = System.Web.HttpContext.Current;
                    string internalName  = Guid.NewGuid() + fileExtension;
                    string absolutePath  = current.Server.MapPath("~/") + "UploadFiles/" + internalName;

                    file.SaveAs(absolutePath);

                    Attachment att = Attachment.Get(refTableId, requirementId.Value);

                    if (att == null)
                    {
                        att = new Attachment();
                        att.InternalName    = internalName;
                        att.RefTableName    = refTableName;
                        att.RefTableID      = refTableId;
                        att.RelativePath    = "//";
                        att.Name            = fileName;
                        att.Extension       = fileExtension;
                        att.Length          = file.ContentLength;
                        att.CreateTime      = DateTime.Now;
                        att.CreatorNameZHCN = ClientCookie.UserNameZHCN;
                        att.CreatorNameENUS = ClientCookie.UserNameENUS;
                        att.CreatorID       = ClientCookie.UserCode;
                        att.ID            = Guid.NewGuid();
                        att.RequirementId = requirementId;
                        att.TypeCode      = "";
                        Attachment.Add(att);
                    }
                    else
                    {
                        att.InternalName    = internalName;
                        att.RefTableName    = refTableName;
                        att.RefTableID      = refTableId;
                        att.RelativePath    = "//";
                        att.Name            = fileName;
                        att.Extension       = fileExtension;
                        att.Length          = file.ContentLength;
                        att.CreateTime      = DateTime.Now;
                        att.CreatorNameZHCN = ClientCookie.UserNameZHCN;
                        att.CreatorNameENUS = ClientCookie.UserNameENUS;
                        att.CreatorID       = ClientCookie.UserCode;
                        Attachment.Update(att);
                    }
                    //TempClosure上传SignAgreement
                    //if (requirementId.Value.Equals(new Guid("1E9B17AF-357A-4DC9-8A60-17766663FB75")))
                    //{
                    //    var url = "/TempClosure/Main#/ClosureMemo?projectId=" + projectId;
                    //    var actor = ProjectUsers.FirstOrDefault(pu => pu.ProjectId == projectId && pu.RoleCode == ProjectUserRoleCode.AssetActor);
                    //    var title = string.Concat(projectId, " ", store.NameZHCN, " ", store.NameENUS);
                    //    TaskWork.Finish(t => t.ReceiverAccount == ClientCookie.UserCode && t.RefID == projectId && t.Status == TaskWorkStatus.UnFinish && t.TypeCode == FlowCode.TempClosure_ClosurePackage);
                    //    //TaskWork.SendTask(projectId, title, projectInfo.USCode, url, actor, FlowCode.TempClosure, FlowCode.TempClosure_ClosureMemo, "Start");
                    //}
                }
                else
                {
                    List <Attachment> attachments = new List <Attachment>();
                    string            typeCode    = "";
                    if (refTableName == "RebuildLegalReview")
                    {
                        typeCode = "Contract";
                    }
                    for (int i = 0; i < files.Count; i++)
                    {
                        var    file          = files[i];
                        string fileName      = Path.GetFileName(file.FileName);
                        string fileExtension = Path.GetExtension(file.FileName);
                        var    current       = System.Web.HttpContext.Current;
                        string internalName  = Guid.NewGuid() + fileExtension;
                        string absolutePath  = current.Server.MapPath("~/") + "UploadFiles/" + internalName;

                        file.SaveAs(absolutePath);

                        Attachment att = new Attachment();
                        att.InternalName    = internalName;
                        att.RefTableName    = refTableName;
                        att.RefTableID      = refTableId;
                        att.RelativePath    = "//";
                        att.Name            = fileName;
                        att.Extension       = fileExtension;
                        att.Length          = file.ContentLength;
                        att.CreateTime      = DateTime.Now;
                        att.CreatorNameZHCN = ClientCookie.UserNameZHCN;
                        att.CreatorNameENUS = ClientCookie.UserNameENUS;
                        att.CreatorID       = ClientCookie.UserCode;
                        att.ID            = Guid.NewGuid();
                        att.RequirementId = requirementId;
                        att.TypeCode      = typeCode;
                        attachments.Add(att);
                    }
                    Attachment.Add(attachments.ToArray());
                }
                tranScope.Complete();
                return(Ok());
            }
        }
Exemplo n.º 8
0
        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());
        }
Exemplo n.º 10
0
        /// <summary>
        /// 提交Closure
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public IHttpActionResult PostClosure(ClosureInfo entity)
        {
            using (TransactionScope tranScope = new TransactionScope())
            {
                //    bll.BeginTransAction();
                //    try
                //    {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                if (entity.ClosureReasonCode != "Others")
                {
                    entity.ClosureReasonRemark = string.Empty;
                }

                if (entity.Id == new Guid())
                {
                    entity.Id = Guid.NewGuid();

                    entity.CreateDate = DateTime.Now;

                    entity.ProjectId = ProjectInfo.CreateMainProject(FlowCode.Closure, entity.USCode, NodeCode.Start, entity.CreateUserAccount);



                    ClosureInfo.Add(entity);
                }
                else
                {
                    ClosureInfo.Update(entity);
                }
                //    bll.Commit();
                //}
                //catch (Exception ex)
                //{
                //    bll.Rollback();
                //    return BadRequest(ex.Message);
                //}
                var usersList  = new List <ProjectUsers>();
                var assetActor = GetClosureUsers(ProjectUserRoleCode.AssetActor, ProjectUserRoleCode.AssetActor, ProjectUserRoleCode.AssetActor, entity.AssetActorAccount, entity.AssetActorNameENUS, entity.AssetActorNameZHCN, entity.ProjectId);
                usersList.Add(assetActor);
                var assetRep = GetClosureUsers(ProjectUserRoleCode.AssetRep, ProjectUserRoleCode.AssetRep, ProjectUserRoleCode.AssetRep, entity.AssetRepAccount, entity.AssetRepNameENUS, entity.AssetRepNameZHCN, entity.ProjectId);
                usersList.Add(assetRep);
                var finance = GetClosureUsers(ProjectUserRoleCode.Finance, ProjectUserRoleCode.Finance, ProjectUserRoleCode.Finance, entity.FinanceAccount, entity.FinanceNameENUS, entity.FinanceNameZHCN, entity.ProjectId);
                usersList.Add(finance);
                var Legal = GetClosureUsers(ProjectUserRoleCode.Legal, ProjectUserRoleCode.Legal, ProjectUserRoleCode.Legal, entity.LegalAccount, entity.LegalNameENUS, entity.LegalNameZHCN, entity.ProjectId);
                usersList.Add(Legal);
                var PM = GetClosureUsers(ProjectUserRoleCode.PM, ProjectUserRoleCode.PM, ProjectUserRoleCode.PM, entity.PMAccount, entity.PMNameZHCN, entity.PMNameENUS, entity.ProjectId);
                usersList.Add(PM);
                var assertMgr = GetClosureUsers(ProjectUserRoleCode.AssetManager, ProjectUserRoleCode.AssetManager, ProjectUserRoleCode.AssetManager, entity.AssetManagerAccount, entity.AssetManagerNameENUS,
                                                entity.AssetManagerNameZHCN, entity.ProjectId);
                usersList.Add(assertMgr);

                var cm = GetClosureUsers(ProjectUserRoleCode.CM, ProjectUserRoleCode.CM, ProjectUserRoleCode.CM, entity.CMAccount, entity.CMNameENUS,
                                         entity.CMNameZHCN, entity.ProjectId);
                usersList.Add(cm);
                if (entity.NecessaryNoticeUserList != null && entity.NecessaryNoticeUserList.Count > 0)
                {
                    usersList.AddRange(entity.NecessaryNoticeUserList.Select(
                                           user => GetClosureUsers(ProjectUserRoleCode.View, ProjectUserRoleCode.View, ProjectUserRoleCode.View, user.Code, user.NameENUS, user.NameZHCN,
                                                                   entity.ProjectId)));
                }
                if (entity.NoticeUserList != null && entity.NoticeUserList.Count > 0)
                {
                    usersList.AddRange(entity.NoticeUserList.Select(
                                           user => GetClosureUsers(ProjectUserRoleCode.View, ProjectUserRoleCode.View, ProjectUserRoleCode.View, user.Code, user.NameENUS, user.NameZHCN,
                                                                   entity.ProjectId)));
                }

                ProjectUsers.Add(usersList.ToArray());
                SendRemind(entity);
                SendWorkTaskAndEmail(entity);

                //初始化项目信息

                ProjectInfo.CreateSubProject(FlowCode.Closure_WOCheckList, entity.ProjectId, entity.USCode, NodeCode.Start, PM.UserAccount);
                ProjectInfo.CreateSubProject(FlowCode.Closure_LegalReview, entity.ProjectId, entity.USCode, NodeCode.Start, assetActor.UserAccount);
                ProjectInfo.CreateSubProject(FlowCode.Closure_ClosureTool, entity.ProjectId, entity.USCode, NodeCode.Start, finance.UserAccount);

                var store = StoreBasicInfo.GetStorInfo(entity.USCode);

                var closureTool = new ClosureTool();
                closureTool.Id                   = Guid.NewGuid();
                closureTool.ProjectId            = entity.ProjectId;
                closureTool.IsHistory            = false;
                closureTool.IsOptionOffered      = entity.IsRelocation();
                closureTool.PipelineName         = store.PipelineNameENUS;
                closureTool.RelocationPipelineID = store.PipelineID;
                closureTool.Add();

                var woCheckList = new ClosureWOCheckList
                {
                    Id                = Guid.NewGuid(),
                    ProjectId         = entity.ProjectId,
                    CreateTime        = DateTime.Now,
                    CreateUserAccount = ClientCookie.UserCode,
                    CreateUserName    = ClientCookie.UserNameENUS,
                    IsHistory         = false
                };
                woCheckList.Add();

                var legalReview = new ClosureLegalReview
                {
                    Id                = Guid.NewGuid(),
                    ProjectId         = entity.ProjectId,
                    CreateTime        = DateTime.Now,
                    CreateUserAccount = ClientCookie.UserCode,
                    CreateUserName    = ClientCookie.UserNameENUS,
                    IsHistory         = false
                };
                legalReview.Add();

                var executiveSummary = new ClosureExecutiveSummary
                {
                    Id             = Guid.NewGuid(),
                    ProjectId      = entity.ProjectId,
                    CreateTime     = DateTime.Now,
                    CreatorAccount = ClientCookie.UserCode,
                    CreatorName    = ClientCookie.UserNameENUS,
                    IsHistory      = false
                };
                executiveSummary.Add();

                //var package = new ClosurePackage
                //{
                //    Id = Guid.NewGuid(),
                //    ProjectId = entity.ProjectId,
                //    CreateTime = DateTime.Now,
                //    CreateUserAccount = ClientCookie.UserCode,
                //    IsHistory = false
                //};
                //package.Add();

                var projectContractInfo = ProjectContractInfo.GetContractWithHistory(entity.ProjectId).Current;
                projectContractInfo.Add();

                ProjectInfo.CreateSubProject(FlowCode.Closure_ExecutiveSummary, entity.ProjectId, entity.USCode, NodeCode.Start, assetActor.UserAccount);

                ProjectInfo.CreateSubProject(FlowCode.Closure_ClosurePackage, entity.ProjectId, entity.USCode, NodeCode.Start, assetActor.UserAccount);

                ProjectInfo.CreateSubProject(FlowCode.Closure_ConsInvtChecking, entity.ProjectId, entity.USCode, NodeCode.Start, entity.PMAccount);


                ProjectInfo.CreateSubProject(FlowCode.Closure_ContractInfo, entity.ProjectId, entity.USCode,
                                             NodeCode.Start, entity.CreateUserAccount);
                ProjectInfo.CreateSubProject(FlowCode.Closure_Memo, entity.ProjectId, entity.USCode,
                                             NodeCode.Start, entity.CreateUserAccount);
                ProjectNode.GenerateOnCreate(FlowCode.Closure, entity.ProjectId);
                try
                {
                    //bllActionLog.Add(new ActionLog
                    //{
                    //    Id = Guid.NewGuid(),
                    //    ProjectId = entity.ProjectId,
                    //    Action = ActionType.Submit,
                    //    CreateTime = DateTime.Now,
                    //    Operator = entity.CreateUserAccount,
                    //    OperatorENUS = entity.CreateUserNameENUS,
                    //    OperatorZHCN = entity.CreateUserNameZHCN,
                    //    Remark = "",
                    //    OperatorTitle = "创建流程"
                    //});
                    tranScope.Complete();
                    //bll.GetDb().SaveChanges();
                }
                catch (DbEntityValidationException dbEx)
                {
                    tranScope.Dispose();
                }


                return(Ok(entity));
            }
        }