Core常⽤的接⼝⼊⼝参数、出⼝参数常⽤的传⼊参数、传出参数格式
public class ParamBox
{
public ParamBox(UniContext uniContext, CurrentUser currentUser, List<int?> permissionsList)
{
UniContext = uniContext;
CurrentUser = currentUser;
PermissionsList = permissionsList;
}
public object Data { get; set; }
public UniContext UniContext { get; set; }
public CurrentUser CurrentUser { get; set; }
public List<int?> PermissionsList { get; set; }
}
public class UniContext
{
public IPAddress iPAddress { get; set; }
public string Referer { get; set; }
public string AccessToken { get; set; }
}
public class CurrentUser
{
public int Id { get; set; }
public string Name { get; set; }
public string UserName { get; set; }
public string Email { get; set; }
public string Grouping { get; set; }
public List<int> Role { get; set; }
public string NickName { get; set; }
}
public enum UniStatusCode
{
Success = 200,
Error = 400,
TokenExpired = 514
}
public class ReturnBox
{
public int Code { get; set; } = 0;
public object Data { get; set; }
public string Message { get; set; } = string.Empty;
public string Meta { get; set; } = string.Empty;
public int PageIndex { get; set; } = 0;
public int PageSize { get; set; } = 0;
public long TotalCount { get; set; } = 0;
}
public class BaseSvrAction
{
///<summary>
/// Return obj
///</summary>
///<param name="data"></param>
///<param name="msg"></param>
///<param name="statusCode"></param>
///<returns></returns>
protected ReturnBox UniData(object data, string msg = "", UniStatusCode statusCode = UniStatusCode.Success)
{
if (data == null)
throw new ArgumentException("Data is null");
var result = new ReturnBox()
{
Message = msg,
Data = data,
Code = (int)statusCode
};
return result;
}
///<summary>
/// Return message
///</summary>
///<param name="msg"></param>
///<param name="meta"></param>
///<param name="statusCode"></param>
///<returns></returns>
protected ReturnBox UniMessage(string msg, string meta = "", UniStatusCode statusCode = UniStatusCode.Success) {
var result = new ReturnBox
{
Message = msg,
Meta = meta,
Code = (int)statusCode
};
return result;
}
///<summary>
/// Return page list
///</summary>
///<param name="data"></param>
///<param name="pageIndex"></param>
/
//<param name="pageSize"></param>
///<param name="totalCount"></param>
///<param name="statusCode"></param>
///<returns></returns>
protected ReturnBox UniPagedBox(object data,
int pageIndex = 0,
int pageSize = 0,
long totalCount = 0,
string msg = "",
UniStatusCode statusCode = UniStatusCode.Success)
{
if (data == null)
throw new ArgumentException("Parameter is null");
var result = new ReturnBox
{
Data = data,
PageIndex = pageIndex,
PageSize = pageSize,
TotalCount = totalCount,
Message = msg,
Code = (int)statusCode
};
return result;
}
///<summary>
/// Return status,Success or Failed
///</summary>
///<param name="isSuccess">True or False</param>
///<param name="msg"></param>
///<returns></returns>
protected ReturnBox UniStatus(bool isSuccess, string msg = "")
{
msg = isSuccess ? (string.IsNullOrEmpty(msg) ? "Success" : msg) : (string.IsNullOrEmpty(msg) ? "Failed" : msg);
if (isSuccess) return UniMessage("Success");
return UniError();
}
///<summary>
/// Return success
///</summary>
///<param name="msg"></param>
///<param name="statusCode"></param>
///<returns></returns>
protected ReturnBox UniSuccess(string msg = "", UniStatusCode statusCode = UniStatusCode.Success)
{
return UniMessage(string.IsNullOrEmpty(msg) ? "Success" : msg, "", statusCode);
}
///<summary>
/// Return error message
///</summary>
///<param name="msg"></param>
///<param name="statusCode"></param>
///<returns></returns>
protected ReturnBox UniError(string msg = "", UniStatusCode statusCode = UniStatusCode.Error)
{
return UniMessage(string.IsNullOrEmpty(msg) ? "Failed" : msg, "", statusCode);
}
///<summary>
/// Convert Object to Model
///</summary>
///<typeparam name="T"></typeparam>
///<param name="obj"></param>
///<returns></returns>
protected T ConvertObjToModel<T>(object obj)
{
return JsonConvert.DeserializeObject<T>(obj.ToString());
}
/
//<summary>
///时间戳转为C#格式时间
///</summary>
///<param name="time"></param>
///<returns></returns>
private DateTime StampToDateTime(string time)
{
time = time.Substring(0, 10);
double timestamp = Convert.ToInt64(time);
System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0); dateTime = dateTime.AddSeconds(timestamp).ToLocalTime();
return dateTime;
}
///<summary>param name
///获取时间戳
///</summary>
///<returns></returns>
public static long GetTimeStamp()
{
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
return Convert.ToInt64(ts.TotalMilliseconds);
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论