public async Task <IActionResult> DeletePhoto(int userId, int idPhoto)
        {
            if (!IsUserAuthorized(userId))
            {
                return(Unauthorized());
            }

            var dbUser = await _datingRepository.GetUser(userId);

            if (!dbUser.Photos.Any(p => p.Id == idPhoto))
            {
                return(Unauthorized());
            }

            var dbPhoto = await _datingRepository.GetPhoto(idPhoto);

            if (dbPhoto.IsMain)
            {
                return(BadRequest("You cannot delete yout main photo!"));
            }

            if (dbPhoto.PublicId != null)
            {
                var deleteParams = new DeletionParams(dbPhoto.PublicId);
                var result       = _cloudinary.Destroy(deleteParams);
                if (result.Result == "ok")
                {
                    _datingRepository.Delete(dbPhoto);
                }
            }
            else
            {
                _datingRepository.Delete(dbPhoto);
            }

            if (await _datingRepository.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to delete the photo"));
        }
예제 #2
0
        public async Task <IActionResult> DeletePhoto(int userId, int id)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var user = await _repo.GetUser(userId);

            if (!user.Photos.Any(P => P.Id == id))
            {
                return(Unauthorized());
            }

            var photoFromRepo = await _repo.GetPhoto(id);

            if (photoFromRepo.IsMain)
            {
                return(BadRequest("You cannot delete your main photo"));
            }

            if (string.IsNullOrWhiteSpace(photoFromRepo.PublicId))
            {
                _repo.Delete(photoFromRepo);
            }
            else
            {
                var deleteParams = new DeletionParams(photoFromRepo.PublicId);
                var result       = _cloudinary.Destroy(deleteParams);
                if (string.Equals(result.Result, "ok", StringComparison.OrdinalIgnoreCase))
                {
                    _repo.Delete(photoFromRepo);
                }
            }

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to delete the photo"));
        }
        public async Task <IActionResult> DeletePhoto(int userId, int id)
        {
            //handle error section
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            var user = await _repo.GetUser(userId);

            //check this user had photo with id
            if (!user.Photos.Any(p => p.Id == id))
            {
                return(Unauthorized()); // status code 401
            }
            var photoFromRepo = await _repo.GetPhoto(id);

            if (photoFromRepo.IsMain == true)
            {
                return(BadRequest("You cannot delete your main photo"));
            }
            //end handle error section

            if (photoFromRepo.PublicId != null) // Seed Data(Generate random pic) has not publicID, so don't use cloudinary
            {
                var deletionParams = new DeletionParams(photoFromRepo.PublicId);
                var result         = _cloudinary.Destroy(deletionParams); // return ok if success check on document
                if (result.Result == "ok")
                {
                    _repo.Delete(photoFromRepo);
                }
            }
            else     // delete seed data
            {
                _repo.Delete(photoFromRepo);
            }

            if (await _repo.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("Failed to delete the photo"));
        }
        public async Task <IActionResult> DeletePhoto(int userId, int id)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {  // Checks so the user wanting to update is the user that's logged in
                return(Unauthorized());
            }
            var user = await _repo.GetUser(userId);

            if (!user.Photos.Any(p => p.Id == id))
            {
                return(Unauthorized());
            }
            var photoFromRepo = await _repo.GetPhoto(id);

            if (photoFromRepo.IsMain)
            {
                return(BadRequest("You cannot delete your main photo"));
            }
            if (photoFromRepo.PublicId != null)
            {
                var deleteParams = new DeletionParams(photoFromRepo.PublicId);

                var result = _cloudinary.Destroy(deleteParams);

                if (result.Result == "ok")
                {
                    _repo.Delete(photoFromRepo);
                }
            }

            if (photoFromRepo.PublicId == null)
            {
                _repo.Delete(photoFromRepo);
            }

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to delete the photo"));
        }
