Beispiel #1
0
        public IActionResult GetEvents([FromQuery] EventSourceParameters parameters)
        {
            var result = _eventService.GetRecords(parameters);

            if (!result.WasSuccessful)
            {
                return(NotFound());
            }

            //TODO
            //var response = new EventApiResponse(_urlHelper, "GetEvents", result.Records, parameters);

            return(Ok(result.Records.ToList()));
        }
Beispiel #2
0
        public CollectionOperationResult <EventModel> GetRecords(EventSourceParameters parameters)
        {
            try
            {
                var rawModels = Repository
                                .GetAsync(i =>
                                          (parameters.PersonIds.Any() || parameters.PersonIds.Contains(i.PersonId)) &&
                                          (String.IsNullOrEmpty(parameters.KeyPhrase) ||
                                           i.Content.Contains(parameters.KeyPhrase,
                                                              StringComparison.InvariantCultureIgnoreCase)))
                                .Result;

                var orderedModels = rawModels.OrderByDescending(model => model.EventDate).AsQueryable();
                var pagedModels   = PagesList <EventModel> .Init(orderedModels, parameters.PageNumber, parameters.PerPage);

                return(CollectionSuccess(OperationTypes.Read, pagedModels));
            }
            catch (Exception e)
            {
                return(CollectionError(OperationTypes.Read, ServerMessages.CannotLoadRecords));
            }
        }
Beispiel #3
0
        public EventApiResponse(IUrlHelper uriHelper, string methodName, PagesList <EventModel> models, EventSourceParameters parameters)
        {
            var uriHelper1 = uriHelper;

            PageNumber = models.CurrentPage;
            Models     = models;

            NextPage = models.HasNext
                ? new Uri(uriHelper1.Link(methodName, new
            {
                keyPhrase  = parameters.KeyPhrase,
                personids  = parameters.PersonIds,
                pageNumber = models.CurrentPage + 1,
                pageSize   = models.PageSize
            }))
                : null;

            PreviousPage       = models.HasPrevious
                ? PreviousPage = new Uri(uriHelper1.Link(methodName, new
            {
                keyPhrase  = parameters.KeyPhrase,
                personids  = parameters.PersonIds,
                pageNumber = models.CurrentPage - 1,
                pageSize   = models.PageSize
            }))
                : null;
        }