You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
3.6 KiB
C#

using Admin.Core.Model;
using Admin.Core.Common;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
namespace Admin.Core.Api
{
/// <summary>
/// BaseApiCpntroller
/// </summary>
public class BaseApiController : Controller
{
/// <summary>
/// Success
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="data"></param>
/// <param name="msg"></param>
/// <returns></returns>
[NonAction]
public MessageModel<T> Success<T>(T data, string msg = "成功")
{
return new MessageModel<T>()
{
success = true,
msg = msg,
data = data,
};
}
/// <summary>
/// Success
/// </summary>
/// <param name="msg"></param>
/// <returns></returns>
[NonAction]
public MessageModel Success(string msg = "成功")
{
return new MessageModel()
{
success = true,
msg = msg,
data = null,
};
}
/// <summary>
/// Failed
/// </summary>
/// <param name="msg"></param>
/// <param name="status"></param>
/// <returns></returns>
[NonAction]
public MessageModel<string> Failed(string msg = "失败", int status = 500)
{
return new MessageModel<string>()
{
success = false,
status = status,
msg = msg,
data = null,
};
}
/// <summary>
/// Failed
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="msg"></param>
/// <param name="status"></param>
/// <returns></returns>
[NonAction]
public MessageModel<T> Failed<T>(string msg = "失败", int status = 500)
{
return new MessageModel<T>()
{
success = false,
status = status,
msg = msg,
data = default,
};
}
/// <summary>
/// SuccessPage
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="page"></param>
/// <param name="dataCount"></param>
/// <param name="pageSize"></param>
/// <param name="data"></param>
/// <param name="msg"></param>
/// <returns></returns>
[NonAction]
public MessageModel<PageModel<T>> SuccessPage<T>(int page, int dataCount, int pageSize, List<T> data, string msg = "获取成功")
{
return new MessageModel<PageModel<T>>()
{
success = true,
msg = msg,
data = new PageModel<T>()
{
page = page,
dataCount = dataCount,
data = data,
pageSize = pageSize
}
};
}
/// <summary>
/// SuccessPage
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="pageModel"></param>
/// <param name="msg"></param>
/// <returns></returns>
[NonAction]
public MessageModel<PageModel<T>> SuccessPage<T>(PageModel<T> pageModel, string msg = "获取成功")
{
return new MessageModel<PageModel<T>>()
{
success = true,
msg = msg,
data = pageModel
};
}
}
}