Exemplo n.º 1
0
        public async Task <IActionResult> Index(int page = 1)
        {
            var currentUserId = GetCurrentUserId();
            var query         = _articlesRepository.GetAllFeed(currentUserId);

            var count = await query.CountAsync();

            var paginationModel = new PaginationViewModel("Home", "Index", count, page);

            try
            {
                paginationModel.Validate(page);
            }
            catch (PaginationOutOfRangeException ex)
            {
                page = ex.Negative ? 1 : paginationModel.TotalPages;

                return(RedirectToAction("Index", new { Page = page }));
            }

            var articles = await paginationModel.GetQuery(query)
                           .ToListAsync();


            var model = new HomeFeedViewModel(paginationModel, articles);

            return(View(model));
        }
Exemplo n.º 2
0
        public HomePage()
        {
            InitializeComponent();
            _viewModel     = new HomeFeedViewModel();
            BindingContext = _viewModel;
            Connectivity.ConnectivityChanged += Connectivity_ConnectivityChanged;

            MessagingCenter.Subscribe <HomeFeedViewModel>(this, "Reload", async(sender) =>
            {
                await SetUserAndProgeny();
                await Reload();
            });

            MessagingCenter.Subscribe <SelectProgenyPage>(this, "Reload", async(sender) =>
            {
                await SetUserAndProgeny();
                await Reload();
            });

            MessagingCenter.Subscribe <AccountViewModel>(this, "Reload", async(sender) =>
            {
                await SetUserAndProgeny();
                await Reload();
            });
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Index(int id = 0)
        {
            int    childId      = id;
            string userEmail    = HttpContext.User.FindFirst("email")?.Value ?? _defaultUser;
            string userTimeZone = HttpContext.User.FindFirst("timezone")?.Value ?? Constants.DefaultTimezone;

            if (string.IsNullOrEmpty(userTimeZone))
            {
                userTimeZone = Constants.DefaultTimezone;
            }
            UserInfo userinfo = await _progenyHttpClient.GetUserInfo(userEmail);

            if (User.Identity.IsAuthenticated)
            {
                if (childId == 0 && userinfo.ViewChild > 0)
                {
                    _progId = userinfo.ViewChild;
                }
            }
            else
            {
                _progId = Constants.DefaultChildId;
            }

            Progeny progeny = await _progenyHttpClient.GetProgeny(_progId);

            if (progeny.Name == "401")
            {
                var returnUrl = $"{Request.Scheme}://{Request.Host}{Request.PathBase}";
                return(RedirectToAction("CheckOut", "Account", new { returnUrl }));
            }
            List <UserAccess> accessList = await _progenyHttpClient.GetProgenyAccessList(_progId);

            int userAccessLevel = (int)AccessLevel.Public;

            if (accessList.Count != 0)
            {
                UserAccess userAccess = accessList.SingleOrDefault(u => u.UserId.ToUpper() == userEmail.ToUpper());
                if (userAccess != null)
                {
                    userAccessLevel = userAccess.AccessLevel;
                }
            }

            if (progeny.IsInAdminList(userEmail))
            {
                userAccessLevel = (int)AccessLevel.Private;
            }

            if (progeny.BirthDay.HasValue)
            {
                progeny.BirthDay = DateTime.SpecifyKind(progeny.BirthDay.Value, DateTimeKind.Unspecified);
            }

            HomeFeedViewModel feedModel = new HomeFeedViewModel();

            feedModel.UserAccessLevel = (int)AccessLevel.Public;
            if (accessList.Count != 0)
            {
                UserAccess userAccess = accessList.SingleOrDefault(u => u.UserId.ToUpper() == userEmail.ToUpper());
                if (userAccess != null)
                {
                    feedModel.UserAccessLevel = userAccess.AccessLevel;
                }
                else
                {
                    ViewBag.OriginalProgeny = progeny;
                    progeny = await _progenyHttpClient.GetProgeny(Constants.DefaultChildId);
                }
            }
            if (progeny.IsInAdminList(userEmail))
            {
                feedModel.UserAccessLevel = (int)AccessLevel.Private;
            }

            BirthTime progBirthTime;

            if (!String.IsNullOrEmpty(progeny.NickName) && progeny.BirthDay.HasValue && feedModel.UserAccessLevel < (int)AccessLevel.Public)
            {
                progBirthTime = new BirthTime(progeny.BirthDay.Value,
                                              TimeZoneInfo.FindSystemTimeZoneById(progeny.TimeZone));
            }
            else
            {
                progBirthTime = new BirthTime(new DateTime(2018, 02, 18, 18, 02, 00), TimeZoneInfo.FindSystemTimeZoneById(progeny.TimeZone));
            }

            feedModel.CurrentTime      = progBirthTime.CurrentTime;
            feedModel.Years            = progBirthTime.CalcYears();
            feedModel.Months           = progBirthTime.CalcMonths();
            feedModel.Weeks            = progBirthTime.CalcWeeks();
            feedModel.Days             = progBirthTime.CalcDays();
            feedModel.Hours            = progBirthTime.CalcHours();
            feedModel.Minutes          = progBirthTime.CalcMinutes();
            feedModel.NextBirthday     = progBirthTime.CalcNextBirthday();
            feedModel.MinutesMileStone = progBirthTime.CalcMileStoneMinutes();
            feedModel.HoursMileStone   = progBirthTime.CalcMileStoneHours();
            feedModel.DaysMileStone    = progBirthTime.CalcMileStoneDays();
            feedModel.WeeksMileStone   = progBirthTime.CalcMileStoneWeeks();


            Picture tempPicture = new Picture();

            tempPicture.ProgenyId      = 0;
            tempPicture.Progeny        = progeny;
            tempPicture.AccessLevel    = (int)AccessLevel.Public;
            tempPicture.PictureLink600 = $"https://{Request.Host}{Request.PathBase}" + "/photodb/0/default_temp.jpg";
            tempPicture.ProgenyId      = progeny.Id;
            tempPicture.PictureTime    = new DateTime(2018, 9, 1, 12, 00, 00);

            Picture displayPicture = tempPicture;

            if (feedModel.UserAccessLevel < (int)AccessLevel.Public)
            {
                displayPicture = await _mediaHttpClient.GetRandomPicture(progeny.Id, feedModel.UserAccessLevel, userTimeZone);
            }
            PictureTime picTime = new PictureTime(new DateTime(2018, 02, 18, 20, 18, 00), new DateTime(2018, 02, 18, 20, 18, 00), TimeZoneInfo.FindSystemTimeZoneById(progeny.TimeZone));

            if (feedModel.UserAccessLevel == (int)AccessLevel.Public || displayPicture == null)
            {
                displayPicture = await _mediaHttpClient.GetRandomPicture(Constants.DefaultChildId, feedModel.UserAccessLevel, userTimeZone);

                if (!displayPicture.PictureLink600.StartsWith("https://"))
                {
                    displayPicture.PictureLink600 = _imageStore.UriFor(displayPicture.PictureLink600);
                }

                feedModel.ImageLink600 = displayPicture.PictureLink600;
                feedModel.ImageId      = displayPicture.PictureId;
                picTime                = new PictureTime(new DateTime(2018, 02, 18, 20, 18, 00), displayPicture.PictureTime, TimeZoneInfo.FindSystemTimeZoneById(progeny.TimeZone));
                feedModel.Tags         = displayPicture.Tags;
                feedModel.Location     = displayPicture.Location;
                feedModel.PicTimeValid = false;
            }
            else
            {
                if (!displayPicture.PictureLink600.StartsWith("https://"))
                {
                    displayPicture.PictureLink600 = _imageStore.UriFor(displayPicture.PictureLink600);
                }

                feedModel.ImageLink600 = displayPicture.PictureLink600;
                feedModel.ImageId      = displayPicture.PictureId;
                if (displayPicture.PictureTime != null && progeny.BirthDay.HasValue)
                {
                    picTime = new PictureTime(progeny.BirthDay.Value,
                                              displayPicture.PictureTime,
                                              TimeZoneInfo.FindSystemTimeZoneById(progeny.TimeZone));
                    feedModel.PicTimeValid = true;
                }

                feedModel.Tags     = displayPicture.Tags;
                feedModel.Location = displayPicture.Location;
            }
            feedModel.PicTime    = picTime.PictureDateTime;
            feedModel.PicYears   = picTime.CalcYears();
            feedModel.PicMonths  = picTime.CalcMonths();
            feedModel.PicWeeks   = picTime.CalcWeeks();
            feedModel.PicDays    = picTime.CalcDays();
            feedModel.PicHours   = picTime.CalcHours();
            feedModel.PicMinutes = picTime.CalcMinutes();
            feedModel.Progeny    = progeny;
            feedModel.EventsList = new List <CalendarItem>();
            feedModel.EventsList = await _progenyHttpClient.GetUpcomingEvents(_progId, userAccessLevel);

            foreach (CalendarItem eventItem in feedModel.EventsList)
            {
                if (eventItem.StartTime.HasValue && eventItem.EndTime.HasValue)
                {
                    eventItem.StartTime = TimeZoneInfo.ConvertTimeFromUtc(eventItem.StartTime.Value, TimeZoneInfo.FindSystemTimeZoneById(userinfo.Timezone));
                    eventItem.EndTime   = TimeZoneInfo.ConvertTimeFromUtc(eventItem.EndTime.Value, TimeZoneInfo.FindSystemTimeZoneById(userinfo.Timezone));
                }
            }

            feedModel.LatestPosts = new TimeLineViewModel();
            feedModel.LatestPosts.TimeLineItems = new List <TimeLineItem>();
            feedModel.LatestPosts.TimeLineItems = await _progenyHttpClient.GetProgenyLatestPosts(_progId, userAccessLevel);

            if (feedModel.LatestPosts.TimeLineItems.Any())
            {
                feedModel.LatestPosts.TimeLineItems = feedModel.LatestPosts.TimeLineItems.OrderByDescending(t => t.ProgenyTime).Take(5).ToList();
            }

            feedModel.YearAgoPosts = new TimeLineViewModel();
            feedModel.YearAgoPosts.TimeLineItems = new List <TimeLineItem>();
            feedModel.YearAgoPosts.TimeLineItems = await _progenyHttpClient.GetProgenyYearAgo(_progId, userAccessLevel);

            if (feedModel.YearAgoPosts.TimeLineItems.Any())
            {
                feedModel.YearAgoPosts.TimeLineItems = feedModel.YearAgoPosts.TimeLineItems.OrderByDescending(t => t.ProgenyTime).ToList();
            }

            return(View(feedModel));
        }