forked from anjoy8/Blog.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseApiController.cs
More file actions
85 lines (81 loc) · 2.37 KB
/
BaseApiController.cs
File metadata and controls
85 lines (81 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using Blog.Core.Model;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
namespace Blog.Core.Controllers
{
public class BaseApiController : Controller
{
[NonAction]
public MessageModel<T> Success<T>(T data, string msg = "成功")
{
return new MessageModel<T>()
{
success = true,
msg = msg,
response = data,
};
}
// [NonAction]
//public MessageModel<T> Success<T>(T data, string msg = "成功",bool success = true)
//{
// return new MessageModel<T>()
// {
// success = success,
// msg = msg,
// response = data,
// };
//}
[NonAction]
public MessageModel Success(string msg = "成功")
{
return new MessageModel()
{
success = true,
msg = msg,
response = null,
};
}
[NonAction]
public MessageModel<string> Failed(string msg = "失败", int status = 500)
{
return new MessageModel<string>()
{
success = false,
status = status,
msg = msg,
response = null,
};
}
[NonAction]
public MessageModel<T> Failed<T>(string msg = "失败", int status = 500)
{
return new MessageModel<T>()
{
success = false,
status = status,
msg = msg,
response = default,
};
}
[NonAction]
public MessageModel<PageModel<T>> SuccessPage<T>(int page, int dataCount, int pageSize, List<T> data, int pageCount, string msg = "获取成功")
{
return new MessageModel<PageModel<T>>()
{
success = true,
msg = msg,
response = new PageModel<T>(page, dataCount, pageSize, data)
};
}
[NonAction]
public MessageModel<PageModel<T>> SuccessPage<T>(PageModel<T> pageModel, string msg = "获取成功")
{
return new MessageModel<PageModel<T>>()
{
success = true,
msg = msg,
response = pageModel
};
}
}
}