123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- using Microsoft.AspNetCore.Mvc;
- using ERP.Framework.Constants;
- namespace ERP.Framework.WebApi
- {
- [ApiController]
- public class BaseController : ControllerBase
- {
-
-
-
-
- protected IActionResult Success()
- {
- return new JsonResult(new
- {
- code = ReponseCode.Success,
- message = "Success",
- });
- }
-
-
-
-
-
- protected IActionResult Success(string message)
- {
- return new JsonResult(new
- {
- code = ReponseCode.Success,
- message
- });
- }
-
-
-
-
-
-
- protected IActionResult Success<T>(T data)
- {
- return new JsonResult(new
- {
- code = ReponseCode.Success,
- data,
- message = "Success"
- });
- }
-
-
-
-
-
-
-
- protected IActionResult Success<T>(string message, T data)
- {
- return new JsonResult(new
- {
- code = ReponseCode.Success,
- data,
- message
- });
- }
-
-
-
-
- protected IActionResult Error()
- {
- return new BadRequestObjectResult(new
- {
- code = ReponseCode.Error,
- message = "Failed"
- });
- }
- protected IActionResult Error(string message)
- {
- return new BadRequestObjectResult(new
- {
- code = ReponseCode.Error,
- message
- });
- }
- protected IActionResult Error(int code, string message)
- {
- return new BadRequestObjectResult(new
- {
- code,
- message
- });
- }
- protected IActionResult Error<T>(T data)
- {
- return new BadRequestObjectResult(new
- {
- code = ReponseCode.Error,
- data,
- message = "Failed"
- });
- }
- protected IActionResult Error<T>(string message, T data)
- {
- return new BadRequestObjectResult(new
- {
- code = ReponseCode.Error,
- data,
- message
- });
- }
-
-
-
-
- protected IActionResult Result(bool isSuccess)
- {
- if (isSuccess)
- {
- return Success();
- }
- else
- {
- return Error();
- }
- }
- protected IActionResult Result<T>(int code, string message, T data)
- {
- return new BadRequestObjectResult(new
- {
- code,
- data,
- message
- });
- }
- protected IActionResult BadResult<T>(int httpErrorCode, int code, T data, string message)
- {
- var result = new BadRequestObjectResult(new
- {
- code,
- data,
- message
- });
- result.StatusCode = httpErrorCode;
- return result;
- }
-
-
-
-
-
-
-
-
-
-
-
-
- }
- }
|