2017-06-19 8 views
0

更新ユーザーフィールド毎月、管理役割およびサブスクリプション

public class Subscriptions 
{ 
public int SubscriptionId {Get;Set;} 
public DateTime CreateTime {Get;set;} 
public int SubscriptionType{get;set;}//fk 
public bool IsActive {get;set;} 
} 

は今ここに私を混乱させている部分があります

if(_profileStatus == ProfileStatus.ACTIVEPROFILE) 
{ 
    // I also have a LastPaymentDate from API here... 
    var lastPaymentDate = _profileStatus.LastPaymentDate.AddMonths(1); 
    // this is to ensure we can compare it against the current date 
    if(currentDate>LastPaymentDate) 
    { 
     // Should signal that the field in user table can be reset 
    } 
} 
0:ユーザーのサブスクリプションは、彼がこのようにログインするたびにアクティブであるかどうか、私がチェックを行うので

Public class Users 
{ 
// some properties... 
public int HitViews {get;set;} 
} 

:私のユーザーテーブルに配置され、ユーザーのフィールドをリセットする方法私たちは次のような状況を想像している場合、ここで

問題は、次のとおりです。

  • ユーザーは、サブスクリプションが更新された日にログインしていない場合、私は私のAPIからlastPaymentDateを受信したとき、このように、それが最新であるもの日付、およびステートメントは、フィールドをリセットする場合、私は第二には履行を持っていません....

私は私のサブスクリプションテーブルにLastPaymentDateを格納することによって、これを修正し、このように、それに対してチェックを実行する想像:

if(_profileStatus == ProfileStatus.ACTIVEPROFILE) 
{ 
if(currentDate>myDBLastPaymentDate) 
{ 
// now I should check whether the db last payment date and API last payment date are different, if they are, then I simply swipe the DB value with API value ? 
} 
} 

ここで私の質問は、これを有効にする正しい方法ですか、そうでない場合は、私はこれを改善できるようにあなたの人の提案は何ですか?

誰かが私を助けることができますか?

+0

はい、正しい方法です。別の方法は、Compareメソッドを使用することです。 – Chirag

+0

比較される変数名は大文字ですか、それはタイプミスですか、その行の直前で定義された変数以外のものを比較していますか? (行:if(currentDate> LastPaymentDate)) –

+0

@RamazanBinarbasi typo、私はスタック上にこのコードを書いています。 – User987

答えて

1

日付を比較するには2通りの方法があります。 あなたは既にそれをやっているので、簡単なチェックがあります。

if(currentDate>myDBLastPaymentDate) 
{ 

} 

もう1つの方法は次のとおりです。この方法は通常、日付がDatetime形式の場合に非常に便利です。

int camparison = DateTime.Compare(currentDate, myDBLastPaymentDate); 
string result; 

if (camparison < 0) 
{ 
    result= "is earlier than"; 
} 
else if (camparison == 0) 
{ 
    result= "is the same time as";   
}  
else 
{ 
    result= "is later than"; 
} 

希望します。

関連する問題