public async Task DeletePhoto(string uploadsFolderPath, Photo photo)
        {
            var filePath = Path.Combine(uploadsFolderPath, photo.FileName);

            photoRepository.Remove(photo);
            await unitOfWork.CompleteAsync();

            photoStorage.DeletePhoto(filePath);
        }
Exemplo n.º 2
0
        public async Task <Photo> DeletePhoto(Photo photo, string targetFilePath)
        {
            // Remove photo file.
            var vehicleId     = photo.VehicleId;
            var photoFilePath = Path.Combine(targetFilePath, FilePaths.VehiclePhotosDirectory, vehicleId.ToString(),
                                             photo.FileName);

            _photoStorage.DeletePhoto(photoFilePath);

            // Remove photo data from database.
            _unitOfWork.Photos.Remove(photo);
            await _unitOfWork.CompleteAsync();

            return(photo);
        }
Exemplo n.º 3
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var user = await _context.Users
                           .Include(u => u.Photos)
                           .SingleOrDefaultAsync(u => u.UserName == _userAccessor.GetCurrentUsername());

                var photo = user.Photos.FirstOrDefault(p => p.Id == request.Id);

                if (photo == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { Photo = "Not found" });
                }

                if (photo.IsMain)
                {
                    throw new RestException(HttpStatusCode.BadRequest, new { Photo = "You cannot delete your main photo" });
                }

                var result = _photoStorage.DeletePhoto(photo.Id);

                if (result == null)
                {
                    throw new Exception("Problem deleting photo");
                }

                user.Photos.Remove(photo);

                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }

                throw new Exception("Problem saving changes");
            }
Exemplo n.º 4
0
 public async Task RemovePhoto(Game game, Photo photo, string uploadsFolderPath)
 {
     photoStorage.DeletePhoto(uploadsFolderPath, photo.FileName);
     game.Photos.Remove(photo);
     await unitOfWork.CompleteAsync();
 }