예제 #1
0
        public int AddMessage(string updateType, LineItemGroup encumbrance, string comments, List <int> otherRecipients, List <int> ccIDs)
        {
            encumbrance = _context.GetDeepEncumbrance(encumbrance.GroupID);
            int        msgID            = 0;
            List <int> recipientIDs     = null; // list of IDs of email recipients
            decimal    encumbranceTotal = 0.0M;
            //string contractViewURL = _serverpath + "/Contracts/View/" + encumbrance.ContractID + "/enc_" + encumbrance.GroupID;
            string contractViewURL = _serverpath + "/LineItemGroups/Manage/" + encumbrance.GroupID;

            encumbranceTotal = GetEncumbranceTotal(encumbrance);
            Contract contract  = _context.Contracts.SingleOrDefault(c => c.ContractID == encumbrance.ContractID);
            User     submitter = _context.Users.SingleOrDefault(u => u.UserID == encumbrance.LastEditedUserID);
            Message  msg       = new Message
            {
                FromUserID  = encumbrance.LastEditedUserID,
                MessageDate = DateTime.Now
            };

            if (!updateType.Equals(ConstantStrings.NoChange))
            {
                switch (updateType)
                {
                case ConstantStrings.DraftToFinance:
                    msg.Subject = "Encumbrance Request# " + encumbrance.GroupID + " for contract " + contract.ContractNumber + " has been submitted for Finance Review";
                    msg.Body    = "<p>Please process the following encumbrance request: ID " + encumbrance.GroupID + " for contract " + contract.ContractNumber + " in the amount of " + Utils.FormatCurrency(encumbranceTotal) + ".</p>\n";
                    if (comments != null && comments.Length > 0)
                    {
                        msg.Body += "<p>Comments: " + comments + "</p>\n";
                    }
                    if (encumbrance.FileAttachments != null && encumbrance.FileAttachments.Count > 0)
                    {
                        msg.Body += "File Attachments:<br/><ul>";
                        foreach (FileAttachment fileAtt in encumbrance.FileAttachments)
                        {
                            var fileUrl = _serverpath + "\\" + FileAttachment.UserFilesPath + "\\" + fileAtt.FileName;
                            msg.Body += "<li><a href='" + fileUrl + "'>" + fileAtt.DisplayName + "</a></li>";
                        }
                        msg.Body += "</ul>";
                    }
                    msg.Body += "<p>Review this encumbrance request in the <a href='" + contractViewURL + "'>" +
                                "EPS Application</a>.</p>";
                    // Send only to TPK Encumbrance mailbox
                    recipientIDs = getFinanceRecipients();
                    break;

                case ConstantStrings.DraftToCFM:
                    msg.Subject = "Encumbrance Request# " + encumbrance.GroupID + " for contract " + contract.ContractNumber + " for " + encumbrance.LineItemType;
                    msg.Body    = "<p>Please input the following encumbrance into CFM: request ID " + encumbrance.GroupID + " for contract " + contract.ContractNumber + ".</p>\n";
                    //msg.Body += "in the amount of " + Utils.FormatCurrency(encumbranceTotal)  + " applied to Amendment " + encumbrance.FlairAmendmentID + " Line " + encumbrance.LineID6S + ".";
                    if (encumbrance.LineItems != null && encumbrance.LineItems.Count > 0)
                    {
                        string tblText = "<table><tr><th>Contract</th><th>Amendment</th><th>Line (6s)</th><th>Amount</th></tr>";
                        foreach (LineItem item in encumbrance.LineItems)
                        {
                            tblText += "<tr><td>" + contract.ContractNumber + "</td><td>" + item.FlairAmendmentID + "</td><td>" + item.LineID6S + "</td><td>" + Utils.FormatCurrency(item.Amount) + "</td></tr>";
                        }
                        tblText  += "</table> <br/>";
                        msg.Body += tblText;
                    }
                    if (comments != null && comments.Length > 0)
                    {
                        msg.Body += "<p>Comments: " + comments + "</p>\n";
                    }
                    msg.Body += "<p>View this encumbrance request in the <a href='" + contractViewURL + "'>" +
                                "EPS Application</a>.</p>";
                    // Send only to TPK Encumbrance mailbox
                    recipientIDs = (List <int>)_context.Users.Where(u => u.Email == ConstantStrings.TPKMailbox).Select(u => u.UserID).ToList();
                    break;

                case ConstantStrings.FinanceToDraft:
                case ConstantStrings.CFMToDraft:
                case ConstantStrings.CompleteToDraft:
                    msg.Subject = "Encumbrance Request#" + encumbrance.GroupID + " for contract " + contract.ContractNumber + " has been returned to the Originator";
                    msg.Body    = "<p>Encumbrance ID " + encumbrance.GroupID + " for contract " + contract.ContractNumber + " has been returned for the following reason:</p>\n";
                    if (comments.Length > 0)
                    {
                        msg.Body += "<p>Comments: " + comments + "</p>\n";
                    }
                    msg.Body += "<p>Review this encumbrance request in the <a href='" + contractViewURL + "'>" +
                                "EPS Application</a>.</p>";
                    recipientIDs = new List <int> {
                        encumbrance.OriginatorUserID
                    };
                    break;

                case ConstantStrings.FinanceToWP:
                    msg.Subject = "Please review encumbrance request #" + encumbrance.GroupID + " for contract " + contract.ContractNumber + " for Work Program Evaluation";
                    msg.Body    = "<p>" + submitter.FullName + " has completed a Finance Review for encumbrance request #" + encumbrance.GroupID + " under contract " + contract.ContractNumber + ".</p>\n";
                    if (comments.Length > 0)
                    {
                        msg.Body += "<p>Comments: " + comments + "</p>\n";
                    }
                    msg.Body += "<p>Review this encumbrance request in the <a href='" + contractViewURL + "'>" +
                                "EPS Application</a>.</p>";
                    recipientIDs = otherRecipients;     //(List<int>)_context.UserRoles.Where(u => u.Role.Equals(ConstantStrings.WPReviewer)).Select(u => u.UserID).ToList();
                    break;

                case ConstantStrings.FinanceToCFM:
                case ConstantStrings.FinanceToComplete:
                    // No notification required. Exit without sending message
                    return(0);

                case ConstantStrings.WPToFinance:
                    msg.Subject = "Encumbrance request #" + encumbrance.GroupID + " for contract " + contract.ContractNumber + " has been returned by Work Program";
                    msg.Body    = "<p>" + submitter.FullName + " has completed a Work Program review for encumbrance request #" + encumbrance.GroupID + " under contract " + contract.ContractNumber + ".</p>\n";
                    msg.Body   += "<p>This encumbrance request is returned to Finance with the following comment:</p>";
                    if (comments.Length > 0)
                    {
                        msg.Body += "<p>Comments: " + comments + "</p>\n";
                    }
                    msg.Body += "<p>Review this encumbrance request in the <a href='" + contractViewURL + "'>" +
                                "EPS Application</a>.</p>";
                    // Send only to TPK Encumbrance mailbox
                    recipientIDs = (List <int>)_context.Users.Where(u => u.Email == ConstantStrings.TPKMailbox).Select(u => u.UserID).ToList();
                    break;

                case ConstantStrings.WPToCFM:
                    msg.Subject = "Encumbrance request #" + encumbrance.GroupID + " for contract " + contract.ContractNumber + " is ready for CFM Input";
                    msg.Body    = "<p>" + submitter.FullName + " has completed a Work Program review for encumbrance request #" + encumbrance.GroupID + " in Work Program review under contract " + contract.ContractNumber + ".</p>\n";
                    if (comments.Length > 0)
                    {
                        msg.Body += "<p>Comments: " + comments + "</p>\n";
                    }
                    msg.Body += "<p>Review this encumbrance request in the <a href='" + contractViewURL + "'>" +
                                "EPS Application</a>.</p>";
                    // Send only to TPK Encumbrance mailbox
                    recipientIDs = (List <int>)_context.Users.Where(u => u.Email == ConstantStrings.TPKMailbox).Select(u => u.UserID).ToList();
                    break;

                case ConstantStrings.CFMToFinance:
                    msg.Subject = "Encumbrance request #" + encumbrance.GroupID + " for contract " + contract.ContractNumber + " has been returned to Finance";
                    msg.Body    = "<p>" + submitter.FullName + " has returned to Encumbranc request #" + encumbrance.GroupID + " to Finance with the following comment:</p>";
                    if (comments.Length > 0)
                    {
                        msg.Body += "<p>Comments: " + comments + "</p>\n";
                    }
                    msg.Body += "<p>Review this encumbrance request in the <a href='" + contractViewURL + "'>" +
                                "EPS Application</a>.</p>";
                    // Send only to TPK Encumbrance mailbox
                    recipientIDs = (List <int>)_context.Users.Where(u => u.Email == ConstantStrings.TPKMailbox).Select(u => u.UserID).ToList();
                    break;

                case ConstantStrings.CFMToWP:
                    msg.Subject = "Please review encumbrance request #" + encumbrance.GroupID + " for contract " + contract.ContractNumber + " requires additional Work Program Review";
                    msg.Body    = "<p>" + submitter.FullName + " has returned encumbrance request #" + encumbrance.GroupID + " from CFM for additional Work Program review for contract " + contract.ContractNumber + ".</p>\n";
                    if (comments.Length > 0)
                    {
                        msg.Body += "<p>Comments: " + comments + "</p>\n";
                    }
                    msg.Body += "<p>Review this encumbrance request in the <a href='" + contractViewURL + "'>" +
                                "EPS Application</a>.</p>";
                    recipientIDs = otherRecipients;;
                    break;

                case ConstantStrings.CFMToComplete:
                    //msg.Subject = "Encumbrance request #" + encumbrance.GroupID + " for contract " + contract.ContractNumber + " has been input into CFM";
                    //msg.Body = "<p>" + submitter.FullName + " has input encumbrance request #" + encumbrance.GroupID + " for contract " + contract.ContractNumber + " into CFM.</p>\n";
                    //if (comments.Length > 0)
                    //{ msg.Body += "<p>Comments: " + comments + "</p>\n"; }
                    //msg.Body += "<p>No further action is required. You may view this encumbrance request in the <a href='" + contractViewURL + "'>" +
                    //    "EPS Application</a>.</p>";
                    //// Send only to TPK Encumbrance mailbox
                    //recipientIDs = new List<int> { submitter.UserID };
                    // No notification needed per Lorna 7/9/2019
                    return(0);

                case ConstantStrings.CloseContract:
                    msg.Subject = "Request to Close Contract #" + contract.ContractNumber;
                    msg.Body    = "<p>" + submitter.FullName + " requests closure of the contract " + contract.ContractNumber + ", closure type " + encumbrance.LineItemType + " </p>";
                    //msg.Body += "<p>Review this closure request in the <a href='" + contractViewURL + "'>" + "EPS Application</a>.</p>";
                    recipientIDs = (List <int>)_context.UserRoles.Where(u => u.Role.Equals(ConstantStrings.Closer)).Select(u => u.UserID).ToList();
                    ccIDs        = (List <int>)_context.UserRoles.Where(u => u.Role.Equals(ConstantStrings.CloserCC)).Select(u => u.UserID).ToList();
                    break;

                default:
                    // if no message then exit
                    return(0);
                }
                // Save the message to the database

                try
                {
                    _context.Messages.Add(msg);
                    _context.SaveChanges();
                    msgID = msg.MessageID;
                    if (otherRecipients != null && otherRecipients.Count > 0)
                    {
                        AddRecipients(msgID, otherRecipients);
                    }
                    else
                    {
                        AddRecipients(msgID, recipientIDs);
                    }
                    if (ccIDs != null && ccIDs.Count > 0)
                    {
                        AddCCs(msgID, ccIDs);
                    }
                }catch (Exception e)
                {
                    Log.Error("MessageService.AddMessage Error:" + e.GetBaseException() + "\n" + e.StackTrace);
                    return(-1);
                }
            }
            return(msgID);
        }