Esempio n. 1
0
        private async void CardsView_OnItemAppearing(CardsView view, ItemAppearingEventArgs args)
        {
            _viewModel.IsZoomed = false;
            _viewModel.IsBusy   = true;

            if (_viewModel.CanLoadMore && _viewModel.CurrentIndex < 1)
            {
                await LoadNewer();
            }

            if (_viewModel.CanLoadMore && _viewModel.CurrentIndex > _viewModel.VideoItems.Count - 2)
            {
                await LoadOlder();
            }

            _viewModel.CurrentVideoViewModel = _viewModel.VideoItems[_viewModel.CurrentIndex];
            _viewModel.CurrentVideoId        = _viewModel.CurrentVideoViewModel.VideoId;
            await UpdateEditInfo();

            if (_viewModel.CurrentVideoViewModel.VideoTime != null && _viewModel.Progeny.BirthDay.HasValue)
            {
                DateTime picTimeBirthday = new DateTime(_viewModel.Progeny.BirthDay.Value.Ticks, DateTimeKind.Unspecified);

                PictureTime picTime = new PictureTime(picTimeBirthday, _viewModel.CurrentVideoViewModel.VideoTime, TimeZoneInfo.FindSystemTimeZoneById(_viewModel.Progeny.TimeZone));
                _viewModel.PicTimeValid = true;
                _viewModel.PicYears     = picTime.CalcYears();
                _viewModel.PicMonths    = picTime.CalcMonths();
                _viewModel.PicWeeks     = picTime.CalcWeeks();
                _viewModel.PicDays      = picTime.CalcDays();
                _viewModel.PicHours     = picTime.CalcHours();
                _viewModel.PicMinutes   = picTime.CalcMinutes();
            }

            LocationMap.Pins.Clear();
            if (!string.IsNullOrEmpty(_viewModel.CurrentVideoViewModel.Latitude) &&
                !string.IsNullOrEmpty(_viewModel.CurrentVideoViewModel.Longtitude))
            {
                LocationMap.IsVisible = true;
                bool latParsed = double.TryParse(_viewModel.CurrentVideoViewModel.Latitude, NumberStyles.Any, CultureInfo.GetCultureInfo("en-US"), out double lat);
                bool lonParsed = double.TryParse(_viewModel.CurrentVideoViewModel.Longtitude, NumberStyles.Any, CultureInfo.GetCultureInfo("en-US"), out double lon);
                if (latParsed && lonParsed)
                {
                    Position position = new Position(lat, lon);
                    Pin      pin      = new Pin();
                    pin.Position = position;
                    pin.Label    = _viewModel.CurrentVideoViewModel.Location;
                    pin.Type     = PinType.SavedPin;
                    LocationMap.Pins.Add(pin);
                    LocationMap.MoveToRegion(MapSpan.FromCenterAndRadius(position, Distance.FromKilometers(2)));
                }
            }
            else
            {
                LocationMap.IsVisible = false;
            }
            _viewModel.IsBusy = false;
        }
