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); } }