Goodday,
Let me explain with scenarios
For example I have an webapi link like this http://localhost:9090/Route/searchAppointments?startdate=2017-07-08&enddate=2017-07-20&subject="Charles"
In my controller
public JsonResult SearchAppointments(ScheduleDataSearchQuery search)
{
var data = _routeService.GetAllScheduledRoutes(search).Entity;
return Json(data, JsonRequestBehavior.AllowGet);
}
In my Service I have below
public OperationResult<IList<ScheduleData>> GetAllScheduledRoutes(ScheduleDataSearchQuery searchQuery)
{
var queryOver = _session.Query<ScheduleData>();
//switch (searchQuery.Status)
//{
// case EntityStatus.Active:
// queryOver = queryOver.Where(item => item.IsActive == true);
// break;
// case EntityStatus.InActive:
// queryOver = queryOver.Where(item => item.IsActive == false);
// break;
// case EntityStatus.Pending:
// queryOver = queryOver.Where(item => item.IsActive == null);
// break;
// case EntityStatus.Any:
// break;
//}
if (!string.IsNullOrWhiteSpace(searchQuery.CompanyName))
{
if (searchQuery.CompanyName != "All")
{
queryOver =
queryOver.Where(item => item.Route.Company.Name.Contains(searchQuery.CompanyName) || item.Route.Company.NameAbbreviation.Contains(searchQuery.CompanyName));
}
}
if (!string.IsNullOrWhiteSpace(searchQuery.RouteName))
{
if (searchQuery.RouteName != "All")
{
queryOver =
queryOver.Where(item => item.Route.Name.Contains(searchQuery.RouteName) );
}
}
if (!string.IsNullOrWhiteSpace(searchQuery.Territory))
queryOver = queryOver.Where(item => item.Route.Origin.TerminalRef.Contains(searchQuery.Territory) || item.Route.Origin.City.Contains(searchQuery.Territory)
|| item.Route.Origin.Location.Contains(searchQuery.Territory) || item.Route.Origin.Country.Name.Contains(searchQuery.Territory) || item.Route.Origin.Country.Capital.Contains(searchQuery.Territory) ||
item.Route.Destination.TerminalRef.Contains(searchQuery.Territory) || item.Route.Destination.City.Contains(searchQuery.Territory)
|| item.Route.Destination.Location.Contains(searchQuery.Territory) || item.Route.Destination.Country.Name.Contains(searchQuery.Territory) || item.Route.Destination.Country.Capital.Contains(searchQuery.Territory));
if (searchQuery.CompanyId.HasValue)
if (searchQuery.CompanyId != 0)
queryOver = queryOver.Where(item => item.Route.Company.Id == searchQuery.CompanyId);
if (searchQuery.RouteId.HasValue)
if (searchQuery.RouteId != 0)
queryOver = queryOver.Where(item => item.Route.Id == searchQuery.RouteId);
if (searchQuery.Id.HasValue)
queryOver = queryOver.Where(item => item.Id == searchQuery.Id);
if (searchQuery.StartDate.HasValue && searchQuery.EndDate.HasValue)
{
queryOver = queryOver.Where(item => item.StartTime >= searchQuery.StartDate.Value && item.EndTime <= searchQuery.EndDate.Value);
}
if (queryOver.Any())
{
return new OperationResult<IList<ScheduleData>>(true) { Entity = queryOver.ToList() };
}
return new OperationResult<IList<ScheduleData>>(false, new Exception("Empty Schedule Route List, Please Schedule a Route")) { Entity = new List<ScheduleData>() };
}
If you look at the code above, you can see that I can search for Appointments (i.e ScheduleData) from my Db but if an appointment has re-occurrence, I want to be able to interpret the re-occurrence e.g
foreach (var item in queryOver)
{
if (item.Recurrence)
{
---- Interpret and add the re-occurrence dates as individual appointment.
}
}
I hope this is more informative.
Also, I want to have a table that will store appointment re-occurrence date series for easy search. In order for me to to this I need to interpret recurrence, recurrence rule and recurrence options.