예제 #5
0
        public async Task <IActionResult> DeleteProduct(int id)
        {
            var selectedProduct = await _unitOfWork.Product.GetAsync(id);

            if (selectedProduct == null)
            {
                return(BadRequest("Product for that Id doesn't exist"));
            }

            var photos = selectedProduct.Photos?.ToList();

            if (photos != null && photos.Select(p => p.PublicId).Any())
            {
                foreach (var photo in photos)
                {
                    if (photo.PublicId != null)
                    {
                        var deleteParams = new DeletionParams(photo.PublicId);

                        var result = _cloudinary.Destroy(deleteParams);

                        if (result.Result == "ok")
                        {
                            _unitOfWork.Photo.Delete(photo);
                        }
                    }
                    else
                    {
                        _unitOfWork.Photo.Delete(photo);
                    }
                }
            }
            _unitOfWork.Product.Delete(selectedProduct);


            if (!await _unitOfWork.SaveAsync())
            {
                return(BadRequest("Something went wrong during deleting product"));
            }
            //"Product deleted successfully" problem with parsing , ui try parse this to JSON instead of keep this as text
            return(NoContent());
        }
예제 #6
0
        public async Task <IActionResult> DeletePhoto(int userId, int id)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            var user = await _userRepo.GetUserAsync(userId);

            if (!user.Photos.Any(p => p.Id == id))
            {
                return(Unauthorized());
            }

            var photoFromRepo = user.Photos.FirstOrDefault(p => p.Id == id);//await _userRepo.GetPhotoAsync(id);

            if (photoFromRepo.IsMain)
            {
                return(BadRequest("You cannot delete your main photo"));
            }

            if (photoFromRepo.PublicID != null)
            {
                DeletionParams param  = new DeletionParams(photoFromRepo.PublicID);
                var            result = _cloudinary.Destroy(param);

                if (result.Result == "ok")
                {
                    _userRepo.Delete(photoFromRepo);
                }
            }
            else
            {
                _userRepo.Delete(photoFromRepo);
            }

            if (await _userRepo.SaveAllAsync())
            {
                return(Ok());
            }

            return(BadRequest("Failed to delete photo."));
        }
예제 #7
0
        public async Task <IActionResult> DeletePhoto(int userId, int id)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var userFromRepo = await _repo.GetUser(userId);

            if (!userFromRepo.Photos.Any(p => p.Id == id))
            {
                return(Unauthorized());
            }

            var photoFromRepo = await _repo.GetPhoto(id);

            if (photoFromRepo.IsMain)
            {
                return(BadRequest("You cant delete your main photo"));
            }

            if (!string.IsNullOrEmpty(photoFromRepo.PublicId))
            {
                var deleteParams = new DeletionParams(photoFromRepo.PublicId);
                var destroyImage = _cloudinary.Destroy(deleteParams);
                if (destroyImage.Result.Equals("ok"))
                {
                    _repo.Delete(photoFromRepo);
                }
            }
            if (string.IsNullOrEmpty(photoFromRepo.PublicId))
            {
                _repo.Delete(photoFromRepo);
            }

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to delete the photo"));
        }
