Search code examples
c#asp.net-mvckendo-gridllblgenpro

how to return results that have a date of yesterday and before


I am returning results using the LLBLGen adapter model. using break points because I cannot get them to populate the kendo grid yet, I can see that they are all coming back. However I need to only return results that have a date property of yesterday and prior. I am not familiar at all using the kendo grid nor the LLBL adapter. The majority of other examples out there are using entity framework. here is what i have so far. There is no error messages because I am stuck at how to setup the filter?

Controller

public ActionResult BundleStatus()
    {
        return View();

    }

    [HttpPost]
    public ActionResult BundleStatusRead([DataSourceRequest] DataSourceRequest request)
    {

            var span = DateTime.Today.AddDays(-1);
            DataAccessAdapter adapter = new DataAccessAdapter();
            EntityCollection allBundles = new EntityCollection(new CarrierBundleEntityFactory());
            adapter.FetchEntityCollection(allBundles, null);
           var results = allBundles;

         return Json(results.ToDataSourceResult(request));
    }

}

View

@{
ViewBag.Title = "BundleStatusGet";
  }

 <div>
@(Html.Kendo().Grid<ZoomAudits.DAL.EntityClasses.CarrierBundleEntity>()
    .Name("grid")
    .Columns(columns =>
    {
        columns.Bound(c => c.BundleId).Width(140);
        columns.Bound(c => c.CarrierId).Width(190);
        columns.Bound(c => c.Date);
        columns.Bound(c => c.IsSent).Width(110);
    })
    .HtmlAttributes(new { style = "height: 380px;" })
    .Scrollable()
    .Groupable()
    .Sortable()
    .Pageable(pageable => pageable
        .Refresh(true)
        .PageSizes(true)
        .ButtonCount(5))
                .Selectable(selectable => selectable
                .Mode(GridSelectionMode.Multiple)
                .Type(GridSelectionType.Cell))
            //.Events(events => events.Change("onChange").Sync("sync_handler")))
    .DataSource(dataSource => dataSource
        .Ajax()
        .Read(read => read.Action("BundleStatusRead", "BundleStatus"))
                //.Update(update => update.Action("EditingInline_Update", "Grid"))
    )
)

Update Controller

public ActionResult BundleStatusRead([DataSourceRequest] DataSourceRequest request)
    {

            var span = DateTime.Today.AddDays(-1);
            DataAccessAdapter adapter = new DataAccessAdapter();
            EntityCollection allBundles = new EntityCollection(new CarrierBundleEntityFactory());
            RelationPredicateBucket filter = new RelationPredicateBucket(CarrierBundleFields.Date == span);
            adapter.FetchEntityCollection(allBundles, filter);
           var results = allBundles;

         return Json(results.ToDataSourceResult(request));

it is not returning any results? this is what i see when i open up the break point at var results LLBL Enumeration yielded no results


Solution

  • Hi I haven't used LLBLGen in a while and that was prior to the adapter. However, I found this documentation on Using the EntityCollection<T> class, Adapter for LLBLGen. Hope it helps.

    By the way, you can also use [HttpGet] and set the action result to allow get.

    return Json(results.ToDataSourceResult(request)), JsonRequestBehavior.AllowGet);
    

    If you are trying to get yesterday and prior then use:

    RelationPredicateBucket filter = new RelationPredicateBucket(CarrierBundleFields.Date <= span);