检查日期是否存在 [英] Check date exist or not

查看:103
本文介绍了检查日期是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加自定义验证,如果一旦日期添加,则相同或日期之间无法添加。



开始日期和结束日期



如果我假设我将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, your StartDate have to be greater than Max(OfferEndDate). In other words, if StartDate is less than Max(OfferEndDate) your method should return false.


假设您想知道是否有任何与指定日期范围重叠的优惠:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