예제 #1
0
        public OwnedAlbum Album(string bizId, int skip)
        {
            var    totalCount = _db.Photos.Where(x => x.UserId == bizId).ToList().Count();
            var    converted  = Convert.ToDouble(totalCount);
            double result     = converted / 12;
            double pages      = Math.Ceiling(result);
            var    photos     = _db.Photos.Where(x => x.UserId == bizId).Skip(skip).Take(12).ToList();

            List <OwnedPhoto> pics = new List <OwnedPhoto>();

            foreach (var item in photos)
            {
                pics.Add(new OwnedPhoto
                {
                    HasPrice = item.HasPrice,
                    PhotoId  = item.Id,
                    PhotoUrl = item.Url,
                    Price    = item.Price,
                    Title    = item.Title,
                });
            }

            OwnedAlbum album = new OwnedAlbum
            {
                CurrentPhotos = pics,
                TotalPhotos   = totalCount,
                Pages         = Convert.ToInt32(pages),
            };

            return(album);
        }
예제 #2
0
        public OwnedAlbum OwnedPhotoAlbum([FromBody] GetAlbum model)
        {
            var userId = _http.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier) ?? "00000000-0000-0000-0000-000000000000";

            var authenticated = _http.HttpContext.User.Identity.IsAuthenticated;

            if (model == null)
            {
                return(null);
            }

            if (model.UserId != userId || !authenticated)
            {
                return(null);
            }

            var    totalCount = _db.Photos.Where(x => x.UserId == model.UserId).ToList().Count();
            var    converted  = Convert.ToDouble(totalCount);
            double result     = converted / 24;
            double pages      = Math.Ceiling(result);
            var    photos     = _db.Photos.Where(x => x.UserId == model.UserId).Skip(model.Skip).Take(24);

            List <OwnedPhoto> pics = new List <OwnedPhoto>();

            foreach (var item in photos)
            {
                pics.Add(new OwnedPhoto
                {
                    HasPrice = item.HasPrice,
                    PhotoId  = item.Id,
                    PhotoUrl = item.Url,
                    Price    = item.Price,
                    Title    = item.Title,
                });
            }

            OwnedAlbum album = new OwnedAlbum
            {
                CurrentPhotos = pics,
                TotalPhotos   = totalCount,
                Pages         = Convert.ToInt32(pages),
            };

            return(album);
        }