Esempio n. 2
0
        public async Task <IActionResult> Video(int id, int childId = 0, string tagFilter = "", int sortBy = 1)
        {
            _progId = childId;
            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 (childId == 0 && userinfo.ViewChild > 0)
            {
                _progId = userinfo.ViewChild;
            }

            Progeny progeny = await _progenyHttpClient.GetProgeny(_progId);

            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))
            {
                _userIsProgenyAdmin = true;
                userAccessLevel     = (int)AccessLevel.Private;
            }

            VideoViewModel video = await _mediaHttpClient.GetVideoViewModel(id, userAccessLevel, sortBy, userinfo.Timezone);

            VideoViewModel model = new VideoViewModel();

            model.VideoId     = video.VideoId;
            model.VideoType   = video.VideoType;
            model.VideoTime   = video.VideoTime;
            model.ProgenyId   = video.ProgenyId;
            model.Progeny     = progeny;
            model.Owners      = video.Owners;
            model.VideoLink   = video.VideoLink;
            model.ThumbLink   = video.ThumbLink;
            model.AccessLevel = video.AccessLevel;
            model.Author      = video.Author;
            model.AccessLevelListEn[video.AccessLevel].Selected = true;
            model.AccessLevelListDa[video.AccessLevel].Selected = true;
            model.AccessLevelListDe[video.AccessLevel].Selected = true;
            model.CommentThreadNumber = video.CommentThreadNumber;
            model.Tags          = video.Tags;
            model.TagsList      = video.TagsList;
            model.Location      = video.Location;
            model.Latitude      = video.Latitude;
            model.Longtitude    = video.Longtitude;
            model.Altitude      = video.Altitude;
            model.VideoNumber   = video.VideoNumber;
            model.VideoCount    = video.VideoCount;
            model.PrevVideo     = video.PrevVideo;
            model.NextVideo     = video.NextVideo;
            model.CommentsList  = video.CommentsList;
            model.CommentsCount = video.CommentsList?.Count ?? 0;
            model.TagFilter     = tagFilter;
            model.SortBy        = sortBy;
            model.UserId        = HttpContext.User.FindFirst("sub")?.Value ?? _defaultUser;
            model.IsAdmin       = _userIsProgenyAdmin;
            if (video.Duration != null)
            {
                model.DurationHours   = video.Duration.Value.Hours.ToString();
                model.DurationMinutes = video.Duration.Value.Minutes.ToString();
                model.DurationSeconds = video.Duration.Value.Seconds.ToString();
            }
            if (model.VideoTime != null && progeny.BirthDay.HasValue)
            {
                PictureTime picTime = new PictureTime(progeny.BirthDay.Value,
                                                      TimeZoneInfo.ConvertTimeToUtc(model.VideoTime.Value, TimeZoneInfo.FindSystemTimeZoneById(userTimeZone)),
                                                      TimeZoneInfo.FindSystemTimeZoneById(progeny.TimeZone));
                model.VidTimeValid = true;
                model.VidTime      = model.VideoTime.Value.ToString("dd MMMM yyyy HH:mm"); // Todo: Replace string format with global constant or user defined value
                model.VidYears     = picTime.CalcYears();
                model.VidMonths    = picTime.CalcMonths();
                model.VidWeeks     = picTime.CalcWeeks();
                model.VidDays      = picTime.CalcDays();
                model.VidHours     = picTime.CalcHours();
                model.VidMinutes   = picTime.CalcMinutes();
            }
            else
            {
                model.VidTimeValid = false;
                model.VidTime      = "";
            }
            if (model.CommentsCount > 0)
            {
                foreach (Comment cmnt in model.CommentsList)
                {
                    UserInfo cmntAuthor = await _progenyHttpClient.GetUserInfoByUserId(cmnt.Author);

                    string authorImg  = cmntAuthor?.ProfilePicture ?? "";
                    string authorName = "";
                    if (!String.IsNullOrEmpty(authorImg))
                    {
                        if (!authorImg.ToLower().StartsWith("http"))
                        {
                            authorImg = _imageStore.UriFor(authorImg, "profiles");
                        }
                    }
                    else
                    {
                        authorImg = "/photodb/profile.jpg";
                    }
                    cmnt.AuthorImage = authorImg;

                    if (!String.IsNullOrEmpty(cmntAuthor.FirstName))
                    {
                        authorName = cmntAuthor.FirstName;
                    }
                    if (!String.IsNullOrEmpty(cmntAuthor.MiddleName))
                    {
                        authorName = authorName + " " + cmntAuthor.MiddleName;
                    }
                    if (!String.IsNullOrEmpty(cmntAuthor.LastName))
                    {
                        authorName = authorName + " " + cmntAuthor.LastName;
                    }

                    authorName = authorName.Trim();
                    if (String.IsNullOrEmpty(authorName))
                    {
                        authorName = cmntAuthor.UserName;
                        if (String.IsNullOrEmpty(authorName))
                        {
                            authorName = cmnt.DisplayName;
                        }
                    }

                    cmnt.DisplayName = authorName;
                }
            }
            if (model.IsAdmin)
            {
                model.ProgenyLocations = new List <Location>();
                model.ProgenyLocations = await _progenyHttpClient.GetProgenyLocations(model.ProgenyId, userAccessLevel);

                model.LocationsList = new List <SelectListItem>();
                if (model.ProgenyLocations.Any())
                {
                    foreach (Location loc in model.ProgenyLocations)
                    {
                        SelectListItem selectListItem = new SelectListItem();
                        selectListItem.Text  = loc.Name;
                        selectListItem.Value = loc.LocationId.ToString();
                        model.LocationsList.Add(selectListItem);
                    }
                }
            }

            return(View(model));
        }