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);
 }
 private object[] Take(LockEntity entity)
 {
     return(new object[]
     {
         @"Content", entity.Content,
         @"LockDate", entity.LockDate,
         @"IsLock", entity.IsLock
     });
 }
 public static LockOutDto EntityToOutDto(LockEntity lockEntity)
 {
     return(lockEntity != null
         ? new LockOutDto()
     {
         LockedBy = lockEntity.LockedBy,
         IsLocked = lockEntity.IsLocked
     }
         : null);
 }
        public string ExcuteUnLock(LockEntity entity)
        {
            const string sql = @"uspExcute_Lock";

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