public ActionResult MessageDetail(int MessageID = 0, string MessageCode = "")
        {
            RememberURL();
            if (!CheckIsLogin())
            {
                return(Redirect(res.Pageviews.PvMemberSignIn));
            }
            else
            {
                if (CheckIsAdmin(9))
                {
                    GetStatusUser();
                    if (MessageID > 0)
                    {
                        Ouikum.Message.MessageService svMessage = new Ouikum.Message.MessageService();
                        var Message = svMessage.SelectData <view_Message>("*", "IsDelete = 0 AND MessageID =" + MessageID).First();

                        ViewBag.Message  = Message;
                        ViewBag.msgtitle = Message.Subject;

                        #region Get FromComp Detail
                        if (Message.FromCompID > 0)
                        {
                            GetCompany((int)Message.FromCompID);
                        }
                        else
                        {
                            ViewBag.Company = null;
                        }
                        #endregion

                        #region Get ToComp Detail
                        if (Message.ToCompID > 0)
                        {
                            GetToCompany((int)Message.ToCompID);
                        }
                        else
                        {
                            ViewBag.CompanyDetail = null;
                        }
                        #endregion

                        return(View());
                    }
                    else
                    {
                        return(Redirect("~/Report/List"));
                    }
                }
                else
                {
                    return(Redirect(res.Pageviews.PvAccessDenied));
                }
            }
        }
