コード例 #1
0
        public async Task <ActionResult <IEnumerable <byte[]> > > GetImages(
            Guid galleryId,
            [FromQuery] Pagination pagination,
            [FromQuery, BindRequired] bool thumb,
            [FromQuery, Range(1, 4096)] int?thumbWidth,
            [FromQuery, Range(1, 2160)] int?thumbHeight,
            [FromQuery] bool?keepAspectRatio)
        {
            // TODO: Very bad conditional validation, when fix this maybe take a look at fluent validation.
            if (thumb)
            {
                IList <string> conditionalValidationErrors = new List <string>();
                if (thumbWidth == null)
                {
                    conditionalValidationErrors.Add("You set 'thumb' to true, please also provide 'thumbWidth'");
                }
                if (thumbHeight == null)
                {
                    conditionalValidationErrors.Add("You set 'thumb' to true, please also provide 'thumbHeight'");
                }
                if (keepAspectRatio == null)
                {
                    conditionalValidationErrors.Add("You set 'thumb' to true, please also provide 'keepAspectRatio'");
                }

                if (conditionalValidationErrors.Count > 0)
                {
                    return(BadRequest(conditionalValidationErrors));
                }
            }

            Guid userId = new Guid(HttpContext.User.Identity.Name);

            if (await _galleryService.DoesGalleryExistAsync(galleryId) == false)
            {
                return(NotFound());
            }

            if (await _galleryService.IsGalleryOwnedByUserAsync(galleryId, userId) == false)
            {
                return(Unauthorized());
            }

            IEnumerable <byte[]> images = await _imageService.GetImagesInGalleryAsync(galleryId, pagination, thumb, thumbWidth, thumbHeight, keepAspectRatio);

            return(Ok(images));
        }
コード例 #2
0
        public async Task <ActionResult <GalleryDTO> > GetGallery(Guid id)
        {
            Guid userId = new Guid(HttpContext.User.Identity.Name);

            if (await _galleryService.DoesGalleryExistAsync(id) == false)
            {
                return(NotFound());
            }

            if (await _galleryService.IsGalleryOwnedByUserAsync(id, userId) == false)
            {
                return(Unauthorized());
            }

            GalleryDTO dto = await _galleryService.GetGalleryAsync(id);

            return(Ok(dto));
        }