public async Task RequestLock <T>(string entityId, string userId)
        {
            var entityLock = await GetValidLockEntity <T>(entityId, userId);

            if (entityLock == null)
            {
                entityLock = new LockEntity()
                {
                    EntityId     = entityId,
                    EntityName   = typeof(T).Name,
                    IsLocked     = true,
                    LastUserId   = userId,
                    LastLockTime = DateTime.UtcNow
                };

                db.Add(entityLock);
            }
            else
            {
                entityLock.IsLocked     = true;
                entityLock.LastUserId   = userId;
                entityLock.LastLockTime = DateTime.UtcNow;
            }

            await db.SaveChangesAsync();
        }
 private bool IsLockedToAnotherUser(string userId, LockEntity entityLock)
 {
     return(entityLock != null &&
            entityLock.IsLocked &&
            entityLock.LastUserId != userId &&
            entityLock.LastLockTime.AddMinutes(30) >= DateTime.UtcNow);
 }
Ejemplo n.º 3
0
 private object[] Take(LockEntity entity)
 {
     return(new object[]
     {
         @"Content", entity.Content,
         @"LockDate", entity.LockDate,
         @"IsLock", entity.IsLock
     });
 }
Ejemplo n.º 4
0
 public static LockOutDto EntityToOutDto(LockEntity lockEntity)
 {
     return(lockEntity != null
         ? new LockOutDto()
     {
         LockedBy = lockEntity.LockedBy,
         IsLocked = lockEntity.IsLocked
     }
         : null);
 }
Ejemplo n.º 5
0
        public string ExcuteUnLock(LockEntity entity)
        {
            const string sql = @"uspExcute_Lock";

            return(Db.Update(sql, true, Take(entity)));
        }