Exemplo n.º 1
0
        public async Task <IActionResult> Approval([FromBody] ApprovalDto obj)
        {
            string token = Request.Headers["Authorization"];

            var userID = Extensions.GetDecodeTokenByProperty(token, "nameid").ToInt();

            var model = await _actionPlanService.Approve(obj.id, userID, obj.KPILevelCode, obj.CategoryID);

            await _hubContext.Clients.All.SendAsync("ReceiveMessage", "user", "message");


            if (model.Item1.Count > 0 && await _settingService.IsSendMail("APPROVAL"))
            {
                if (model.Item2 == true)
                {
                    Thread thread = new Thread(async() =>
                    {
                        string URL     = _configuaration.GetSection("AppSettings:URL").ToSafetyString();
                        var data       = model.Item1.DistinctBy(x => x);
                        string content = @"<p><b>*PLEASE DO NOT REPLY* this email was automatically sent from the KPI system.</b></p> 
                                        <p>The account <b>" + data.First()[0].ToTitleCase() + "</b> approved the action plan <b>'" + data.First()[3] + "'</b> </p>" +
                                         "<p>Link: <a href='" + _configuration["AppSettings:URL"] + model.Item3 + "'>Click Here</a></p>" +
                                         "<br/>" +

                                         @"<p><b>*請勿回信*這封信是KPI系統自動寄出.</b></p> 
                                        <p>帳號<b>" + data.First()[0].ToTitleCase() + "</b> 已經核准了行動方案 <b>'" + data.First()[3] + "'</b> </p>" +
                                         "<p>連結: <a href='" + _configuration["AppSettings:URL"] + model.Item3 + "'>點選這裡</a></p>"
                        ;
                        await _mailHelper.SendEmailRange(data.Select(x => x[1]).ToList(), "[KPI System-05] Approved (已核准)", content);
                    });
                    thread.Start();
                }
                else
                {
                    Thread thread = new Thread(async() =>
                    {
                        string URL     = _configuaration.GetSection("AppSettings:URL").ToSafetyString();
                        var data       = model.Item1.DistinctBy(x => x);
                        string content = @"<p><b>*PLEASE DO NOT REPLY* this email was automatically sent from the KPI system.</b></p> 
                                        <p>The account <b>" + data.First()[0].ToTitleCase() + "</b> not approve the action plan <b>'" + data.First()[3] + "'</b> </p>" +
                                         "<p>Link: <a href='" + _configuration["AppSettings:URL"] + model.Item3 + "'>Click Here</a></p>" +
                                         "<br/>" +

                                         @"<p><b>*請勿回信*這封信是KPI系統自動寄出.</b></p> 
                                        <p>帳號<b>" + data.First()[0].ToTitleCase() + "</b> 取消核准行動方案 <b>'" + data.First()[3] + "'</b> </p>" +
                                         "<p>連結: <a href='" + _configuration["AppSettings:URL"] + model.Item3 + "'>點選這裡</a></p>"
                        ;
                        await _mailHelper.SendEmailRange(data.Select(x => x[1]).ToList(), "[KPI System-05] Not Approved", content);
                    });
                    thread.Start();
                }
            }
            return(Ok(new { status = true, isSendmail = true }));
        }