示例#1
0
        public IActionResult EventsDayView(DateDto dto, string ext)
        {
            var dateTime = dto.GetDateTime();

            if (string.IsNullOrEmpty(dto.Name) && dateTime.Year > 2015)
            {
                return(BadRequest("name or date wrong"));
            }

            var result =
                _updateStatusContent.EventsDayView(dateTime, dto.Name);

            if (result == null)
            {
                return(BadRequest("name error"));
            }

            switch (ext)
            {
            case "csv":
                var resultCsv = "DateTime;Weight;Label\n";
                foreach (var item in result.AmountOfMotions)
                {
                    resultCsv += $"{item.StartDateTime};{item.Weight};{item.Label}\n";
                }
                return(Content(resultCsv));

            case "json":
                return(Json(result));

            default:
                return(Json(result));
            }
        }
示例#2
0
        public void GetDateTimeAbsoluteToday()
        {
            var model = new DateDto();

            var today = RoundDown(DateTime.UtcNow, new TimeSpan(1, 0, 0, 0));

            model.Date = today.ToString("yyyy-MM-dd");
            var getDateTimeFromModel = model.GetDateTime();

            Assert.AreEqual(getDateTimeFromModel, today);
        }
示例#3
0
        public void GetDateTimeRelativeYesterday()
        {
            var model = new DateDto();

            var yesterday = RoundDown(DateTime.UtcNow, new TimeSpan(1, 0, 0, 0)).AddDays(-1);

            model.Date = "-1";
            var getDateTimeFromModel = model.GetDateTime();

            Assert.AreEqual(getDateTimeFromModel, yesterday);
        }
示例#4
0
        public IActionResult EventsOfficeHours(DateDto dto)
        {
            var dateTime = dto.GetDateTime();

            if (string.IsNullOrEmpty(dto.Name) && dateTime.Year > 2015)
            {
                return(BadRequest("name or date wrong"));
            }

            var startDateTime = dateTime.ToUniversalTime().AddHours(9);
            var endDateTime   = dateTime.ToUniversalTime().AddHours(18);

            var getDataChannelEvents = _updateStatusContent.GetTimeSpanByName(dto.Name, startDateTime, endDateTime).ToList();
            var result = _updateStatusContent.ParseEvents(getDataChannelEvents, startDateTime, endDateTime);

            if (result == null)
            {
                return(BadRequest("name error"));
            }

            return(Json(result));
        }
示例#5
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));
        }