예제 #8
0
        public async Task <IActionResult> DeletePhoto(int userId, int id)
        {
            if (userId != Convert.ToInt32(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var user = await _repo.GetUser(userId);

            if (!user.Photos.Any(x => x.Id == id))
            {
                return(Unauthorized());
            }

            var photoFromRepo = await _photoRepo.GetPhoto(id);

            if (photoFromRepo.IsMain)
            {
                return(BadRequest("Cannot delete the main photo"));
            }

            if (photoFromRepo.PublicId != null)
            {
                var deleteParam = new DeletionParams(photoFromRepo.PublicId);
                var result      = _cloudinary.Destroy(deleteParam);
                if (result.Result == "ok")
                {
                    _repo.Delete(photoFromRepo);
                }
            }
            else
            {
                _repo.Delete(photoFromRepo);
            }

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Photo cannot be deleted"));
        }
예제 #9
0
        public async Task <IActionResult> DeletePhoto(int userId, int photoId)
        {
            if (!isAuthorized(userId))
            {
                return(Unauthorized());
            }

            var photoFromRepo = await _repo.GetPhoto(photoId);

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

            if (photoFromRepo.IsMain)
            {
                return(BadRequest("You cannot delete the main photo"));
            }

            // in case photo not in cloudinary
            if (photoFromRepo.PublicId == null)
            {
                var deleteParams = new DeletionParams(photoFromRepo.PublicId);

                var result = _cloudinary.Destroy(deleteParams);

                if (result.Result == "ok")
                {
                    _repo.Delete(photoFromRepo);
                }
            }
            else
            {
                _repo.Delete(photoFromRepo);
            }
            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Falied to delete the photo"));
        }
예제 #10
0
        public async Task <IActionResult> DeletePhoto(int userId, int id)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var userFormRepo = await _repo.GetUser(userId);

            if (!userFormRepo.Photos.Any(p => p.Id == id))
            {
                return(Unauthorized());
            }

            var photoFormRepo = await _repo.GetPhoto(id);

            if (photoFormRepo.IsMain)
            {
                return(BadRequest("You can't remove your Main photo"));
            }

            if (photoFormRepo.PublicId == null)
            {
                _repo.Delete(photoFormRepo);
            }
            else
            {
                var deletionParams = new DeletionParams(photoFormRepo.PublicId);
                var result         = _cloudinary.Destroy(deletionParams);
                if (result.Result == "ok")
                {
                    _repo.Delete(photoFormRepo);
                }
            }

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to remove photo"));
        }
예제 #11
0
        public async Task <IActionResult> DeletePhoto(int imovelId, int id)
        {
            // if (imovelId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            // return Unauthorized();

            var imovel = await _repo.GetImovel(imovelId);

            if (!imovel.Fotos.Any(p => p.Id == id))
            {
                return(Unauthorized());
            }
            var photoFromRepo = await _repo.GetPhoto(id);

            if (photoFromRepo.Principal)
            {
                return(BadRequest("Foto principal não pode ser apagada!"));
            }

            if (photoFromRepo.Principal != null)
            {
                var deleteParams = new DeletionParams(photoFromRepo.PublicId);

                var result = _cloudinary.Destroy(deleteParams);

                if (result.Result == "ok")
                {
                    _repo.Delete(photoFromRepo);
                }
            }

            if (photoFromRepo.PublicId == null)
            {
                _repo.Delete(photoFromRepo);
            }

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Falha ao deletar a foto!"));
        }
        public async Task <IActionResult> Sil(int kullaniciNo, int id)
        {
            return(await KullaniciVarsaCalistir <IActionResult>(async() =>
            {
                if (kullaniciNo != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
                {
                    Unauthorized();
                }
                var dbdekiKayit = await repo.FotografBulAsync(id);
                if (dbdekiKayit == null)
                {
                    return NotFound("Fotoğraf bulunamadı!");
                }

                if (dbdekiKayit.ProfilFotografi)
                {
                    return BadRequest("Asıl fotoğrafı silemezsiniz!");
                }
                if (dbdekiKayit.PublicId != null)
                {
                    var deleteParams = new DeletionParams(dbdekiKayit.PublicId);
                    var result = cloudinary.Destroy(deleteParams);
                    if (result.Result == "ok")
                    {
                        repo.Sil(dbdekiKayit);
                    }
                }
                if (dbdekiKayit.PublicId == null)
                {
                    repo.Sil(dbdekiKayit);
                }

                if (await repo.KaydetAsync())
                {
                    return Ok();
                }
                else
                {
                    return BadRequest("Fotoğraf silinemedi");
                }
            }));
        }
예제 #13
0
        public async Task <IActionResult> DeletePhoto(int userId, int id)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var user = await _repository.GetUser(userId);

            if (!user.Photos.Any(p => p.Id == id))
            {
                return(Unauthorized());
            }

            var photoFromRepo = await _repository.GetPhoto(id);

            if (photoFromRepo.IsMain)
            {
                return(BadRequest("To zdjęcie jest ustawione jako profilowe i nie można go usunąć"));
            }

            if (photoFromRepo.public_id != null)
            {
                var deleteParams = new DeletionParams(photoFromRepo.public_id);
                var result       = _cloudinary.Destroy(deleteParams);

                if (result.Result == "ok")
                {
                    _repository.Delete(photoFromRepo);
                }
            }
            else
            {
                _repository.Delete(photoFromRepo);
            }

            if (await _repository.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("Nie udało się usunąć zdjęcia"));
        }
예제 #14
0
        public async Task <IActionResult> DeletePhoto(int userId, int id)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var user = await _repository.GetUser(userId);

            if (!user.Photos.Any(p => p.Id == id))
            {
                return(Unauthorized());
            }

            var photoFromRepo = await _repository.GetPhoto(id);

            if (photoFromRepo.isMain)
            {
                return(BadRequest("This is already your main photo"));
            }

            if (photoFromRepo.PublicId != null)
            {
                var deleteParams = new DeletionParams(photoFromRepo.PublicId);
                var result       = _cloudinary.Destroy(deleteParams);
                if (result.Result == "ok")
                {
                    _repository.Delete(photoFromRepo);
                }
            }
            else if (photoFromRepo.PublicId != null)
            {
                _repository.Delete(photoFromRepo);
            }

            if (await _repository.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to delete the photo"));
        }
예제 #15
0
        public async Task <IActionResult> DeletePhoto(int userid, int id)
        {
            if (userid != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var user = await _repository.GetUser(userid);

            if (!user.Photos.Any(p => p.Id == id))
            {
                return(BadRequest("There is no photo with the id you provided"));
            }

            var photoFromRepo = await _repository.GetPhoto(id);

            if (photoFromRepo.IsMain)
            {
                return(BadRequest("Main Photo can't be deleted"));
            }

            if (photoFromRepo.PublicId != null)
            {
                var delParams    = new DeletionParams(photoFromRepo.PublicId);
                var resFromCloud = _cloudinary.Destroy(delParams);
                if (resFromCloud.Result == "ok")
                {
                    _repository.Delete(photoFromRepo);
                }
            }
            else
            {
                _repository.Delete(photoFromRepo);
            }

            if (await _repository.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Unable to delete the photo"));
        }
예제 #16
0
        public async Task <IActionResult> DeletePhoto(int userId, int id)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var photoFromRepo = await _repo.GetPhoto(id);

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

            if (photoFromRepo.IsMain)
            {
                return(BadRequest("You cannot delete your main photo"));
            }

            if (photoFromRepo.PublicId != null)
            {
                var deleteParams = new DeletionParams(photoFromRepo.PublicId);
                var result       = _cloudinary.Destroy(deleteParams);

                if (result.Result == "ok")
                {
                    _repo.Delete(photoFromRepo);
                }
            }

            if (photoFromRepo.PublicId == null)
            {
                _repo.Delete(photoFromRepo);
            }

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to delete the photo"));
        }
예제 #17
0
        public async Task <IActionResult> DeletePhoto(int userId, int id)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized()); // sprawdzamy czy użytkownik jest bieżącym użytkownikiem
            }
            var user = await _repo.GetUser(userId);

            if (!user.Photos.Any(p => p.Id == id))
            {
                return(Unauthorized()); // jeśli, żadne id zdjęcia nie pasuje do tego w tabeli zdjęcia zwracamy nieautoryzowany dostęp
            }
            var photoFromRepo = await _repo.GetPhoto(id);

            if (photoFromRepo.IsMain)
            {
                return(BadRequest("You cannot delete your main photo")); // sprawdzamy czy zdjęcie jest już głównym
            }
            if (photoFromRepo.PublicId != null)
            {
                var deleteParams = new DeletionParams(photoFromRepo.PublicId); // parametry, czyli publicID

                var result = _cloudinary.Destroy(deleteParams);                // rezultat z serwisu cloudinary

                if (result.Result == "ok")
                {
                    _repo.Delete(photoFromRepo); // jeśli się powiedzie to usuwamy
                }
            }

            if (photoFromRepo.PublicId == null) // dla zdjęć, które nie są w serwisie cloudinary
            {
                _repo.Delete(photoFromRepo);
            }

            if (await _repo.SaveAll()) // i zapisujemy zmiany
            {
                return(Ok());
            }

            return(BadRequest("Failed to delete the photo"));
        }
        public async Task <IActionResult> DeletePhoto(int id)
        {
            var photoFromRepo = await _repo.GetPhoto(id);

            var deleteParams = new DeletionParams(photoFromRepo.PublicId);

            var result = _cloudinary.Destroy(deleteParams);

            if (result.Result == "ok")
            {
                _repo.Delete(photoFromRepo);
            }

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to delete the photo"));
        }
