Esempio n. 1
0
        public async Task <PicturePageViewModel> GetPicturePage(int pageSize, int id, int progenyId, int userAccessLevel, int sortBy, string tagFilter, string timeZone)
        {
            var    currentContext = _httpContextAccessor.HttpContext;
            string accessToken    = await currentContext.GetTokenAsync(OpenIdConnectParameterNames.AccessToken).ConfigureAwait(false);

            if (!string.IsNullOrWhiteSpace(accessToken))
            {
                _httpClient.SetBearerToken(accessToken);
            }
            else
            {
                accessToken = await GetNewToken();

                _httpClient.SetBearerToken(accessToken);
            }

            string pageApiPath = "/api/pictures/page?pageSize=" + pageSize + "&pageIndex=" + id + "&progenyId=" + progenyId + "&accessLevel=" + userAccessLevel + "&sortBy=" + sortBy;

            if (tagFilter != "")
            {
                pageApiPath = pageApiPath + "&tagFilter=" + tagFilter;
            }

            var resp = await _httpClient.GetAsync(pageApiPath);

            string pageResponseString = await resp.Content.ReadAsStringAsync();

            PicturePageViewModel model = JsonConvert.DeserializeObject <PicturePageViewModel>(pageResponseString);

            if (timeZone != "")
            {
                foreach (Picture pic in model.PicturesList)
                {
                    if (pic.PictureTime.HasValue)
                    {
                        pic.PictureTime = TimeZoneInfo.ConvertTimeFromUtc(pic.PictureTime.Value,
                                                                          TimeZoneInfo.FindSystemTimeZoneById(timeZone));
                    }
                }
            }

            return(model);
        }
        public PicturePage(string pictureUrl)
        {
            InitializeComponent();

            BindingContext = new PicturePageViewModel(pictureUrl);
        }
Esempio n. 3
0
        public async Task <IActionResult> Index(int id = 1, int pageSize = 8, int childId = 0, int sortBy = 1, string tagFilter = "")
        {
            _progId = childId;
            if (id < 1)
            {
                id = 1;
            }
            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;
            }
            else
            {
                _progId = childId;
            }

            if (_progId == 0)
            {
                _progId = Constants.DefaultChildId;
            }


            Progeny progeny = await _progenyHttpClient.GetProgeny(_progId);

            if (progeny == null)
            {
                progeny             = new Progeny();
                progeny.Admins      = Constants.AdminEmail;
                progeny.Id          = 0;
                progeny.BirthDay    = DateTime.UtcNow;
                progeny.Name        = "No Children in the Database";
                progeny.NickName    = "No default child defined";
                progeny.TimeZone    = Constants.DefaultTimezone;
                progeny.PictureLink = Constants.ProfilePictureUrl;
            }

            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;
            }


            PicturePageViewModel model = await _mediaHttpClient.GetPicturePage(pageSize, id, progeny.Id, userAccessLevel, sortBy, tagFilter, userTimeZone);

            model.Progeny  = progeny;
            model.IsAdmin  = _userIsProgenyAdmin;
            model.SortBy   = sortBy;
            model.PageSize = pageSize;
            foreach (Picture pic in model.PicturesList)
            {
                if (!pic.PictureLink600.StartsWith("https://"))
                {
                    pic.PictureLink600 = _imageStore.UriFor(pic.PictureLink600);
                }
            }

            return(View(model));
        }
Esempio n. 4
0
        public async Task <IActionResult> PageMobile([FromQuery] int pageSize = 8, [FromQuery] int pageIndex = 1, [FromQuery] int progenyId = Constants.DefaultChildId, [FromQuery] int accessLevel = 5, [FromQuery] string tagFilter = "", [FromQuery] int sortBy = 1)

        {
            if (pageIndex < 1)
            {
                pageIndex = 1;
            }

            List <Picture> allItems;

            if (!string.IsNullOrEmpty(tagFilter))
            {
                allItems = await _dataService.GetPicturesList(Constants.DefaultChildId); // await _context.PicturesDb.AsNoTracking().Where(p => p.ProgenyId == 2 && p.AccessLevel >= 5 && p.Tags.ToUpper().Contains(tagFilter.ToUpper())).OrderBy(p => p.PictureTime).ToListAsync();

                allItems = allItems.Where(p => p.AccessLevel >= 5 && p.Tags.ToUpper().Contains(tagFilter.ToUpper())).OrderBy(p => p.PictureTime).ToList();
            }
            else
            {
                allItems = await _dataService.GetPicturesList(2); // await _context.PicturesDb.AsNoTracking().Where(p => p.ProgenyId == 2 && p.AccessLevel >= 5).OrderBy(p => p.PictureTime).ToListAsync();

                allItems = allItems.Where(p => p.AccessLevel >= 5).OrderBy(p => p.PictureTime).ToList();
            }

            if (sortBy == 1)
            {
                allItems.Reverse();
            }

            int           pictureCounter = 1;
            int           picCount       = allItems.Count;
            List <string> tagsList       = new List <string>();

            foreach (Picture pic in allItems)
            {
                if (sortBy == 1)
                {
                    pic.PictureNumber = picCount - pictureCounter + 1;
                }
                else
                {
                    pic.PictureNumber = pictureCounter;
                }

                pictureCounter++;
                if (!String.IsNullOrEmpty(pic.Tags))
                {
                    List <string> pvmTags = pic.Tags.Split(',').ToList();
                    foreach (string tagstring in pvmTags)
                    {
                        if (!tagsList.Contains(tagstring.TrimStart(' ', ',').TrimEnd(' ', ',')))
                        {
                            tagsList.Add(tagstring.TrimStart(' ', ',').TrimEnd(' ', ','));
                        }
                    }
                }
            }

            var itemsOnPage = allItems
                              .Skip(pageSize * (pageIndex - 1))
                              .Take(pageSize)
                              .ToList();

            foreach (Picture pic in itemsOnPage)
            {
                pic.Comments = await _dataService.GetCommentsList(pic.CommentThreadNumber); // await _context.CommentsDb.AsNoTracking().Where(c => c.CommentThreadNumber == pic.CommentThreadNumber).ToListAsync();

                if (!pic.PictureLink.ToLower().StartsWith("http"))
                {
                    pic.PictureLink = _imageStore.UriFor(pic.PictureLink);
                }
                if (!pic.PictureLink1200.ToLower().StartsWith("http"))
                {
                    pic.PictureLink1200 = _imageStore.UriFor(pic.PictureLink1200);
                }
                if (!pic.PictureLink600.ToLower().StartsWith("http"))
                {
                    pic.PictureLink600 = _imageStore.UriFor(pic.PictureLink600);
                }
            }
            PicturePageViewModel model = new PicturePageViewModel();

            model.PicturesList = itemsOnPage;
            model.TotalPages   = (int)Math.Ceiling(allItems.Count / (double)pageSize);
            model.PageNumber   = pageIndex;
            model.SortBy       = sortBy;
            model.TagFilter    = tagFilter;
            string tList = "";

            foreach (string tstr in tagsList)
            {
                tList = tList + tstr + ",";
            }
            model.TagsList = tList.TrimEnd(',');

            return(Ok(model));
        }