2017-07-26 10 views
0

ハードコードされた入力(ContactInterval)を変更して、ユーザーが入力する時間を選択できるようにする方法を検討しています。現在は20分に設定されています。 そしてContactIntervalハードEcho.Common.Services.LockManagerServicesにユーザー入力にハードコードされた値

public Echo.Common.Business.LockingManager.LockItem GetLock(Echo.Common.Business.LockingManager.LockItem.LockType lockType, int entityId, int userId, string userName, string phoneNumber) 
{ 
    Echo.Common.Business.LockingManager.LockItem theLock = new Echo.Common.Business.LockingManager.LockItem(); 

    try 
    { 
     Echo.Common.Services.LockManagerServices lockManagerServices = new Echo.Common.Services.LockManagerServices(); 
     Echo.Common.Services.LockItem returnedLock = lockManagerServices.GetLock((Echo.Common.Services.LockType)lockType, entityId, userId, userName, phoneNumber); 
     theLock.UserId = returnedLock.UserId; 
     theLock.UserName = returnedLock.UserName; 
     theLock.PhoneNumber = returnedLock.PhoneNumber; 
     theLock.ExpireSecs = returnedLock.ExpireSecs; 
     theLock.ContactInterval = returnedLock.ContactInterval; 
     int respondsID = (int)returnedLock.ResponseId; 
     theLock.ResponseId = (LockItem.LockResponse)respondsID; 
    } 
    catch 
    { 
     theLock.ResponseId = LockItem.LockResponse.ERROR; 
    } 
    return theLock; 
} 
+2

これはjavascriptと何が関係していますか? – itsme86

+0

'ContactInterval'は' System.TimeSpan'ですか?そうであれば、 '.TryParse()'や '.TryParseExact()'を使って、ユーザが希望する 'TimeSpan'に入力することができます。 – Filburt

+0

ユーザーとのコミュニケーションはどうですか? – pm100

答えて

0

をコード化されているあなたは、常にメソッドをオーバーロードしようとすることができます:ここで

はロックが作成される方法です

public Echo.Common.Business.LockingManager.LockItem GetLock(Echo.Common.Business.LockingManager.LockItem.LockType lockType, int entityId, int userId, string userName, string phoneNumber, ContactInterval contactInterval = null) 
{ 
    Echo.Common.Business.LockingManager.LockItem theLock = new Echo.Common.Business.LockingManager.LockItem(); 

    try 
    { 
     Echo.Common.Services.LockManagerServices lockManagerServices = new Echo.Common.Services.LockManagerServices(); 
     Echo.Common.Services.LockItem returnedLock = lockManagerServices.GetLock((Echo.Common.Services.LockType)lockType, entityId, userId, userName, phoneNumber); 
     theLock.UserId = returnedLock.UserId; 
     theLock.UserName = returnedLock.UserName; 
     theLock.PhoneNumber = returnedLock.PhoneNumber; 
     theLock.ExpireSecs = returnedLock.ExpireSecs; 
     // check if contactInterval is null, if not, use it, otherwise use default from returnedLock 
     theLock.ContactInterval = (contactInterval != null) ? contactInterval : returnedLock.ContactInterval; 
     int respondsID = (int)returnedLock.ResponseId; 
     theLock.ResponseId = (LockItem.LockResponse)respondsID; 
    } 
    catch 
    { 
     theLock.ResponseId = LockItem.LockResponse.ERROR; 
    } 
    return theLock; 
} 

もちろんこれはContactIntervalがそれ自身の型であることを前提としています。それ以外の場合は、タイプを渡すだけです。つまり、int,double,datetimeなどです。

+0

フィードバックをお寄せいただきありがとうございます。あなたの提案のいくつかを試してみましたが、サービスは私にとって手に取れないのでバイパスする必要があることが分かりました。 Lockが期限切れになったときに、サービス内の値に基づいて自動的に新しいものが作成されることを認識していませんでした。 – Jbbanuelos

関連する問題