예제 #19
0
        public void TestDestroyRaw()
        {
            RawUploadParams uploadParams = new RawUploadParams()
            {
                File = new FileDescription(m_testImagePath)
            };

            RawUploadResult uploadResult = m_cloudinary.Upload(uploadParams);

            Assert.NotNull(uploadResult);

            DeletionParams destroyParams = new DeletionParams(uploadResult.PublicId)
            {
                ResourceType = ResourceType.Raw
            };

            DeletionResult destroyResult = m_cloudinary.Destroy(destroyParams);

            Assert.AreEqual("ok", destroyResult.Result);
        }
예제 #20
0
        public async Task <bool> DeleteVideosAsync(List <string> publicIds)
        {
            var result = new DeletionResult();

            foreach (var publicId in publicIds)
            {
                var deleteParams = new DeletionParams(publicId)
                {
                    ResourceType = ResourceType.Video
                };
                result = await _cloudinary.DestroyAsync(deleteParams);

                if (result.Error != null)
                {
                    throw new Exception(ExceptionMessages.VideoDeleteError);
                }
            }

            return(result.Result == "ok");
        }
예제 #21
0
        public async Task <IActionResult> RejectPhoto(int photoId)
        {
            var photo = await _context.Photos.IgnoreQueryFilters().SingleOrDefaultAsync(p => p.Id == photoId);

            if (photo.PublicId != null)
            {
                var deleteParams = new DeletionParams(photo.PublicId);

                var deleteResult = _cloudinary.Destroy(deleteParams);

                if (deleteResult.Result == "ok")
                {
                    _context.Photos.Remove(photo);
                }
            }

            await _context.SaveChangesAsync();

            return(Ok());
        }
