Exemple #1
0
        public async Task <ActionResult> SetMainPhoto(int partId, int photoId)
        {
            var spec = new PhotosOfPartSpecification(partId);

            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"));
        }
Exemple #2
0
        public async Task <IReadOnlyList <PartPhotoDto> > GetPhotosOfPartAsync(int partId)
        {
            var spec = new PhotosOfPartSpecification(partId);

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