检查日期是否存在 [英] Check date exist or not
问题描述
我想添加自定义验证,如果一旦日期添加,则相同或日期之间无法添加。
开始日期和结束日期
如果我假设我将01-06-2018添加到10-06-2018这个记录
那么此记录之间不能再多了添加。
假设用户现在输入06-06-2018到15-06-2018然后返回false。因为06-06-2018已经首先注册。
我尝试过:
列表lstOffers = db.OfferMasters.Where(x =>((x.OfferStartDate = dtStart)||(x.OfferStartDate> = dtEndDate&& x.OfferEndDate = dtStart&& x .OfferEndDate< = dtEndDate))&& x.IsActive&& x.RestaurantId == RestaurantId)。ToList();
I want to add custom validation where if once date adds then same or between date cannot be added.
start date and End date
if suppose I add 01-06-2018 to 10-06-2018 this record
then no more between this record can be added.
suppose user enter now 06-06-2018 to 15-06-2018 then return false. because 06-06-2018 is already registered first.
What I have tried:
List lstOffers = db.OfferMasters.Where(x => ((x.OfferStartDate = dtStart) || (x.OfferStartDate >= dtEndDate && x.OfferEndDate = dtStart && x.OfferEndDate <= dtEndDate)) && x.IsActive && x.RestaurantId == RestaurantId).ToList();
推荐答案
所有,我建议阅读: .NET时间段库 [ ^ ],因为它可以帮助你理解两个时间段之间的关系...
根据你的要求,你的StartDate
必须大于Max(OfferEndDate)
。换句话说,如果StartDate
小于Max(OfferEndDate)
,您的方法应该返回false
。
First of all, i'd suggest to read this: Time Period Library for .NET[^], because it may help you in understanding the relationship between two time periods...
According to your requirement, yourStartDate
have to be greater thanMax(OfferEndDate)
. In other words, ifStartDate
is less thanMax(OfferEndDate)
your method should returnfalse
.
假设您想知道是否有任何与指定日期范围重叠的优惠:
Assuming you want to find out whether there are any offers which overlap the specified date range:
bool anyOverlappingOffers = db.OfferMasters
.Where(x => x.RestaurantId == RestaurantId && x.IsActive)
.Any(x => x.OfferStartDate <= dtEndDate && dtStartDate <= x.OfferEndDate);
这篇关于检查日期是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!