예제 #22
0
        public async Task <IActionResult> DeletePhotoForUser(int userId, int id)
        {
            //authorization
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            //checking if the user trying to set the photo is among from his own photo.
            var userFromRepo = await _repo.GetUser(userId);

            if (!userFromRepo.Photos.Any(p => p.Id == id))
            {
                return(BadRequest("Photo could not found"));
            }

            //checking if the photo is already a main photo.
            var photoFromRepo = await _repo.GetPhoto(id);

            if (photoFromRepo.IsMain)
            {
                return(BadRequest("Cannot delete main photo"));
            }
            if (photoFromRepo.PublicId != null)
            {
                var deleteParams = new DeletionParams(photoFromRepo.PublicId);
                var result       = _cloudinary.Destroy(deleteParams);
                if (result.Result == "ok")
                {
                    _repo.Delete(photoFromRepo);
                }
            }

            _repo.Delete(photoFromRepo);

            if (await _repo.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("could not delete photo"));
        }
        public async Task <IActionResult> DeletePost(int userId, int postId)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            // Get post from the repo
            var postFromRepo = await _recipeRepo.GetPost(postId);

            if (postFromRepo.UserId == userId)
            {
                foreach (var photo in postFromRepo.PostPhoto)
                {
                    var photoFromRepo = await _recipeRepo.GetPostPhoto(photo.PostPhotoId);

                    if (photoFromRepo.PublicId != null)
                    {
                        var deleteParams = new DeletionParams(photoFromRepo.PublicId);

                        var result = _cloudinary.Destroy(deleteParams);

                        if (result.Result == "ok")
                        {
                            _recipeRepo.Delete(photoFromRepo);
                        }
                    }
                }

                _recipeRepo.Delete(postFromRepo);

                if (await _recipeRepo.SaveAll())
                {
                    return(Ok("Successfully deleted post"));
                }

                throw new Exception($"Deleting post {postId} failed on save");
            }

            return(Unauthorized());
        }
