예제 #1
0
        public EventsOfficeHoursModel ParseEvents(List <ChannelEvent> channelEvents, DateTime startDateTime, DateTime endDateTime)
        {
            var dto = new DateDto();

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

            model.Length = _context.ChannelEvent
                           .Count(
                p => p.DateTime > model.StartDateTime &&
                p.DateTime < model.EndDateTime
                );

            const int interval = 60 * 5; // 5 minutes
            var       i        = dto.GetUnixTime(startDateTime);

            while (i <= dto.GetUnixTime(endDateTime))
            {
                var eventItem = new WeightViewModel
                {
                    StartDateTime = dto.UnixTimeToDateTime(i),
                    EndDateTime   = dto.UnixTimeToDateTime(i + interval)
                };
                eventItem.LabelUtc = eventItem.StartDateTime.ToString("HH:mm");
                eventItem.Label    = dto.UtcDateTimeToAmsterdamDateTime(eventItem.StartDateTime).ToString("HH:mm");

                var weightSum = channelEvents
                                .Where(p =>
                                       p.DateTime > eventItem.StartDateTime &&
                                       p.DateTime < eventItem.EndDateTime)
                                .Select(p => p.Weight).Sum();

                eventItem.Weight = weightSum;
                model.AmountOfMotions.Add(eventItem);
                i += interval;
            }
            return(model);
        }
예제 #2
0
        public IActionResult Index(DateDto dto)
        {
            var date         = dto.GetDateTime();
            var urlSafeName  = dto.Name;
            var relativeDays = dto.GetRelativeDays(date);

            var tommorow  = date.AddDays(1);
            var yesterday = date.AddDays(-1);

            var allChannelUsers = _updateStatusContent.GetAllChannelUsers()
                                  .Where(p => p.IsVisible && p.IsAccessible).ToList();

            if (!allChannelUsers.Any())
            {
                return(BadRequest("Database connection successful; Please add a ChannelUser first to continue; You need to restart the application"));
            }

            // Show default page
            if (string.IsNullOrEmpty(urlSafeName))
            {
                var find = allChannelUsers.Find(x => x.NameUrlSafe.Contains("tafelvoetbal"));

                if (find != null)
                {
                    urlSafeName = find.NameUrlSafe;
                }
                else
                {
                    var selectItemUrlSafe = allChannelUsers.Single(p => p.NameUrlSafe.Length >= 1).NameUrlSafe;
                    if (selectItemUrlSafe != null)
                    {
                        urlSafeName = selectItemUrlSafe;
                    }
                }
            }

            var channelUserObject = _updateStatusContent.GetChannelUserIdByUrlSafeName(urlSafeName, false);

            if (channelUserObject == null)
            {
                return(NotFound("not found"));
            }

            var model = new HomeViewModel
            {
                List         = allChannelUsers,
                Name         = channelUserObject.Name,
                NameId       = channelUserObject.NameId,
                NameUrlSafe  = channelUserObject.NameUrlSafe,
                RelativeDate = relativeDays,
                Today        = date.Year + "-" + dto.LeadingZero(date.Month) + "-" + dto.LeadingZero(date.Day),
                Tomorrow     = tommorow.Year + "-" + dto.LeadingZero(tommorow.Month) + "-" + dto.LeadingZero(tommorow.Day),
                Yesterday    = yesterday.Year + "-" + dto.LeadingZero(yesterday.Month) + "-" + dto.LeadingZero(yesterday.Day),
                Day          = dto.GetDateTime()
            };



            if (model.RelativeDate == 0)
            {
                var isFreeStatus = _updateStatusContent.IsFree(channelUserObject.NameId);
                model.IsFree = isFreeStatus.IsFree;
                model.IsFreeLatestUtcString         = isFreeStatus.DateTimeUtcString;
                model.IsFreeLatestAmsterdamDateTime = dto.UtcDateTimeToAmsterdamDateTime(isFreeStatus.DateTime);
                return(View("Live", model));
            }

            return(View("Archive", model));
        }