Exemplo n.º 1
0
 public string EditAnswer(int id, DiaryAnswer newAnswer)
 {
     try
     {
         var oldAnswer = _context.DiaryAnswer.SingleOrDefault(x => x.Id == id);
         if (oldAnswer != null)
         {
             oldAnswer.Answer = newAnswer.Answer;
             _context.SaveChanges();
             return("編輯成功");
         }
         else
         {
             return("編輯失敗");
         }
     }
     catch (Exception e)
     { return("編輯失敗" + e.ToString()); }
 }
Exemplo n.º 2
0
        public string InsertAnswer(DiaryAnswer diaryAnswer)
        {
            try

            {
                var isAnswerExist = _context.DiaryAnswer.SingleOrDefault(x => x.MemberId == diaryAnswer.MemberId && x.Date == diaryAnswer.Date);
                if (isAnswerExist != null)
                {
                    return(EditAnswer(isAnswerExist.Id, diaryAnswer));
                }
                else
                {
                    var questionId = GetQuestionDiary(diaryAnswer.Date.ToString("yyyy-MM-dd HH:mm:ss").Substring(0, 10));
                    diaryAnswer.QuestionId = questionId.Id;
                    _context.DiaryAnswer.Add(diaryAnswer);
                    _context.SaveChanges();
                    return("新增答案成功");
                }
            }
            catch (Exception e)
            {
                return(e.ToString());
            }
        }
Exemplo n.º 3
0
        public string EditAnswer(int id, DiaryAnswer newAnswer)
        {
            var editAnswer = diaryService.EditAnswer(id, newAnswer);

            return(editAnswer);
        }
Exemplo n.º 4
0
        public string InsertAnswer(DiaryAnswer diaryAnswer)
        {
            var insertAnswer = diaryService.InsertAnswer(diaryAnswer);

            return(insertAnswer);
        }