More in this section
Forums / Module Builder / Filter Child Content items by Date

Filter Child Content items by Date

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
1 posts, 0 answered
  1. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    15 Aug 2017
    Link to this post

    I have a dynamic module with two content types 1) Traded Funds and 2) Historic Data the second of which has the first as its parent. Each historic data entry has a date and also stores two additional fields storing the traded values for that day. 

    I'm creating a custom widget using MVC and trying to query the historic data filtering by dates so that the user can view only a selected number of days' worth of financial data. 

    Here's a sample of code I'm using: 

    var dynamicModuleManager = new DynamicModuleManager(String.Empty);
    Type typeETF = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.TradedFunds.ExchangeTradedFund");
    Type typeHistoricData = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.TradedFunds.HistoricDataEntry");
     
    //get the fund that we're dealing with
    var fundItem = dynamicModuleManager.GetDataItems(typeETF).Where(x => x.UrlName == urlName && x.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && x.Visible == true).First();
     
    var newFromDate = from.Subtract(TimeSpan.FromDays(1));
    var newToDate = to.AddDays(1);
     
    //now get the child items
    var childItems = fundItem.GetChildItems(typeHistoricData)
        .Where(x => x.Status == ContentLifecycleStatus.Live
        && x.Visible == true
        && x.GetValue<DateTime?>("Date") > newFromDate
        && x.GetValue<DateTime?>("Date") < newToDate).ToList();
     
    var childItems2 = dynamicModuleManager.GetDataItems(typeHistoricData).Where(x => x.SystemParentId == fundItem.OriginalContentId
        && x.Status == ContentLifecycleStatus.Live
        && x.Visible == true
        && x.GetValue<DateTime?>("Date") > newFromDate
        && x.GetValue<DateTime?>("Date") < newToDate).ToList();

    In both attempts childItems and childItems2 the count returned is zero. 

    There is data available for the days I'm selecting so I'm not sure why this is happening. I seem to be able to filter/sort on other fields except Date. 

1 posts, 0 answered