Пример #1
0
        // 實現onCreateNewPost
        public override Task <CreateNewPostResult> CreateNewPostFun(NewPostInfo request, ServerCallContext context)
        {
            CreateNewPostResult ret = new CreateNewPostResult();

            ret.Result = 0;

            try
            {
                CreateNewPost rData = new CreateNewPost
                {
                    MemberID = request.MemberID,

                    Photo = request.Photo,

                    Content = request.Content
                };

                string sData = JsonConvert.SerializeObject(rData);

                JObject jsMain = new JObject();

                jsMain.Add("CmdID", (int)C2S_CmdID.emCreateNewPost);
                jsMain.Add("Data", JsonConvert.DeserializeObject <JObject>(sData));

                MsgInfo info = new MsgInfo(jsMain.ToString(), this.SendToClient);

                this.addQueue?.Invoke(info);

                ret.Result = 1;
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{ex.Message}");

                SaveLog($"[Error] gRpcImpl::CreateNewPostFun, Catch Error, Msg:{ex.Message}");
            }

            return(Task.FromResult(ret));
        }
Пример #2
0
        public async Task <ActionResult> PulishNewPostAsync([FromForm] NewPostInfo model)
        {
            if (string.IsNullOrWhiteSpace(model.Author))
            {
                model.Author = "匿名";
            }
            if (string.IsNullOrWhiteSpace(model.Description))
            {
                model.Description = "";
            }

            bool   suc;
            string msg;

            Domain.Posts.PostsService post = new Domain.Posts.PostsService();
            (suc, msg) = await post.PulishNewPostAsync(model);

            if (suc)
            {
                return(Ok(Result("成功")));
            }
            return(Accepted(Result(msg)));
        }