Пример #1
0
        public EventsOfficeHoursModel EventsDayView(DateTime dateTime, string urlSafeName)
        {
            var dto = new DateDto();

            var startDateTime = dateTime;
            var endDateTime   = dateTime.AddHours(24);

            var channelUser = GetChannelUserIdByUrlSafeName(urlSafeName, true);

            if (channelUser == null)
            {
                return(null);
            }

            var channelUserId = channelUser.NameId;

            var channelEvents = _context.ChannelEvent
                                .Where(
                p => p.ChannelUserId == channelUserId &&
                p.DateTime > startDateTime &&
                p.DateTime < endDateTime
                ).OrderBy(x => x.DateTime).ToList();

            if (channelEvents.Count == 0)
            {
                var startEmthyDateTime =
                    dto.RoundDown(
                        DateTime.UtcNow.Subtract(new TimeSpan(0, 8, 0, 0)),
                        new TimeSpan(0, 0, 5, 0));

                var endEmthyDateTime = dto.RoundUp(DateTime.UtcNow, new TimeSpan(0, 0, 5, 0));

                var model = new EventsOfficeHoursModel
                {
                    Day             = startDateTime.DayOfWeek,
                    StartDateTime   = startEmthyDateTime,
                    EndDateTime     = endEmthyDateTime,
                    AmountOfMotions = new List <WeightViewModel>(),
                    Length          = 0
                };
                return(model);
            }

            var median = channelEvents.Skip(channelEvents.Count() / 2).First().DateTime;

            startDateTime = dto.RoundDown(median.ToUniversalTime().AddHours(-4), new TimeSpan(0, 0, 5, 0));
            endDateTime   = dto.RoundUp(median.ToUniversalTime().AddHours(4), new TimeSpan(0, 0, 5, 0));

            var channelParseEvents = channelEvents
                                     .Where(p => p.DateTime > startDateTime &&
                                            p.DateTime < endDateTime);

            return(ParseEvents(channelParseEvents.ToList(), startDateTime, endDateTime));
        }
Пример #2
0
        public EventsOfficeHoursModel EventsRecent(string urlSafeName)
        {
            var dto = new DateDto();

            var startDateTime =
                dto.RoundDown(
                    DateTime.UtcNow.Subtract(new TimeSpan(0, 8, 0, 0)),
                    new TimeSpan(0, 0, 5, 0));

            var endDateTime = dto.RoundUp(DateTime.UtcNow, new TimeSpan(0, 0, 5, 0));

            var channelUser = GetChannelUserIdByUrlSafeName(urlSafeName, true);

            if (channelUser == null)
            {
                return(null);
            }
            var channelUserId = channelUser.NameId;

            var channelEvents = _context.ChannelEvent
                                .Where(
                p => p.ChannelUserId == channelUserId &&
                p.DateTime > startDateTime &&
                p.DateTime < endDateTime
                ).OrderBy(p => p.DateTime);

            return(ParseEvents(channelEvents.ToList(), startDateTime, endDateTime));
        }