Esempio n. 1
0
        public async Task <PartialViewResult> CreateOrEditModal(int id)
        {
            if (id != 0)
            {
                var output = await _mpSelfArticleAppService.Get(new EntityDto <int>(id));

                var viewModel = new CreateOrEditMpSelfArticleViewModel(output);
                return(PartialView("_CreateOrEditModal", viewModel));
            }
            else
            {
                var mpID = await _userMpAppService.GetDefaultMpId();

                var model = new CreateOrEditMpSelfArticleViewModel()
                {
                    MpID = mpID
                };
                return(PartialView("_CreateOrEditModal", model));
            }
        }
        /// <summary>
        /// 获取实体中的回复
        /// </summary>
        /// <param name="type"></param>
        /// <param name="imageMediaID"></param>
        /// <param name="content"></param>
        /// <param name="voiceMediaID"></param>
        /// <param name="videoID"></param>
        /// <param name="articleID"></param>
        /// <param name="articleGroupID"></param>
        /// <returns></returns>
        private async Task <IResponseMessageBase> GetEntityResponse(string type, string imageMediaID, string content, string voiceMediaID, string videoID, string articleID, string articleGroupID, RequestMessageText requestMessage = null)
        {
            if (type == ReplyMsgType.kf.ToString())
            {
                #region 春雨医生逻辑处理
                var chunyuHandler = _iocResolver.Resolve <IChunYuMessageHandler>();
                //如果春雨医生未结束,先引导用户主动关闭春雨医生会话
                if (await chunyuHandler.IsAsking(mpId, requestMessage.FromUserName))
                {
                    return(await chunyuHandler.CustomerNotice(mpId, requestMessage));
                }
                #endregion

                #region 客服逻辑处理
                var kefuMessageHandler = _iocResolver.Resolve <IKeFuMessageHandler>();
                return(await kefuMessageHandler.InCustomer(mpId, requestMessage));

                #endregion
            }
            else if (type == ReplyMsgType.doctor.ToString())
            {
                #region 客服逻辑处理
                var kefuMessageHandler = _iocResolver.Resolve <IKeFuMessageHandler>();
                if (await kefuMessageHandler.IsAsking(mpId, requestMessage.FromUserName))
                {
                    return(await kefuMessageHandler.ChunYuNotice(mpId, requestMessage));
                }
                #endregion

                #region 春雨医生逻辑处理
                var chunyuHandler = _iocResolver.Resolve <IChunYuMessageHandler>();
                return(await chunyuHandler.CreateProblem(mpId, requestMessage));

                #endregion
            }
            else if (type == ReplyMsgType.none.ToString())
            {
                return(base.CreateResponseMessage <ResponseMessageNoResponse>());
            }
            else if (type == ReplyMsgType.image.ToString())
            {
                var responseMessage = base.CreateResponseMessage <ResponseMessageImage>();
                responseMessage.Image.MediaId = imageMediaID;
                return(responseMessage);
            }
            else if (type == ReplyMsgType.text.ToString())
            {
                var responseMessage = base.CreateResponseMessage <ResponseMessageText>();
                responseMessage.Content = content;
                return(responseMessage);
            }
            else if (type == ReplyMsgType.voice.ToString())
            {
                var responseMessage = base.CreateResponseMessage <ResponseMessageVoice>();
                responseMessage.Voice.MediaId = voiceMediaID;
                return(responseMessage);
            }
            else if (type == ReplyMsgType.video.ToString())
            {
                var responseMessage = base.CreateResponseMessage <ResponseMessageVideo>();
                int vedioId         = 0;
                int.TryParse(videoID, out vedioId);
                var video = await _mpMediaVideoAppService.Get(new EntityDto <int> {
                    Id = vedioId
                });

                if (video != null)
                {
                    responseMessage.Video.MediaId     = video.MediaID;
                    responseMessage.Video.Title       = video.Title;
                    responseMessage.Video.Description = video.Description;
                    return(responseMessage);
                }
                else
                {
                    return(base.CreateResponseMessage <ResponseMessageNoResponse>());
                }
            }
            else if (type == ReplyMsgType.mpnews.ToString())
            {
                var responseMessage = base.CreateResponseMessage <ResponseMessageNews>();
                int articleId       = 0;
                int.TryParse(articleID, out articleId);
                var article = await _mpSelfArticleAppService.Get(new EntityDto <int> {
                    Id = articleId
                });

                if (article != null)
                {
                    responseMessage.Articles.Add(new Article()
                    {
                        Title       = article.Title,
                        Description = article.Description,
                        Url         = article.AUrl,
                        PicUrl      = article.FilePathOrUrl
                    });
                    return(responseMessage);
                }
                else
                {
                    return(base.CreateResponseMessage <ResponseMessageNoResponse>());
                }
            }
            else if (type == ReplyMsgType.mpmultinews.ToString())
            {
                var responseMessage = base.CreateResponseMessage <ResponseMessageNews>();
                int articleGroupId  = 0;
                int.TryParse(articleGroupID, out articleGroupId);
                var groupItems = await _mpSelfArticleGroupItemAppService.GetGroupItems(articleGroupId);

                if (!(groupItems == null || groupItems.Count() < 2))
                {
                    var articleIds = groupItems.Select(m => m.ArticleID).ToList();
                    var articles   = await _mpSelfArticleAppService.GetListByIds(articleIds);

                    foreach (var id in articleIds)
                    {
                        var item = articles.Where(m => m.Id == id).FirstOrDefault();
                        responseMessage.Articles.Add(new Article()
                        {
                            Title       = item.Title,
                            Description = item.Description,
                            Url         = item.AUrl,
                            PicUrl      = item.FilePathOrUrl
                        });
                    }

                    return(responseMessage);
                }
                else
                {
                    return(base.CreateResponseMessage <ResponseMessageNoResponse>());
                }
            }
            else
            {
                return(null);
            }
        }