C#编写手机端接口返回Json 实例

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DTK.MIS.Common;
using DTK.MIS.Entities;
using System.IO;
using Newtonsoft.Json;
using DTK.MIS.BLL;


namespace DTKMIS.Api
{
    /// <summary>
    /// WorkflowCallbackHandler 在办事项收回
    /// </summary>
    public class WorkflowCallbackHandler : IHttpHandler
    {


        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";      
            ResultEntity entity = null;
            WorkFlowSqEntity workflow = new WorkFlowSqEntity();
            context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            using (var reader = new StreamReader(context.Request.InputStream))
            {
                String postJson = reader.ReadToEnd();
                entity = (ResultEntity)JsonConvert.DeserializeObject(postJson, typeof(ResultEntity));
            }
            //办理人编号
            int UserId = 0;
            //工作流编号
            int SqId = 0;
            // 工作节点顺序编号
            int OrderId = 0;
            if (context.Request.RequestType.ToLower() == "post")
            {
                if (entity == null)
                {
                    return;
                }
                UserId = entity.UserId;
                SqId = entity.SqId;
                OrderId = entity.OrderID;
            }
            SetParameter para = new SetParameter();
            para.state = 0;
            para.msg = "操作失败";
            //已处理的节点顺序
            int AreadyOrder = OrderId + 1;
            if (SqNodeBLL.DeleteBySqlIDAndOrderID(AreadyOrder, SqId))
            {
                if (SqNodeBLL.UpdateWhere(" NodeStatus=0", "SqID=" + SqId + " and OrderID=" + OrderId + ""))
                {
                    if (SqNodeBLL.UpdateWhere(" Status=2,SpDate='" + DateTime.Now + "'", "SqID=" + SqId + " and OrderID=" + OrderId + " and BlPerson=" + UserId + ""))
                    {
                        para.state = 1;
                        para.msg = "操作成功";
                    }
                    else
                    {
                        para.state = 0;
                        para.msg = "操作失败";
                    }
                }
            }
            string strJson = JsonConvert.SerializeObject(para);
            context.Response.Write(strJson);
        }


        /// <summary>
        /// POST请求参数
        /// </summary>
        public class ResultEntity
        {
            /// <summary>
            /// 办理人
            /// </summary>
            public int UserId { get; set; }
            /// <summary>
            /// 工作流编号
            /// </summary>
            public int SqId { get; set; }
            /// <summary>
            /// 流程节点顺序
            /// </summary>
            public int OrderID { get; set; }
        }




        public class SetParameter
        {
            public int state;
            public string msg;
        }


        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值