using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Configuration; using System.Diagnostics; using System.IO; using System.Linq; using System.Net.Http; using System.Text; using System.Threading.Tasks; using System.Web; using System.Web.Http; namespace XdCxRhDW.WebApi.Controllers { /// /// /// [RoutePrefix("")] public class BaseController : ApiController { private readonly string uploadFolder; /// /// /// public BaseController() { this.uploadFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot"); } /// /// 返回本地文件 /// /// /// protected string GetLocalFile(string fileName) { return Path.Combine(this.uploadFolder, fileName); } /// /// 返回成功 /// /// 返回的数据 /// protected AjaxResult Success(object data = null) { AjaxResult res = new AjaxResult { code = 200, msg = "请求成功!", data = data }; return res; } /// /// 返回成功 /// /// 返回的消息 /// 返回的数据 /// protected AjaxResult Success(object data, string msg = "请求成功!") { AjaxResult res = new AjaxResult { code = 200, msg = msg, data = data }; return res; } /// /// 返回成功 /// /// 返回的消息 /// 返回的数据 /// protected AjaxResult Success(T data, string msg = "请求成功!") { AjaxResult res = new AjaxResult { code = 200, msg = msg, data = data }; return res; } /// /// 返回错误 /// /// 错误提示 /// protected AjaxResult Error(string msg) { AjaxResult res = new AjaxResult { code = 0, msg = msg, data = null }; return res; } /// /// 返回错误 /// /// 错误提示 /// protected AjaxResult Error(string msg) { AjaxResult res = new AjaxResult { code = 0, msg = msg, data = default }; return res; } } }