Example #1
0
        public IActionResult Index(EventsReportViewModel request)
        {
            var model = request.Search;

            if (model == null)
            {
                model = new SearchEventsViewModel();
            }
            model.Page = model.Page.HasValue ? model.Page.Value : 1;

            EventsReportListViewModel      result = new EventsReportListViewModel();
            IEnumerable <EventsItemReport> events = context.Query <EventsItemReport>().FromSql($"SELECT * FROM get_events_report({model.Page.Value}, {pageSize}, {model.StartAfter}, {model.StartBefore}, {model.EndAfter}, {model.EndBefore})").ToList();

            result.Events = events;

            result.TotalEvents = context.Query <EventsReportCount>().FromSql($"SELECT * FROM get_events_report_count({model.StartAfter}, {model.StartBefore}, {model.EndAfter}, {model.EndBefore})").FirstOrDefault().total;
            result.TotalPages  = (result.TotalEvents / pageSize) + ((result.TotalEvents % pageSize != 0) ? 1 : 0);

            EventsReportViewModel response = new EventsReportViewModel
            {
                EventsList = result,
                Search     = model
            };

            return(View(response));
        }
        public IActionResult Index(int page = 1)
        {
            EventsListViewModel      result = new EventsListViewModel();
            IEnumerable <EventsItem> events = context.Query <EventsItem>().FromSql($"SELECT * FROM get_events({page}, {pageSize})").ToList();

            result.Events      = events;
            result.TotalEvents = context.Events.Count();
            result.TotalPages  = (result.TotalEvents / pageSize) + ((result.TotalEvents % pageSize != 0) ? 1 : 0);

            return(View(result));
        }