public bool Create(ReplyPhraseViewModel replyPhraseViewModel)
        {
            bool ret = false;
            try
            {
                ReplyPhrase itemdata = new ReplyPhrase();

                itemdata.Note = replyPhraseViewModel.Note;
                itemdata.EventClass = replyPhraseViewModel.EventClass;

                itemdata.Type = replyPhraseViewModel.Type;
                itemdata.OrderSeq = replyPhraseViewModel.OrderSeq;

                itemdata.CreateDateTime = DateTime.Now;
                itemdata.ModifyDateTime = DateTime.Now;
                itemdata.CreateUserID = replyPhraseViewModel.CreateUserID;
                itemdata.ModifyUserID = replyPhraseViewModel.CreateUserID;

                db.ReplyPhrase.Add(itemdata);
                db.SaveChanges();

                ret = true;
            }
            catch
            {
            }
            return ret;
        }
        public IQueryable<ReplyPhraseViewModel> Read(string eventclass,string type)
        {

            List<ReplyPhraseViewModel> ret = new List<ReplyPhraseViewModel>();
            
            var qry = db.ReplyPhrase.Where(q => q.EventClass == eventclass);
            if (type != "" && type != null)
            {
                int t = int.Parse(type);
                qry = qry.Where(x => x.Type == t);
            }

            foreach (ReplyPhrase o in qry)
            {
                ReplyPhraseViewModel r = new ReplyPhraseViewModel();

                r.Seq = o.Seq;
                r.Note = o.Note;
                r.EventClass = o.EventClass;
                r.EventClassStr = o.EventClass + " - " + db.EventClass.Where(x => x.Class == o.EventClass).Select(x => x.Name).First();
                r.Type = o.Type;
                
                switch (o.Type)
                {
                    case 0:
                        r.TypeStr = "問題描述";
                        break;
                    case 1:
                        r.TypeStr = "建議解決方式描述";
                        break;
                    case 2:
                        r.TypeStr = "備機說明";
                        break;
                    case 3:
                        r.TypeStr = "回覆說明(拒絕必填原因)";
                        break;
                    case 4:
                        r.TypeStr = "處理說明";
                        break;
                }
                r.OrderSeq = o.OrderSeq;
                r.ModifyDTStr = o.ModifyDateTime.ToString("yyyy/MM/dd HH:mm");
                r.CreateDTStr = o.CreateDateTime.ToString("yyyy/MM/dd HH:mm");
                r.CreateUserName = o.UserData.UserName;
                r.ModifyUserName = o.UserData1.UserName;
              
                ret.Add(r);
            }

            return ret.AsQueryable();
        }
 public bool Delete(ReplyPhraseViewModel replyPhraseViewModel)
 {
     bool ret = false;
     try
     {
         int seq = replyPhraseViewModel.Seq;
         ReplyPhrase replyPhrase = db.ReplyPhrase.Find(seq);
         db.ReplyPhrase.Remove(replyPhrase);
         db.SaveChanges();
         ret = true;
     }
     catch
     {
     }
     return ret;
 }
        public bool Update(ReplyPhraseViewModel replyPhraseViewModel)
        {
            bool ret = false;
            try
            {
                int seq = replyPhraseViewModel.Seq;

                ReplyPhrase replyPhrase = db.ReplyPhrase.Find(seq);

                replyPhrase.Type = replyPhraseViewModel.Type;
                replyPhrase.OrderSeq = replyPhraseViewModel.OrderSeq;
                //replyPhrase.ID = replyPhraseViewModel.ID;
                replyPhrase.Note = replyPhraseViewModel.Note;
                replyPhrase.EventClass = replyPhraseViewModel.EventClass;
                replyPhrase.ModifyDateTime = DateTime.Now;
                replyPhrase.ModifyUserID = replyPhraseViewModel.ModifyUserID;
                db.SaveChanges();
                ret = true;

            }
            catch (DbUpdateConcurrencyException ex)
            {
                // Update the values of the entity that failed to save from the store
                ex.Entries.Single().Reload();
            }
            catch (DbEntityValidationException ex)
            {
                var errorMessages = ex.EntityValidationErrors
                         .SelectMany(x => x.ValidationErrors)
                         .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                // Combine the original exception message with the new one.
                var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                // Throw a new DbEntityValidationException with the improved exception message.
                throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
            }
            return ret;
        }