public ActionResult _PartialOpenPopupReply(EEmailReplyCan emailreplycan, int? deleteReply)
        {
            if (ModelState.IsValid)
            {
                if (deleteReply != null && deleteReply > 0)
                {
                    emailreplycan = db.EmailReplyCan.Find(emailreplycan.Id);
                    db.EmailReplyCan.Remove(emailreplycan);
                }
                else
                {
                    emailreplycan.TempCnt = System.Text.Encoding.GetEncoding("utf-8").GetBytes(emailreplycan.TmpContent);

                    if (emailreplycan.Id == 0)
                    {
                        db.EmailReplyCan.Add(emailreplycan);
                    }
                    else
                    {
                        if (emailreplycan.Id == 1 || emailreplycan.Id == 2)
                            emailreplycan.Active = true;

                        db.Entry(emailreplycan).State = EntityState.Modified;
                    }
                }
                db.SaveChanges();
            }

            return RedirectToAction("Index", "EmailReplyTemplate", new { Area = "EmailSrv" });
        }
        public ActionResult _PartialOpenPopupReply(int id = 0)
        {
            var emailreplycan = db.EmailReplyCan.Find(id);

            if (emailreplycan != null)
            {
                emailreplycan.TmpContent = System.Text.Encoding.GetEncoding("utf-8").GetString(emailreplycan.TempCnt);
                emailreplycan.TempCnt = null;
                return PartialView("~/Areas/EmailSrv/Views/EmailReplyTemplate/_PartialOpenPopupReply.cshtml", emailreplycan);
            }
            else
            {
                emailreplycan = new EEmailReplyCan();
                emailreplycan.Id = id;
                emailreplycan.Name = "";
                emailreplycan.TmpContent = "";
                emailreplycan.Active = true;

                return PartialView("~/Areas/EmailSrv/Views/EmailReplyTemplate/_PartialOpenPopupReply.cshtml", emailreplycan);
            }
        }
        private EmailReplyTemplate GetIndexModel(string type = "", string condition = "", int page = 1)
        {
            int currentPage = page < 1 ? 1 : page;

            EmailReplyTemplate emailreplytemp = new EmailReplyTemplate();

            #region 檢查簽名檔, 若沒有, 則新增
            bool bAddNew = false;
            if (db.EmailReplyCan.Find(1) == null)
            {
                EEmailReplyCan emailreplycan = new EEmailReplyCan();
                emailreplycan.Id = 1;
                emailreplycan.Name = "個人版簽名檔";
                emailreplycan.Active = true;
                emailreplycan.TempCnt = System.Text.Encoding.GetEncoding("utf-8").GetBytes("");
                db.EmailReplyCan.Add(emailreplycan);

                bAddNew = true;
            }

            if (db.EmailReplyCan.Find(2) == null)
            {
                EEmailReplyCan emailreplycan = new EEmailReplyCan();
                emailreplycan.Id = 1;
                emailreplycan.Name = "企業版簽名檔";
                emailreplycan.Active = true;
                emailreplycan.TempCnt = System.Text.Encoding.GetEncoding("utf-8").GetBytes("");
                db.EmailReplyCan.Add(emailreplycan);

                bAddNew = true;
            }

            if (bAddNew)
                db.SaveChanges();

            #endregion

            emailreplytemp.EmailReplyCan = db.EmailReplyCan.OrderByDescending(c => c.Id);

            #region 查詢
            if (!String.IsNullOrEmpty(condition) && !String.IsNullOrEmpty(condition))
            {
                emailreplytemp.EmailReplyCan = emailreplytemp.EmailReplyCan.Where(c => (c.Name.ToUpper().Contains(condition.ToUpper())));
            }
            #endregion

            // 抓取需求頁碼的資料
            emailreplytemp.EmailReplyCan = emailreplytemp.EmailReplyCan.ToPagedList(currentPage, pageSize);

            #region 回覆範本內容解碼
            foreach (var rc in emailreplytemp.EmailReplyCan)
            {
                rc.TmpContent = System.Text.Encoding.GetEncoding("utf-8").GetString(rc.TempCnt);
                rc.TempCnt = null;
            }

            #endregion

            ViewBag.ConditionReplyCan = condition;
            ViewBag.NumberBeginReplyCan = pageSize * (page - 1);

            return emailreplytemp;
        }