本文整理汇总了C#中System.Factory.Put方法的典型用法代码示例。如果您正苦于以下问题:C# Factory.Put方法的具体用法?C# Factory.Put怎么用?C# Factory.Put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Factory
的用法示例。
在下文中一共展示了Factory.Put方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Put
public static Response<Asiento> Put(this Asiento request,
Factory factory,
IRequestContext requestContext,
bool checkSucursal=true,
bool checkPeriodo=false,
Action<IDbCommand,Asiento> runBeforePutDbCommandsFn=null,
Action<IDbCommand,Asiento> runAfterPutDbCommandsFn=null)
{
request.CheckId(Operaciones.Update);
string lockKey=request.GetLockKey();
var httpRequest = requestContext.Get<IHttpRequest>();
Action block=()=>{
SqlExpressionVisitor<Asiento> ev = OrmLiteConfig.DialectProvider.ExpressionVisitor<Asiento>();
ev.Update( f=> new { f.Descripcion, f.Fecha , f.Periodo, f.IdSucursal, f.CodigoDocumento, f.Documento })
.Where(f=>f.Id==request.Id);
var cacheKey=request.GetCacheKey();
factory.Put(request, ev,
(dbCmd)=>
{
httpRequest.CacheClientExec(cache=>
{
var data=cache.Get<Asiento>(cacheKey);
if(data== default(Asiento))
{
data= dbCmd.FirstOrDefault<Asiento>(q=> q.Id==request.Id);
AssertExists(data, request.Id);
}
if(!request.CodigoDocumento.IsNullOrEmpty() )
data.CodigoDocumento=request.CodigoDocumento;
if(!request.Documento.IsNullOrEmpty())
data.Documento=request.Documento;
data.ValidateAndThrowHttpError(Operaciones.Update,httpRequest, factory);
if(request.IdSucursal!=default(int))
{
data.IdSucursal= request.IdSucursal;
}
if(request.Fecha!=default(DateTime))
{
data.Fecha= request.Fecha;
data.Periodo= data.Fecha.ObtenerPeriodo();
}
if(checkSucursal) data.CheckSucursal(factory, httpRequest);
if(checkPeriodo) data.CheckPeriodo(factory,httpRequest);
if(!request.Descripcion.IsNullOrEmpty()) data.Descripcion=request.Descripcion;
request.PopulateWith(data);
if(runBeforePutDbCommandsFn!=null) runBeforePutDbCommandsFn(dbCmd,request);
});
},
(dbCmd)=>
{
if(runAfterPutDbCommandsFn!=null) runAfterPutDbCommandsFn(dbCmd, request);
httpRequest.CacheClientExec(cache=> cache.Set(cacheKey, request,
TimeSpan.FromDays(Definiciones.DiasEnCache)));
});
};
IRedisClientsManager cm = httpRequest.GetCacheClient() as IRedisClientsManager;
try
{
if( cm != null)
{
cm.Exec(redisClient=>
{
using (redisClient.AcquireLock(lockKey, TimeSpan.FromSeconds(Definiciones.LockSeconds)))
{
block();
}
});
}
else
block();
List<Asiento> data = new List<Asiento>();
data.Add(request);
return new Response<Asiento>(){Data=data};
}
catch(Exception e)
{
throw new HttpError(e.Message);
}
}