Пример #1
0
        public async Task <ActionResult> DeleteImage(long placeId, int imageId)
        {
            var place = await _context.Places
                        .Include(p => p.Images)
                        .FirstOrDefaultAsync(p => p.ID == placeId);

            if (place == null || place?.Images == null)
            {
                return(NotFound());
            }

            var image = place.Images.FirstOrDefault(p => p?.ID == imageId);

            if (image == null)
            {
                return(NotFound());
            }

            _imageUploadService.RemoveImage(image.URI);

            _context.PlaceImages.Remove(image);
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Пример #2
0
        public async Task <IActionResult> DeleteCurrentUserAvatar()
        {
            var user = await _context.Users.FindAsync(CurrentUserId);

            if (user == null || user?.AvatarURI == null)
            {
                return(NotFound());
            }

            _imageUploadService.RemoveImage(user.AvatarURI);

            user.AvatarURI = null;

            await _context.SaveChangesAsync();

            return(NoContent());
        }