v1.1.3
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
using CC.Yi.IBLL;
|
using CC.Yi.Common;
|
||||||
|
using CC.Yi.IBLL;
|
||||||
using CC.Yi.Model;
|
using CC.Yi.Model;
|
||||||
using Common;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|||||||
@@ -3,37 +3,37 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
|
|
||||||
namespace Common
|
namespace CC.Yi.Common
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 结果数据
|
/// 结果数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Result
|
public class Result
|
||||||
{
|
{
|
||||||
public bool Status { get; set; }
|
public bool status { get; set; }
|
||||||
public int Code { get; set; }
|
public int code { get; set; }
|
||||||
public string Msg { get; set; }
|
public string msg { get; set; }
|
||||||
public object Data { get; set; }
|
public object data { get; set; }
|
||||||
public static Result Instance(bool status, string msg)
|
public static Result Instance(bool status, string msg)
|
||||||
{
|
{
|
||||||
return new Result() { Status = status,Code=500, Msg = msg };
|
return new Result() { status = status, code = 500, msg = msg };
|
||||||
}
|
}
|
||||||
public static Result Error(string msg)
|
public static Result Error(string msg = "fail")
|
||||||
{
|
{
|
||||||
return new Result() { Status = false, Code = 500, Msg = msg };
|
return new Result() { status = false, code = 500, msg = msg };
|
||||||
}
|
}
|
||||||
public static Result Success(string msg= "succeed")
|
public static Result Success(string msg = "succeed")
|
||||||
{
|
{
|
||||||
return new Result() { Status = true, Code = 200, Msg = msg };
|
return new Result() { status = true, code = 200, msg = msg };
|
||||||
}
|
}
|
||||||
public Result SetData(object obj)
|
public Result SetData(object obj)
|
||||||
{
|
{
|
||||||
this.Data = obj;
|
this.data = obj;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public Result SetCode(int Code)
|
public Result SetCode(int Code)
|
||||||
{
|
{
|
||||||
this.Code = Code;
|
this.code = Code;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ namespace CC.Yi.DAL
|
|||||||
Webcontext = webContext;
|
Webcontext = webContext;
|
||||||
}
|
}
|
||||||
public static DataContext GetCurrentDbContent()
|
public static DataContext GetCurrentDbContent()
|
||||||
|
{
|
||||||
|
object myLock = new object();
|
||||||
|
lock (myLock)
|
||||||
{
|
{
|
||||||
//return new DataModelContainer();
|
//return new DataModelContainer();
|
||||||
//一次请求共用一个上下文实例
|
//一次请求共用一个上下文实例
|
||||||
@@ -23,13 +26,18 @@ namespace CC.Yi.DAL
|
|||||||
//CallContext:是线程内部唯一的数据槽(一块内存空间/容器),相当于一个键值对数据容器,通过key获取value了,需要引入System.Runtime.Remoting.Messaging;命名空间
|
//CallContext:是线程内部唯一的数据槽(一块内存空间/容器),相当于一个键值对数据容器,通过key获取value了,需要引入System.Runtime.Remoting.Messaging;命名空间
|
||||||
DataContext db = CallContext.GetData("DbContext") as DataContext;
|
DataContext db = CallContext.GetData("DbContext") as DataContext;
|
||||||
//从 CallContext 中检索具有指定key“DbContext”的对象,并强转为DbContext
|
//从 CallContext 中检索具有指定key“DbContext”的对象,并强转为DbContext
|
||||||
|
|
||||||
if (db == null)//线程在数据槽里面没有此上下文
|
if (db == null)//线程在数据槽里面没有此上下文
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
db = Webcontext;
|
db = Webcontext;
|
||||||
CallContext.SetData("DbContext", db);//放到数据槽中去,DbContext是key,db是value
|
CallContext.SetData("DbContext", db);//放到数据槽中去,DbContext是key,db是value
|
||||||
}
|
}
|
||||||
|
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class CallContext
|
private static class CallContext
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user