【发布时间】:2017-11-21 07:15:42
【问题描述】:
我的项目中有一个 DB 表(映射为类),如下所示:
public class Subscriptions
{
public int SubscriptionId {Get;Set;}
public DateTime CreateTime {Get;set;}
public int SubscriptionType{get;set;}//fk
public bool IsActive {get;set;}
}
现在让我感到困惑的部分是如何重置位于我的用户表中的用户字段:
Public class Users
{
// some properties...
public int HitViews {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
}
}
这里的问题是,如果我们想象以下场景:
- 如果用户在订阅续订当天没有登录怎么办,因此当我从我的 API 收到 lastPaymentDate 时,它将是最新日期,并且我将无法在第二个 if 语句中执行重置字段。 ...
我想通过将 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 ?
}
}
我的问题是,这是有效且正确的方法吗?如果不是,您的建议是什么,以便我可以改进?
有人可以帮帮我吗?
【问题讨论】:
-
是的,你做对了。另一种方法是使用比较方法。
-
比较的变量名是大写的,是错字还是你比较的不是在该行之前定义的变量? (行:if(currentDate>LastPaymentDate))
-
@RamazanBinarbasi 错字,我在堆栈上写了这段代码只是为了展示一个例子:)
标签: c# asp.net .net asp.net-mvc c#-4.0