Example #1
0
        public APIResult Add([FromBody] AddArgsModel args)
        {
            try
            {
                if (string.IsNullOrEmpty(args.Question))
                {
                    throw new ArgumentNullException("Question");
                }
                var isExit = wechatCoreDb.QueryRobotMessage()
                             .Where(m => m.Question == args.Question)
                             .Where(m => !m.IsDel)
                             .Count() > 0;
                if (isExit)
                {
                    throw new Exception("问题已经存在");
                }

                var model = new RobotMessage()
                {
                    Question     = args.Question,
                    QuestionType = args.QuestionType,
                    Answer       = args.Answer,
                    Status       = RobotMessageStatus.正常
                };
                wechatCoreDb.AddToRobotMessage(model);
                wechatCoreDb.SaveChanges();
                return(Success());
            }
            catch (Exception ex)
            {
                return(Error(ex.Message));
            }
        }