コード例 #1
0
        public async Task <bool> UpdateAsync(RuleReplyDto model)
        {
            var uri      = API.Rule.UpdateAsync(_baseUrl);
            var content  = new StringContent(JsonConvert.SerializeObject(model), System.Text.Encoding.UTF8, "application/json");
            var response = await _apiClient.PostAsync(uri, content);

            response.EnsureSuccessStatusCode();
            string res = await response.Content.ReadAsStringAsync();

            return(res.ToLower() == bool.TrueString.ToLower());
        }
コード例 #2
0
        public async Task <IActionResult> Update([FromBody] RuleReplyDto model)
        {
            var res = await ruleService.UpdateAsync(model);

            return(Ok(res));
        }
コード例 #3
0
        /// <summary>
        /// 规则修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <bool> UpdateAsync(RuleReplyDto model)
        {
            using (var tran = databaseFixture.Db.BeginTransaction())
            {
                try
                {
                    var dbrule = await databaseFixture.Db.WxRule.FindByIdAsync(model.Id);

                    dbrule.ResponseMsgType = model.ResponseMsgType;
                    dbrule.RuleName        = model.RuleName;
                    dbrule.RuleType        = model.RuleType;
                    switch ((WxRuleType)model.RuleType)
                    {
                    case WxRuleType.Normal:
                        dbrule.RequestMsgType = (int)RequestMsgType.Text;
                        break;

                    case WxRuleType.Subscribe:
                        dbrule.RequestMsgType = (int)RequestMsgType.Event;
                        break;

                    case WxRuleType.Unmatched:
                        dbrule.RequestMsgType = model.RequestMsgType;
                        break;
                    }
                    await databaseFixture.Db.WxRule.UpdateAsync(dbrule, tran);

                    switch ((RequestMsgType)dbrule.RequestMsgType)
                    {
                    case RequestMsgType.Text:    //关键词
                        var dbkeywords = await databaseFixture.Db.WxKeyword.FindAllAsync(m => m.RuleId == dbrule.Id);

                        foreach (var item in dbkeywords)
                        {
                            await databaseFixture.Db.WxKeyword.DeleteAsync(item, tran);
                        }
                        foreach (var item in model.Keywords)
                        {
                            WxKeyword keyword = new WxKeyword
                            {
                                RuleId  = dbrule.Id,
                                Keyword = item
                            };
                            await databaseFixture.Db.WxKeyword.InsertAsync(keyword, tran);
                        }
                        break;

                    case RequestMsgType.Image:
                        break;

                    case RequestMsgType.Voice:
                        break;

                    case RequestMsgType.Video:
                        break;

                    case RequestMsgType.Location:
                        break;

                    case RequestMsgType.Link:
                        break;

                    case RequestMsgType.ShortVideo:
                        break;

                    case RequestMsgType.Event:
                        break;

                    default:
                        break;
                    }
                    switch ((ResponseMsgType)model.ResponseMsgType)
                    {
                    case ResponseMsgType.Text:
                        var dbtexts = await databaseFixture.Db.WxTextResponse.FindAllAsync(m => m.RuleId == dbrule.Id);

                        foreach (var item in dbtexts)
                        {
                            await databaseFixture.Db.WxTextResponse.DeleteAsync(item, tran);
                        }
                        foreach (var item in model.ResponseText)
                        {
                            WxTextResponse textResponse = new WxTextResponse
                            {
                                Content = item,
                                RuleId  = dbrule.Id
                            };
                            await databaseFixture.Db.WxTextResponse.InsertAsync(textResponse, tran);
                        }
                        break;

                    case ResponseMsgType.Image:
                        break;

                    case ResponseMsgType.Voice:
                        break;

                    case ResponseMsgType.Video:
                        break;

                    case ResponseMsgType.Music:
                        break;

                    case ResponseMsgType.News:
                        break;

                    case ResponseMsgType.Transfer_Customer_Service:
                        break;

                    default:
                        break;
                    }

                    tran.Commit();
                    return(true);
                }
                catch (System.Exception ex)
                {
                    tran.Rollback();
                    return(false);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// 规则新增
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <bool> AddAsync(RuleReplyDto model)
        {
            using (var tran = databaseFixture.Db.BeginTransaction())
            {
                try
                {
                    WxRule rule = new WxRule
                    {
                        RuleName        = model.RuleName,
                        RuleType        = model.RuleType,
                        ResponseMsgType = model.ResponseMsgType
                    };
                    switch ((WxRuleType)model.RuleType)
                    {
                    case WxRuleType.Normal:
                        rule.RequestMsgType = (int)RequestMsgType.Text;
                        break;

                    case WxRuleType.Subscribe:
                        rule.RequestMsgType = (int)RequestMsgType.Event;
                        break;

                    case WxRuleType.Unmatched:
                        rule.RequestMsgType = model.RequestMsgType;
                        break;
                    }
                    int ruleid = await databaseFixture.Db.WxRule.InsertReturnIdAsync(rule, tran);

                    switch ((RequestMsgType)rule.RequestMsgType)
                    {
                    case RequestMsgType.Text:    //关键字请求
                        foreach (var item in model.Keywords)
                        {
                            WxKeyword keyword = new WxKeyword
                            {
                                Keyword = item,
                                RuleId  = ruleid
                            };
                            await databaseFixture.Db.WxKeyword.InsertAsync(keyword, tran);
                        }
                        break;

                    case RequestMsgType.Image:
                        break;

                    case RequestMsgType.Voice:
                        break;

                    case RequestMsgType.Video:
                        break;

                    case RequestMsgType.Location:
                        break;

                    case RequestMsgType.Link:
                        break;

                    case RequestMsgType.ShortVideo:
                        break;

                    case RequestMsgType.Event:
                        break;

                    default:
                        break;
                    }

                    switch ((ResponseMsgType)model.ResponseMsgType)
                    {
                    case ResponseMsgType.Text:
                        foreach (var item in model.ResponseText)
                        {
                            WxTextResponse textResponse = new WxTextResponse
                            {
                                Content = item,
                                RuleId  = ruleid
                            };
                            await databaseFixture.Db.WxTextResponse.InsertAsync(textResponse, tran);
                        }
                        break;

                    case ResponseMsgType.Image:
                        break;

                    case ResponseMsgType.Voice:
                        break;

                    case ResponseMsgType.Video:
                        break;

                    case ResponseMsgType.Music:
                        break;

                    case ResponseMsgType.News:
                        break;

                    case ResponseMsgType.Transfer_Customer_Service:
                        break;

                    default:
                        break;
                    }

                    tran.Commit();
                    return(true);
                }
                catch (System.Exception ex)
                {
                    tran.Rollback();
                    return(false);
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// 获取规则回复明细
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <RuleReplyDto> GetRuleReplyAsync(int id)
        {
            var dbrule = await databaseFixture.Db.WxRule.FindByIdAsync(id);

            RuleReplyDto model = new RuleReplyDto()
            {
                Id              = dbrule.Id,
                RuleName        = dbrule.RuleName,
                RuleType        = dbrule.RuleType,
                RequestMsgType  = dbrule.RequestMsgType,
                ResponseMsgType = dbrule.ResponseMsgType
            };

            switch ((RequestMsgType)dbrule.RequestMsgType)
            {
            case RequestMsgType.Text:
                var dbkeywords = await databaseFixture.Db.WxKeyword.FindAllAsync(m => m.RuleId == dbrule.Id);

                model.Keywords = dbkeywords.Select(m => m.Keyword).ToList();
                break;

            case RequestMsgType.Image:
                break;

            case RequestMsgType.Voice:
                break;

            case RequestMsgType.Video:
                break;

            case RequestMsgType.Location:
                break;

            case RequestMsgType.Link:
                break;

            case RequestMsgType.ShortVideo:
                break;

            case RequestMsgType.Event:
                break;

            default:
                break;
            }
            switch ((ResponseMsgType)dbrule.ResponseMsgType)
            {
            case ResponseMsgType.Text:
                var dbtexts = await databaseFixture.Db.WxTextResponse.FindAllAsync(m => m.RuleId == dbrule.Id);

                model.ResponseText = dbtexts.Select(m => m.Content).ToList();
                break;

            case ResponseMsgType.Image:
                break;

            case ResponseMsgType.Voice:
                break;

            case ResponseMsgType.Video:
                break;

            case ResponseMsgType.Music:
                break;

            case ResponseMsgType.News:
                break;

            case ResponseMsgType.Transfer_Customer_Service:
                break;

            default:
                break;
            }
            return(model);
        }
コード例 #6
0
 public async Task <bool> UpdateAsync([FromBody] RuleReplyDto model)
 {
     return(await wxRuleService.UpdateAsync(model));
 }