Esempio n. 2
0
        public ActionResult New(FormCollection form)
        {
            if (LogonCompID > 0)
            {
                Ouikum.Message.MessageService svMessage = new Ouikum.Message.MessageService();
                svCompany = new CompanyService();
                string   ToCompID          = form["hidToCompID"];
                string[] sub_ToCompID      = ToCompID.Split(',');
                int      rootMsgID         = DataManager.ConvertToInteger(form["hidMsgID"]);
                string   sqlWhere          = "";
                string   msgdetail         = form["MsgDetail"];
                string   msgStatus         = form["msgstatus"];
                var      emMessageSender   = new emMessage();
                var      emMessageReceiver = new emMessage();
                var      comp = svCompany.SelectData <b2bCompany>("CompID,CompPhone,CompName,ContactFirstName,ContactEmail", "CompID = " + LogonCompID).First();
                if (DataManager.ConvertToBool(form["IsImportance"]) == true)
                {
                    msgdetail += "<p><strong>" + res.Message_Center.lblContactImmediately + "</strong></p>";
                }
                // บันทึกในแบบร่าง
                if (msgStatus == "Draft")
                {
                    var emMessage = new emMessage();

                    var Messages = svMessage.SelectData <view_Message>("*", "MsgFolderID = 3 AND MessageID = " + DataManager.ConvertToInteger(form["hidMsgID"]));
                    #region Draft
                    if (Messages.Count > 0)
                    {
                        for (int i = 0; i < sub_ToCompID.Length; i++)
                        {
                            var sqlUpdate = "ToCompID = " + DataManager.ConvertToInteger(sub_ToCompID[i]) + " , Subject = N'" + form["txtSubject"] + "' , MsgDetail = N'" + msgdetail + "'";
                            if (!string.IsNullOrEmpty(form["hidImgFileName"]))
                            {
                                sqlUpdate += ", IsAttach = 1";
                            }
                            else
                            {
                                sqlUpdate += ", IsAttach = 0";
                            }
                            svMessage.UpdateByCondition <emMessage>(sqlUpdate, " MessageID = " + Messages[0].MessageID);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < sub_ToCompID.Length; i++)
                        {
                            emMessage.ToCompID         = DataManager.ConvertToInteger(sub_ToCompID[i]);
                            emMessage.FromCompID       = LogonCompID;
                            emMessage.IsFavorite       = DataManager.ConvertToBool(form["IsImportance"]);
                            emMessage.Subject          = form["txtSubject"];
                            emMessage.MsgDetail        = msgdetail;
                            emMessage.MsgFolderID      = 3;
                            emMessage.RootMessageID    = 0;//rootMsgID
                            emMessage.MessageCode      = emMessage.ToCompID + "-" + GetTimeStamp() + "-" + svMessage.Generate_MessageCode();
                            emMessage.MsgStatus        = "3";
                            emMessage.IsSend           = false;
                            emMessage.FromName         = comp.ContactFirstName != null ? comp.ContactFirstName : comp.CompName;
                            emMessage.FromContactPhone = comp.CompPhone;
                            emMessage.FromEmail        = comp.ContactEmail;
                            if (!string.IsNullOrEmpty(form["hidImgFileName"]))
                            {
                                emMessage.IsAttach = true;
                            }
                            else
                            {
                                emMessage.IsAttach = false;
                            }
                            #region Save Draft
                            emMessage = svMessage.InsertMessage(emMessage);
                            #endregion

                            // เช็คไฟล์แนบ
                            if (!string.IsNullOrEmpty(form["hidImgFileName"]))
                            {
                                #region Save Image Files
                                imgManager             = new FileHelper();
                                imgManager.DirPath     = "MessageFile/" + LogonCompID + "/" + emMessage.MessageID;
                                imgManager.DirTempPath = "Temp/MessageFile/" + LogonCompID;
                                SaveFileImage(
                                    imgManager.DirTempPath,
                                    imgManager.DirPath,
                                    form["hidImgFileName"]);
                                #endregion

                                string   strFileName   = form["hidImgFileName"];
                                string[] ArrayFileName = strFileName.Split('.');

                                var Attach = new emMessageAttach();
                                Attach.MessageID   = emMessage.MessageID;
                                Attach.MessageCode = emMessage.MessageCode;
                                Attach.FileName    = form["hidImgFileName"];
                                Attach.FileType    = "." + ArrayFileName[1];
                                Attach.FilePath    = "https://ouikumstorage.blob.core.windows.net/upload/MessageFile/" + LogonCompID + "/" + emMessage.MessageID + "/" + form["hidImgFileName"];
                                Attach.FileSize    = 0;
                                Attach             = svMessage.InsertMessageFile(Attach);
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    //ส่งข้อความ
                    for (int i = 0; i < sub_ToCompID.Length; i++)
                    {
                        // บันทึกข้อมูลลงกล่องขาออกของผู้ส่ง
                        #region Sender Message
                        emMessageSender.ToCompID         = DataManager.ConvertToInteger(sub_ToCompID[i]);
                        emMessageSender.FromCompID       = LogonCompID;
                        emMessageSender.IsFavorite       = DataManager.ConvertToBool(form["IsImportance"]);
                        emMessageSender.Subject          = form["txtSubject"];
                        emMessageSender.MsgDetail        = msgdetail;
                        emMessageSender.MsgFolderID      = 2;
                        emMessageSender.RootMessageID    = (rootMsgID != 0) ? rootMsgID : 0;
                        emMessageSender.MessageCode      = emMessageSender.ToCompID + "-" + GetTimeStamp() + "-" + svMessage.Generate_MessageCode();
                        emMessageSender.MsgStatus        = "2";
                        emMessageSender.IsSend           = true;
                        emMessageSender.FromName         = comp.ContactFirstName != null ?comp.ContactFirstName : comp.CompName;
                        emMessageSender.FromContactPhone = comp.CompPhone;
                        emMessageSender.FromEmail        = comp.ContactEmail;
                        if (!string.IsNullOrEmpty(form["hidImgFileName"]))
                        {
                            emMessageSender.IsAttach = true;
                        }
                        else
                        {
                            emMessageSender.IsAttach = false;
                        }

                        #region Save Sender Message
                        if (msgStatus == "Reply")
                        {
                            emMessageSender = svMessage.InsertMessageReply(emMessageSender, "Reply");
                        }
                        else if (msgStatus == "Forward")
                        {
                            emMessageSender = svMessage.InsertMessageReply(emMessageSender, "Forward");
                        }
                        else
                        {
                            emMessageSender = svMessage.InsertMessage(emMessageSender);
                        }
                        #endregion
                        #endregion
                        // บันทึกข้อมูลลงกล่องขาเข้าของผู้รับ
                        #region Receiver Message
                        emMessageReceiver.ToCompID         = DataManager.ConvertToInteger(sub_ToCompID[i]);
                        emMessageReceiver.FromCompID       = LogonCompID;
                        emMessageReceiver.Subject          = form["txtSubject"];
                        emMessageReceiver.MsgDetail        = form["MsgDetail"];
                        emMessageReceiver.MsgFolderID      = 1;
                        emMessageReceiver.IsFavorite       = DataManager.ConvertToBool(form["IsImportance"]);
                        emMessageReceiver.RootMessageID    = (rootMsgID != 0) ? rootMsgID : 0;
                        emMessageReceiver.MessageCode      = emMessageSender.MessageCode;
                        emMessageReceiver.MsgStatus        = "1";
                        emMessageReceiver.IsSend           = false;
                        emMessageReceiver.FromName         = comp.ContactFirstName != null ?comp.ContactFirstName : comp.CompName;
                        emMessageReceiver.FromContactPhone = comp.CompPhone;
                        emMessageReceiver.FromEmail        = comp.ContactEmail;
                        if (!string.IsNullOrEmpty(form["hidImgFileName"]))
                        {
                            emMessageReceiver.IsAttach = true;
                        }
                        else
                        {
                            emMessageReceiver.IsAttach = false;
                        }

                        #region Save Receiver Message

                        if (msgStatus == "Reply")
                        {
                            emMessageReceiver = svMessage.InsertMessageReply(emMessageReceiver, "Reply");
                        }
                        else if (msgStatus == "Forward")
                        {
                            emMessageReceiver = svMessage.InsertMessageReply(emMessageReceiver, "Forward");
                        }
                        else
                        {
                            emMessageReceiver = svMessage.InsertMessage(emMessageReceiver);
                        }
                        #endregion

                        #endregion
                        // เช็คไฟล์แนบ
                        if (!string.IsNullOrEmpty(form["hidImgFileName"]))
                        {
                            // บันทึกข้อมูลลงกล่องขาออกของผู้ส่ง
                            #region Save Image Files
                            imgManager             = new FileHelper();
                            imgManager.DirPath     = "MessageFile/" + LogonCompID + "/" + emMessageSender.MessageID;
                            imgManager.DirTempPath = "Temp/MessageFile/" + LogonCompID;
                            SaveFileImage(
                                imgManager.DirTempPath,
                                imgManager.DirPath,
                                form["hidImgFileName"]);
                            #endregion

                            string   strFileName1   = form["hidImgFileName"];
                            string[] ArrayFileName1 = strFileName1.Split('.');

                            var Attach1 = new emMessageAttach();
                            Attach1.MessageID   = emMessageSender.MessageID;
                            Attach1.MessageCode = emMessageSender.MessageCode;
                            Attach1.FileName    = form["hidImgFileName"];
                            Attach1.FileType    = "." + ArrayFileName1[1];
                            Attach1.FilePath    = "https://ouikumstorage.blob.core.windows.net/upload/MessageFile/" + LogonCompID + "/" + emMessageSender.MessageID + "/" + form["hidImgFileName"];
                            Attach1.FileSize    = 0;
                            Attach1             = svMessage.InsertMessageFile(Attach1);

                            // บันทึกข้อมูลลงกล่องขาเข้าของผู้รับ
                            #region Save Image Files
                            imgManager             = new FileHelper();
                            imgManager.DirPath     = "MessageFile/" + LogonCompID + "/" + emMessageReceiver.MessageID;
                            imgManager.DirTempPath = "Temp/MessageFile/" + LogonCompID;
                            SaveFileImage(
                                imgManager.DirTempPath,
                                imgManager.DirPath,
                                form["hidImgFileName"]);
                            #endregion

                            string   strFileName2   = form["hidImgFileName"];
                            string[] ArrayFileName2 = strFileName2.Split('.');

                            var Attach2 = new emMessageAttach();
                            Attach2.MessageID   = emMessageReceiver.MessageID;
                            Attach2.MessageCode = emMessageReceiver.MessageCode;
                            Attach2.FileName    = form["hidImgFileName"];
                            Attach2.FileType    = "." + ArrayFileName2[1];
                            Attach2.FilePath    = "https://ouikumstorage.blob.core.windows.net/upload/MessageFile/" + LogonCompID + "/" + emMessageReceiver.MessageID + "/" + form["hidImgFileName"];
                            Attach2.FileSize    = 0;
                            Attach2             = svMessage.InsertMessageFile(Attach2);
                        }

                        if (emMessageReceiver.ToCompID > 0)
                        {
                            #region GetToCompName
                            sqlWhere = "CompID = " + emMessageReceiver.ToCompID + " AND IsDelete = 0";
                            var Company     = svCompany.SelectData <b2bCompany>("CompID,CompName,ContactEmail", sqlWhere).First();
                            var toCompName  = Company.CompName;
                            var toCompEmail = Company.ContactEmail;
                            #endregion

                            #region Send Email
                            if (svMessage.IsResult)
                            {
                                SendEmail(emMessageReceiver, toCompName, toCompEmail);
                            }
                            #endregion
                        }
                        else
                        {
                            if (svMessage.IsResult)
                            {
                                SendEmailNoMember(emMessageReceiver, form["hidNameNotMember"], form["hidEmailNotMember"]);
                            }
                        }
                    }
                }

                GetStatusUser();
                CountMessage();

                return(View());
            }
            else
            {
                return(Redirect(res.Pageviews.PvMemberSignUp));
            }
        }