public static sysGlobalClass.CResutlWebMethod SaveToDB(CSave_Data item, List <dataFileContactUs> objFile)
    {
        sysGlobalClass.CResutlWebMethod result = new sysGlobalClass.CResutlWebMethod();
        PTTGC_EPIEntities db  = new PTTGC_EPIEntities();
        DateTime          now = DateTime.Now;

        if (UserAcc.UserExpired())
        {
            result.Status = SystemFunction.process_SessionExpired;
        }
        else
        {
            UserAcc ua = UserAcc.GetObjUser();
            try
            {
                string     sPathSend = "";
                int        nID       = db.TContactUs.Any() ? db.TContactUs.Max(m => m.nContactID) + 1 : 1;
                TContactUs t         = new TContactUs();
                t.nContactID    = nID;
                t.sContactName  = item.sName;
                t.sContactEmail = item.sEmail;
                t.sContactTel   = item.sTel;
                t.sSubject      = item.sSubject;
                t.sDetail       = item.sDec;
                t.dCreate       = now;
                t.dUpdate       = now;
                t.cDel          = "N";
                if (objFile.Count > 0 && objFile != null)
                {
                    string sPathSave = string.Format(sFolderInPathSave, nID);
                    SystemFunction.CreateDirectory(sPathSave);
                    //string sPathSave = string.Format(sFolderInPathSave, nID);
                    //SystemFunction.CreateDirectory(sPathSave);
                    var    f = objFile.First();
                    string sSystemFileName = nID + "_" + "-" + DateTime.Now.ToString("ddMMyyyyHHmmss") + "." + SystemFunction.GetFileNameFromFileupload(f.sFileName, ""); //SystemFunction2.GetFileType(item.SaveToFileName);
                    SystemFunction.UpFile2Server(f.sPath, sPathSave, f.sSysFileName, sSystemFileName);

                    t.sContactFile    = f.sFileName;
                    t.sContactSysFile = sSystemFileName;
                    t.sContactPath    = sPathSave;
                    sPathSend         = HttpContext.Current.Server.MapPath("./") + sPathSave + sSystemFileName;
                }
                //t.cStatusAns = "NULL";
                db.TContactUs.Add(t);
                var Ispass = db.SaveChanges() > 0;

                if (Ispass)
                {
                    string From    = "";
                    var    lstUser = db.mTUser.FirstOrDefault(w => w.ID == ua.nUserID);
                    if (lstUser != null)
                    {
                        From = lstUser.Email;
                    }

                    // string From = item.sEmail;
                    #region Get_Email_Admin
                    string AdminContactmail = "";
                    var    lst_Email_Admin  = db.TMenu_Permission.Where(w => w.nRoleID == 1 && w.nMenuID == 65 && w.nPermission == 2).ToList();
                    if (lst_Email_Admin.Any())
                    {
                        lst_Email_Admin.ForEach(f =>
                        {
                            int nUserID   = f.nUserID;
                            var lst_Tuser = db.mTUser.FirstOrDefault(w => w.cActive == "Y" && w.ID == nUserID);
                            if (lst_Tuser != null)
                            {
                                AdminContactmail += "," + lst_Tuser.Email + " ";
                            }
                        });
                        AdminContactmail = AdminContactmail.Remove(0, 1);
                    }
                    else
                    {
                        AdminContactmail = WebConfigurationManager.AppSettings["ContactMail"] + "";
                    }
                    #endregion



                    string To       = "*****@*****.**";
                    string sSubject = SystemFunction.sAbbrSystem + " : Contact Us." + item.sSubject;
                    string sGurl    = SystemFunction.RequestUrl() + WebConfigurationManager.AppSettings["DefaultPage"] + "";
                    string sHtml    = @"
                    <table align='left'  border='0' cellspacing='2' cellpadding='3'>

                        <tr>
                            <td align='left'>Dear administrator: " + SystemFunction.SystemName + @" </td>
                        </tr>
                         <tr>
                           <td align='left'>Subject: " + item.sSubject + @"</td>
                        </tr>
                         <tr>
                           <td align='left'>Description: " + item.sDec + @"</td>
                        </tr>
                         <tr>
                           <td align='left'>From: " + item.sName + " E-mail: " + item.sEmail + " Contact phone number: " + item.sTel + @"</td>
                        </tr>
                        <tr>
                            <td align='left'><b>Check out more details.</b>: <a href='" + sGurl + @"' target='_blank'>Please click here</a></td>
                        </tr>
                       
                    </table>";
                    //sPathSend != "" ? sPathSend.Replace("/", "\\") : ""
                    Workflow.DataMail_log log = new Workflow.DataMail_log();
                    log           = SystemFunction.SendMailAll(From, AdminContactmail, "", "", sSubject, sHtml, sPathSend != "" ? sPathSend.Replace("/", "\\") : "");
                    log.nDataID   = SystemFunction.GetIntNullToZero(nID + "");
                    log.sPageName = "f_ContactUs.aspx";
                    new Workflow().SaveLogMail(log);
                    if (log.bStatus)
                    {
                        result.Status = SystemFunction.process_Success;
                    }
                }
            }
            catch (Exception e)
            {
                result.Msg    = e.Message;
                result.Status = SystemFunction.process_Failed;
            }

            result.Status = SystemFunction.process_Success;
        }

        return(result);
    }
    public static sysGlobalClass.CResutlWebMethod SaveToDB(string sDesc, string sID, List <dataFileContactUs> objFile)
    {
        sysGlobalClass.CResutlWebMethod result = new sysGlobalClass.CResutlWebMethod();
        PTTGC_EPIEntities db  = new PTTGC_EPIEntities();
        DateTime          now = DateTime.Now;

        if (UserAcc.UserExpired())
        {
            result.Status = SystemFunction.process_SessionExpired;
        }
        else
        {
            try
            {
                UserAcc ua = UserAcc.GetObjUser();
                if (!string.IsNullOrEmpty(sID))
                {
                    string sPathSend = "";
                    int    nID       = int.Parse(STCrypt.Decrypt(sID));
                    var    Query     = db.TContactUs.FirstOrDefault(w => w.cDel == "N" && w.nContactID == nID);
                    if (Query != null)
                    {
                        Query.sAnswer    = sDesc;
                        Query.cStatusAns = "2";
                        Query.dAnswer    = now;
                        Query.dUpdate    = now;
                        Query.nAnswerBy  = UserAcc.GetObjUser().nUserID;

                        if (objFile.Count > 0 && objFile != null)
                        {
                            string sPathSave = string.Format(sFolderInPathSave, nID);
                            SystemFunction.CreateDirectory(sPathSave);
                            //string sPathSave = string.Format(sFolderInPathSave, nID);
                            //SystemFunction.CreateDirectory(sPathSave);
                            var    f = objFile.First();
                            string sSystemFileName = nID + "_" + "-" + DateTime.Now.ToString("ddMMyyyyHHmmss") + "." + SystemFunction.GetFileNameFromFileupload(f.sFileName, ""); //SystemFunction2.GetFileType(item.SaveToFileName);
                            SystemFunction.UpFile2Server(f.sPath, sPathSave, f.sSysFileName, sSystemFileName);

                            Query.sAnsFile    = f.sFileName;
                            Query.sAnsSysFile = sSystemFileName;
                            Query.sAnsPath    = sPathSave;
                            sPathSend         = HttpContext.Current.Server.MapPath("./") + sPathSave + sSystemFileName;
                        }

                        var Ispass = db.SaveChanges() > 0;
                        if (Ispass)
                        {
                            string To = Query.sContactEmail;                                                   // Contact Mail
                            string AdminContactmail = WebConfigurationManager.AppSettings["ContactMail"] + ""; // Mail Admin
                            //string To1 = "*****@*****.**";

                            string sSubject           = SystemFunction.sAbbrSystem + " : Contact Us." + Query.sSubject;
                            string sGurl              = SystemFunction.RequestUrl() + WebConfigurationManager.AppSettings["DefaultPage"] + "";
                            string sHtml              = @"
                                    <table align='left'  border='0' cellspacing='2' cellpadding='3'>

                                        <tr>
                                            <td align='left'>Dear: " + Query.sContactName + @"</td>
                                        </tr>
                                         <tr>
                                           <td align='left'>Subject: " + Query.sSubject + @"</td>
                                        </tr>
                                         <tr>
                                           <td align='left'>Description: " + Query.sDetail + @"</td>
                                        </tr>
                                        <tr>
                                           <td align='left'>Answer: " + Query.sAnswer + @"</td>
                                        </tr>

                                    </table>";
                            Workflow.DataMail_log log = new Workflow.DataMail_log();

                            string ccMail  = "";
                            var    lstUser = db.mTUser.FirstOrDefault(w => w.ID == ua.nUserID);
                            if (lstUser != null)
                            {
                                ccMail = lstUser.Email;
                            }

                            log           = SystemFunction.SendMailAll(AdminContactmail, To, ccMail, "", sSubject, sHtml, sPathSend != "" ? sPathSend.Replace("/", "\\") : "");
                            log.nDataID   = SystemFunction.GetIntNullToZero(nID + "");
                            log.sPageName = "admin_ContactUs_update.aspx";
                            new Workflow().SaveLogMail(log);
                            if (log.bStatus)
                            {
                                result.Status = SystemFunction.process_Success;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                result.Msg    = e.Message;
                result.Status = SystemFunction.process_Failed;
            }

            result.Status = SystemFunction.process_Success;
        }

        return(result);
    }