using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using Newtonsoft.Json;
using COMCMS.Common;
using System.Text;
using System.IO;
namespace COMCMS.Core
{
///
/// 系统JSON提示实体类
///
[Serializable]
public class JsonTip
{
public JsonTip() { }
///
/// 成功状态
///
public static readonly string SUCCESS = "success";
///
/// 失败状态
///
public static readonly string ERROR = "error";
///
/// 请求返回状态 默认 error(错误);成功:success
///
public string Status { get; set; } = ERROR;
///
/// 提示信息
///
public string Message { get; set; }
///
/// 其他信息
///
public string Other { get; set; }
///
/// Id 可选
///
public int Id { get; set; } = 0;
///
/// 返回URL
///
public string ReturnUrl { get; set; }
///
/// 获取JSON字符串
///
/// JsonTip实体类
///
public static string GetJsonString(JsonTip json)
{
if (json != null)
return JsonConvert.SerializeObject(json);
else
return string.Empty;
}
}
public static class Extension
{
public static void EchoTip(this JsonTip json)
{
string strJson = JsonTip.GetJsonString(json);
Byte[] bytes = Encoding.UTF8.GetBytes(strJson);
Stream stream = new MemoryStream(bytes);
MyHttpContext.Current.Response.ContentType = "text/plain";
MyHttpContext.Current.Response.Body = stream;
}
}
}