I have the following class:
public class Membership
{
public DateTime StartDate { get; set; }
public DateTime? EndDate { get; set; } // If null then
public bool DoesAnOfferAlreadyExistWithinTheTimeframeProvided(int RetailerId, DateTime ValidFrom, DateTime ValidTo)
{
bool result = true;
try
{
// Obtain the current list of coupons associated to the retailer.
List retailerCoupons = PayPalInStore.Data.RetailerCoupon.Find(x => x.RetailerId == RetailerId).ToList();
// Loop through each coupon and see if the timeframe provided in the NEW coupon doesnt fall between any EZISTING coupon.
if (retailerCoupons != null)
{
foreach (RetailerCoupon coupon in retailerCoupons)
{
DateTime retailerCouponValidFrom = coupon.DateValidFrom;
DateTime retailerCouponValidTo = coupon.DateExpires;
if ((ValidFrom <= retailerCouponValidFrom && ValidTo <= retailerCouponValidFrom) || (ValidFrom >= retailerCouponValidTo && ValidTo >= retailerCouponValidTo))
{
return false;
}
}
}
return result;
}
catch (Exception ex)
{
this.errorManager.LogError("DoesAnOfferAlreadyExistWithinTheTimeframeProvided failed", ex);
return result;
}
}