コード例 #1
0
ファイル: Events.cs プロジェクト: rroa/marvel-csharp
        /// <summary>
        /// Fetches lists of events with optional filters.
        /// </summary>
        /// <param name="filter">
        /// Search query filter data
        /// </param>
        public virtual EventResult GetEvents(EventRequestFilter filter = default(EventRequestFilter))
        {
            var request = new RestRequest(EventsUrlSegment, Method.GET);

            // Parse filter
            //
            ParseEventFilter(request, filter);

            return(Execute <EventResult>(request));
        }
コード例 #2
0
        public PageResponse <Event> GetEventPage([FromQuery] int page, [FromQuery] int size)
        {
            _logger.LogInformation(LoggingEvents.GetPage, "Getting page {PAGE}", page);

            string             filterString = HttpContext.Request.Query["filter"];
            EventRequestFilter filter       = JsonConvert.DeserializeObject <EventRequestFilter>(filterString);

            CorrectUserTime(filter);
            _logger.LogDebug(LoggingEvents.Filtering, "Getting page {PAGE} FromDate: {FROM} ToDate: {TO}", page, filter.fromDate, filter.toDate);
            return(_service.GetPage(page, size, filter));
        }
コード例 #3
0
 private void ParseEventFilter(IRestRequest request, EventRequestFilter filter)
 {
     if (filter != null)
     {
         if (filter.Name.HasValue())
         {
             request.AddParameter("name", filter.Name);
         }
         if (filter.NameStartsWith.HasValue())
         {
             request.AddParameter("nameStartsWith", filter.NameStartsWith);
         }
         if (filter.ModifiedSince.HasValue)
         {
             request.AddParameter("modifiedSince", filter.ModifiedSince.Value.ToString("yyyy-MM-dd"));
         }
         if (filter.Creators.HasValue())
         {
             request.AddParameter("creators", filter.Creators);
         }
         if (filter.Characters.HasValue())
         {
             request.AddParameter("characters", filter.Characters);
         }
         if (filter.Series.HasValue())
         {
             request.AddParameter("series", filter.Series);
         }
         if (filter.Comics.HasValue())
         {
             request.AddParameter("comics", filter.Comics);
         }
         if (filter.Stories.HasValue())
         {
             request.AddParameter("stories", filter.Stories);
         }
         if (filter.ResultSetOrder.HasValue())
         {
             request.AddParameter("orderBy", filter.ResultSetOrder);
         }
         if (filter.Limit.HasValue)
         {
             request.AddParameter("limit", filter.Limit.Value);
         }
         if (filter.Offset.HasValue)
         {
             request.AddParameter("offset", filter.Offset.Value);
         }
     }
 }
コード例 #4
0
        /// <summary>
        /// Fetches lists of events in which a specific comic appears,
        /// with optional filters.
        /// </summary>
        /// <param name="comicId">
        /// Comic unique identifier
        /// </param>
        /// <param name="filter">
        /// Search query filter data
        /// </param>
        public virtual EventResult GetComicEvents(string comicId, EventRequestFilter filter = default(EventRequestFilter))
        {
            // Build request url
            //
            string requestUrl =
                string.Format("{0}/{1}/events", ComicsUrlSegment, comicId);

            var request = new RestRequest(requestUrl, Method.GET);

            // Parse filter
            //
            ParseEventFilter(request, filter);

            return(Execute <EventResult>(request));
        }
コード例 #5
0
        private void CorrectUserTime(EventRequestFilter f)
        {
            var offset = GetOffset();

            if (offset != 0)
            {
                if (f.fromDate > DateTime.MinValue && f.toDate < DateTime.MaxValue)
                {
                    TimeSpan tsOffset = TimeSpan.FromMinutes(-offset);
                    //FromDate
                    f.fromDate = new DateTimeOffset(f.fromDate).ToOffset(tsOffset).DateTime;
                    //ToDate
                    f.toDate = new DateTimeOffset(f.toDate).ToOffset(tsOffset).DateTime;
                }
            }
        }