Beispiel #1
0
        public async Task <ActionResult> SetMainPhoto(int productId, int photoId)
        {
            var spec = new PhotosOfProductSpecification(productId);

            var photos = await _photosRepo.ListAsync(spec);

            var mainPhoto = photos.FirstOrDefault(x => x.Id == photoId);

            if (mainPhoto.IsMain)
            {
                return(BadRequest("This is already Main Photo"));
            }

            var currentMainPhoto = photos.FirstOrDefault(x => x.IsMain);

            if (currentMainPhoto != null)
            {
                currentMainPhoto.IsMain = false;
            }

            mainPhoto.IsMain = true;

            if (await _photosRepo.SaveAllAsync())
            {
                return(NoContent());
            }

            return(BadRequest("Failed to set Main Photo"));
        }
Beispiel #2
0
        public async Task <ActionResult <IReadOnlyList <PhotoDto> > > GetPhotosOfProductAsync(int productId)
        {
            var spec = new PhotosOfProductSpecification(productId);

            return(_mapper.Map <PhotoDto[]>(await _photosRepo.ListAsync(spec)));
        }