Exemplo n.º 1
0
        public async Task <PhotoResponse> SaveAsync(Photo photo)
        {
            try
            {
                await _photoRepository.AddAsync(photo);

                await _unitOfWork.CompleteAsync();

                return(new PhotoResponse(photo));
            }
            catch (Exception ex)
            {
                return(new PhotoResponse($"Error occured when saving photo: {ex.Message}"));
            }
        }
Exemplo n.º 2
0
        public async Task <Response <bool> > Handle(UpdateUserPhotoCommand request, CancellationToken cancellationToken)
        {
            UploadedFileData uploadedData = await fileManager.AddFileAsync(request.Photo, FileTypeEnum.UserPhoto);

            Img userPhoto = await photoRepo.GetImgByUserIdAsync(request.Userid);

            // remove from hard
            fileManager.DeleteFile(userPhoto.Path);
            // remove from db
            await photoRepo.Remove(userPhoto);

            Img newImg = new Img {
                UserId = request.Userid,
                Url    = uploadedData.Url,
                Path   = uploadedData.Path
            };
            await photoRepo.AddAsync(newImg);

            return(Response.Ok());
        }