BllResult.cs 3.1 KB
using System;

namespace RCS.Model.Comm
{
    public class BllResult<T>
    {
        public BllResult(bool success, string msg, T data)
        {
            code = 200;
            if (success)
            {
                code = 200;
            }
            else
            {
                code = 400;
            }
            IsSuccess = success;
            Message = msg;
            Data = data;
        }

        public int code { get; set; }
        public bool IsSuccess { get; set; }
        public string Message { get; set; }
        public T Data { get; set; }

        public static BllResult<T> Success(T data, string msg)
        {
            return new BllResult<T>(true, msg, data);
        }

        public static BllResult<T> Success(T data)
        {
            return new BllResult<T>(true, "", data);
        }

        public static BllResult<T> Success(string msg)
        {
            return new BllResult<T>(true, msg, default);
        }

        public static BllResult<T> Success()
        {
            return new BllResult<T>(true, "", default);
        }

        public static BllResult<T> Error(T data, string msg)
        {
            return new BllResult<T>(false, msg, data);
        }

        public static BllResult<T> Error(T data)
        {
            return new BllResult<T>(false, "", data);
        }

        public static BllResult<T> Error(string msg)
        {
            return new BllResult<T>(false, msg, default);
        }

        public static BllResult<T> Error()
        {
            return new BllResult<T>(false, "", default);
        }
    }

    public class BllResult
    {
        public BllResult(bool success, string msg, object data)
        {
            code = 200;
            if (success)
            {
                code = 200;
            }
            else
            {
                code = 400;
            }

            IsSuccess = success;
            Message = msg;
            Data = data;
        }
        public int code { get; set; }
        public bool IsSuccess { get; set; }
        public string Message { get; set; }
        public object Data { get; set; }

        public static BllResult Success(object data, string msg)
        {
            return new BllResult(true, msg, data);
        }

        public static BllResult Success(object data)
        {
            return new BllResult(true, "", data);
        }

        public static BllResult Success(string msg)
        {
            return new BllResult(true, msg, null);
        }

        public static BllResult Success()
        {
            return new BllResult(true, "", null);
        }

        public static BllResult Error(object data, string msg)
        {
            return new BllResult(false, msg, data);
        }

        public static BllResult Error(object data)
        {
            return new BllResult(false, "", data);
        }

        public static BllResult Error(string msg)
        {
            return new BllResult(false, msg, null);
        }

        public static BllResult Error()
        {
            return new BllResult(false, "", null);
        }
    }
}