using CZFW.Framework.Model.ViewModel; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.IO; using System.Text; using CZFW.Core; using Microsoft.AspNetCore.Http; using Newtonsoft.Json; namespace CZFW.Framework { public class ControllerBase : Controller { public ResultModel Result(bool success = true, string message = null, object data = null, string code = null) { return new ResultModel(success, message, data, code); } public ResultModel Result(bool success = true, string message = null, TType Tdata = default(TType), string code = null, int affectedRows=0) { return new ResultModel(success, message, Tdata, code, affectedRows); } public string GetBodyJson() { if (!Request.Body.CanRead) return null; using (StreamReader reader = new StreamReader(Request.Body, true)) { var res = reader.ReadToEnd(); return res; } } public void WriteSession(string key, object value) { var json = value.ToJson(); HttpContext.Session.SetString(key, json); } public TResult GetSession(string key) { var json = HttpContext.Session.GetString(key); if (string.IsNullOrWhiteSpace(json)) return default(TResult); var res = JsonConvert.DeserializeObject(json); return res; } } }