예제 #24
0
        public async Task <IActionResult> DeletePhoto(int userId, int id)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var user = await _dating.GetUser(userId);

            if (!user.Photos.Any(u => u.Id == id))
            {
                return(Unauthorized());
            }

            var PhotoFromRepo = await _dating.GetPhoto(id);

            if (PhotoFromRepo.IsMain)
            {
                return(BadRequest("you can not delete the main photo"));
            }

            if (PhotoFromRepo.PublicID != null)
            {
                var deletionparam = new DeletionParams(PhotoFromRepo.PublicID);
                var result        = _cloudinary.Destroy(deletionparam);
                if (result.Result == "ok")
                {
                    _dating.Delete(PhotoFromRepo);
                }
            }
            if (PhotoFromRepo.PublicID == null)
            {
                _dating.Delete(PhotoFromRepo);
            }

            if (await _dating.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest());
        }
        public async Task <IActionResult> DeletePhoto(string userId, int photoId)
        {
            if (userId != User.FindFirst(ClaimTypes.NameIdentifier).Value)
            {
                return(Unauthorized());
            }

            var user = await _unitofWork.PartnerFinder.GetUser(userId);

            if (!user.Photos.Any(p => p.Id == id))
            {
                return(BadRequest("this photo is not present in this user profile"));
            }

            var photoFromRepo = await _unitofWork.PhotoRepo.GetPhoto(photoId);

            if (photoFromRepo.IsMain)
            {
                return(BadRequest("not able to delete main photo"));
            }
            if (photoFromRepo.PublicId != null)
            {
                var deleteParams = new DeletionParams(photoFromRepo.PublicId);
                var deleteresult = _cloudinary.Destroy(deleteParams);
                if (deleteresult.Result == "ok")
                {
                    _unitofWork.PhotoRepo.Delete(photoFromRepo);
                }
            }
            if (photoFromRepo.PublicId == null)
            {
                _unitofWork.PhotoRepo.Delete(photoFromRepo);
            }
            var result = await _unitofWork.Save();

            if (result == 0)
            {
                return(StatusCode(500, "saving probem"));
            }
            return(Ok("delete photo"));
        }
예제 #26
0
        public async Task <IActionResult> DeletePhoto(int userId, int photoId)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            var userFromRepo = await _repo.GetUser(userId);

            if (!userFromRepo.Photos.Any(p => p.Id == photoId))
            {
                return(Unauthorized());
            }

            var photoFromRepo = await _repo.GetPhoto(photoId);

            if (photoFromRepo.IsMain)
            {
                return(BadRequest("Main photo cannot be deleted!"));
            }

            if (photoFromRepo.PublicId != null)
            {
                var deletionParams = new DeletionParams(photoFromRepo.PublicId);
                var response       = _cloudinary.Destroy(deletionParams);

                if (response.Result.ToLower() == "ok")
                {
                    _repo.Delete(photoFromRepo);
                }
            }
            else
            {
                _repo.Delete(photoFromRepo);
            }
            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to delete the photo"));
        }
