示例#1
0
        public string InsertMessage(string subject, string msgContent, string sentStatus, string sentType, string toUsers, string ccUsers, string msgCode)
        {
            string result = string.Empty;
            List <MVCModels.MessagingModel> lstMsgContent = new List <MVCModels.MessagingModel>();
            List <MVCModels.MessagingModel> lstMsgUsers   = new List <MVCModels.MessagingModel>();

            DataControl.CurrentInfo  objCurInfo         = new DataControl.CurrentInfo();
            DataControl.BLMessaging  objMsg             = new DataControl.BLMessaging();
            MVCModels.MessagingModel objMsgContentModel = new MVCModels.MessagingModel();
            try
            {
                #region message content details
                if (sentStatus.ToUpper().Trim() == "SEND")
                {
                    if (!string.IsNullOrEmpty(msgCode))
                    {
                        objMsgContentModel.Msg_Code = msgCode;
                    }
                    else
                    {
                        sentType = "STRAIGHT";
                        msgCode  = Convert.ToString(objMsg.GetSeqNumber("SEQ_tbl_SFA_Noticeboard_Content_MSG"));
                        objMsgContentModel.Msg_Code = msgCode;
                    }


                    objMsgContentModel.Sent_Status = "SENT";
                }
                else if (sentStatus.ToUpper().Trim() == "DRAFT")
                {
                    sentType = "STRAIGHT";
                    if (!string.IsNullOrEmpty(msgCode))
                    {
                        objMsgContentModel.Msg_Code = msgCode;
                    }
                    else
                    {
                        msgCode = Convert.ToString(objMsg.GetSeqNumber("SEQ_tbl_SFA_Noticeboard_Content_MSG"));
                        objMsgContentModel.Msg_Code = msgCode;
                    }

                    objMsgContentModel.Sent_Status = "DRAFTED";
                }
                objMsgContentModel.Company_Code    = objCurInfo.GetCompanyCode();
                objMsgContentModel.Subject         = subject.Replace("á", "<").Replace("í", ">");
                objMsgContentModel.Message_Content = msgContent.Replace("á", "<").Replace("í", ">"); //ALT+160 = á , ALT+161 = í
                objMsgContentModel.Is_Richtext     = "1";
                objMsgContentModel.Priority        = "1";
                // objMsgContentModel.Date_From = "GETDATE()";
                objMsgContentModel.Sender     = objCurInfo.GetUserCode();
                objMsgContentModel.Sent_Type  = sentType;
                objMsgContentModel.Row_Status = "1";
                lstMsgContent.Add(objMsgContentModel);
                #endregion message content details
                #region message user details
                //TO USERS
                string[] ar = toUsers.Split(',');
                for (int i = 0; i < ar.Length; i++)
                {
                    if (!string.IsNullOrEmpty(ar[i]))
                    {
                        MVCModels.MessagingModel objMsgUserModel = new MVCModels.MessagingModel();
                        objMsgUserModel.Company_Code   = objCurInfo.GetCompanyCode();
                        objMsgUserModel.Msg_Code       = msgCode;
                        objMsgUserModel.Target_Address = ar[i];
                        objMsgUserModel.Address_Type   = "TO";
                        objMsgUserModel.Row_Status     = "1";
                        objMsgUserModel.Project_Code   = "MSGSYSTEM";
                        objMsgUserModel.Ack_Reqd       = "N";
                        objMsgUserModel.IsRead         = "0";
                        lstMsgUsers.Add(objMsgUserModel);
                    }
                }
                string[] arcc = ccUsers.Split(',');
                for (int i = 0; i < arcc.Length; i++)
                {
                    if (!string.IsNullOrEmpty(arcc[i]))
                    {
                        MVCModels.MessagingModel objMsgUserModel = new MVCModels.MessagingModel();
                        objMsgUserModel.Company_Code   = objCurInfo.GetCompanyCode();
                        objMsgUserModel.Msg_Code       = msgCode;
                        objMsgUserModel.Target_Address = arcc[i];
                        objMsgUserModel.Address_Type   = "CC";
                        objMsgUserModel.Row_Status     = "1";
                        objMsgUserModel.Project_Code   = "MSGSYSTEM";
                        objMsgUserModel.Ack_Reqd       = "N";
                        objMsgUserModel.IsRead         = "0";
                        lstMsgUsers.Add(objMsgUserModel);
                    }
                }
                #endregion message user details

                int rowsAffected = 0;
                if ("DRAFTED" == sentType.ToUpper())
                {
                    //DRAFTED THEN SEND THE MSG
                    rowsAffected = objMsg.UpdateDraftedMail(objCurInfo.GetCompanyCode(), lstMsgContent, lstMsgUsers, msgCode);
                }
                else
                {
                    rowsAffected = objMsg.InsertSendOrDraftMail(objCurInfo.GetCompanyCode(), lstMsgContent, lstMsgUsers, sentStatus);
                    //REPLY, FORWARD, FORWARDALL MSG
                    //  rowsAffected = objMsg.InsertReplyOrForwardMail(objCurInfo.GetCompanyCode(), lstMsgContent, lstMsgUsers);
                }
                if (rowsAffected > 0)
                {
                    if (sentStatus.ToUpper().Trim() == "DRAFT")
                    {
                        result = "SUCCESS:" + msgCode + "~Your message has been drafted";
                    }
                    else
                    {
                        result = "SUCCESS:" + msgCode + "~Your message has been sent";
                    }
                }
                else
                {
                    result = "ERROR:" + msgCode + "~Sorry. Error while sennding the message ...";
                }
            }
            catch (Exception ex)
            {
                Dictionary <string, string> dicObj = new Dictionary <string, string>();
                DataControl.Impl.ExceptionHandler.WriteLog(ex: ex, dic: dicObj);
                result = "Sorry. Error while sennding the message ...";
            }
            return(result);
        }