Returns the class encapsulates .NetWebApi

Returns the class defined ReturnMsg:

public class ReturnMsg
{
    /// <summary>
    /// 成功构造函数
    /// </summary>
    /// <param name="ReBody">实体类或者实体类集合都可以</param>
    public ReturnMsg(object ReBody)
    {
        Status = ReStatus.Success.ToString();
        Body = ReBody;
    }

    /// <summary>
    /// 失败构造函数
    /// </summary>
    /// <param name="ex"></param>
    public ReturnMsg(Exception ex)
    {
        Error = ex.Message;
        Status = ReStatus.Fail.ToString();
    }
    public string Error { get; set; }
    public string Status { get; set; }
    public object Body { get; set; }

}
enum ReStatus
{
    Fail = 0,
    Success = 1
}

Call, return type is ReturnMsg, the success of the New ReturnMsg (object), the failure of the New ReturnMsg (Exception)

        [HttpPost]
        public ReturnMsg Post(coreUser coreuser)
        {
            try
            {
                using (TransactionScope trans = new TransactionScope())
                {
                    trans.Complete();
                    return new ReturnMsg(coreuser);
                }
            }
            catch (Exception ex)
            {
                return new ReturnMsg(ex);
            }

        }
Published 23 original articles · won praise 3 · Views 5203

Guess you like

Origin blog.csdn.net/qq_20662097/article/details/104711712
Recommended