예제 #27
0
        public async Task <IActionResult> DeletePhoto(int userId, int id)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            var user = await _unitOfWork.userService.GetUser(userId);

            if (!user.Photos.Any(p => p.Id == id))
            {
                return(Unauthorized());
            }
            var photoFromRepo = await _unitOfWork.userService.GetPhoto(id);

            if (photoFromRepo.IsMain)
            {
                return(BadRequest("Can't delete main photo!"));
            }
            if (photoFromRepo.PublicId != null)
            {
                var deleteParams = new DeletionParams(photoFromRepo.PublicId);
                var result       = _cloudinary.Destroy(deleteParams);
                if (result.Result == "ok")
                {
                    _unitOfWork.userService.Delete(photoFromRepo);
                }
                else
                {
                    return(BadRequest("Something went wrong!\nPlease try again later"));
                }
            }
            if (photoFromRepo.PublicId == null)
            {
                _unitOfWork.userService.Delete(photoFromRepo);
            }
            if (await _unitOfWork.Complete())
            {
                return(Ok());
            }
            return(BadRequest("Failed to Delete"));
        }
        public async Task <IActionResult> DeletePhoto(int userId, int photoId)
        {
            if (!IsUserValid(userId))
            {
                return(Unauthorized());
            }

            if (!await IsUsersPhoto(userId, photoId))
            {
                return(Unauthorized());
            }

            var photoFromRepo = await _repo.GetPhoto(photoId);

            if (photoFromRepo.IsMain)
            {
                return(BadRequest("You can not delete your main photo"));
            }

            if (photoFromRepo.PublicId != null)
            {
                var deleteParams = new DeletionParams(photoFromRepo.PublicId);
                var result       = _cloudinary.Destroy(deleteParams);

                if (result.Result == "ok")
                {
                    _repo.Delete(photoFromRepo);
                }
            }

            if (photoFromRepo.PublicId == null)
            {
                _repo.Delete(photoFromRepo);
            }
            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to delete the photo"));
        }
예제 #29
0
        public async Task <IActionResult> DeletePhoto(long userId, int id)
        {
            if (userId != long.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(StatusCode(StatusCodes.Status401Unauthorized));
            }
            var user = await _datingRepository.GetUser(userId);

            if (!user.Photos.Any(x => x.Id == id))
            {
                return(StatusCode(StatusCodes.Status401Unauthorized));
            }
            var photo = await this._datingRepository.GetPhoto(id);

            if (photo.IsProfilePic)
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "You cannot delete your profile photo."));
            }


            if (string.IsNullOrWhiteSpace(photo.PublicId))
            {
                _datingRepository.Delete(photo);
            }
            else
            {
                var deleteParams = new DeletionParams(photo.PublicId);
                var result       = await _cloudinary.DestroyAsync(deleteParams);

                if (result.Result == "ok")
                {
                    _datingRepository.Delete(photo);
                }
            }
            if (await _datingRepository.SaveAll())
            {
                return(StatusCode(StatusCodes.Status200OK));
            }

            return(StatusCode(StatusCodes.Status400BadRequest, "Failed to delete photo"));
        }
예제 #30
0
        public async Task <IActionResult> DeleteUserImage(int userId, int photoId)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            Models.User userFromRepo = await _datingRepo.GetUser(userId);

            if (!userFromRepo.Photos.Any(p => p.Id == photoId))
            {
                return(Unauthorized());
            }

            Models.Photo photoFromRepo = await _datingRepo.GetPhoto(photoId);

            if (photoFromRepo.IsMain)
            {
                return(BadRequest("You cannot delete your main photo"));
            }

            if (photoFromRepo.PublicId != null)
            {
                DeletionParams deleteParams = new DeletionParams(photoFromRepo.PublicId);
                var            result       = _cloudinary.Destroy(deleteParams);

                if (result.Result.ToLower() == "ok")
                {
                    _datingRepo.Delete(photoFromRepo);
                }
            }
            else
            {
                _datingRepo.Delete(photoFromRepo);
            }
            if (await _datingRepo.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("Error occurred while deleting photo"));
        }