private DeletionResult DeleteImageFromCloudinary(string publicId) { DeletionResult deletionResult = null; try { var account = new Account { ApiKey = _cloudinarySettings.ApiKey, ApiSecret = _cloudinarySettings.ApiSecret, Cloud = _cloudinarySettings.CloudName }; var cloudinary = new Cloudinary(account); var deletionParameters = new DeletionParams(publicId); deletionResult = cloudinary.Destroy(deletionParameters); } catch (System.Exception ex) { _logger.LogError(ex.Message); } return(deletionResult); }
public async Task <ActionResult> DeletePhoto(int photoId) { var user = await _userRepository.GetUserByUsernameAsync(User.GetUsername()); var photo = user.Photos.FirstOrDefault(x => x.Id == photoId); if (photo == null) { return(NotFound()); } if (photo.IsMain) { return(BadRequest("You cannot delete your main photo")); } if (photo.PublicId != null) { DeletionResult result = await _photoSerivce.DeletePhotoAsync(photo.PublicId); if (result.Error != null) { return(BadRequest(result.Error.Message)); } } user.Photos.Remove(photo); if (await _userRepository.SaveAllAsync()) { return(Ok()); } return(BadRequest("Failed to delete the photo")); }
public async Task <IActionResult> RejectPhoto(Guid photoId) { Photo photo = await _context.Photos.IgnoreQueryFilters().FirstOrDefaultAsync(p => p.Id == photoId); if (photo != null) { if (photo.IsMain) { return(BadRequest("You cannot reject the main photo")); } if (string.IsNullOrEmpty(photo.PublicId)) { _context.Photos.Remove(photo); } else { DeletionParams deletionParams = new DeletionParams(photo.PublicId); DeletionResult deletionResult = _cloudinary.Destroy(deletionParams); if (deletionResult.Result == "ok") { _context.Photos.Remove(photo); } } await _context.SaveChangesAsync(); } return(Ok()); }
public async Task <IActionResult> DeletePhoto(int photoId) { Photo photoFromRepo = await _repo.GetPhoto(photoId); if (photoFromRepo.IsMain) { return(BadRequest("You cannot delete the main photo")); } if (photoFromRepo.PublicId != null) { DeletionParams deletionParams = new DeletionParams(photoFromRepo.PublicId); DeletionResult deletionResult = _cloudinary.Destroy(deletionParams); if (deletionResult.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")); }
public async Task <bool> DeleteData(StoreFileInfo fileInfo) { try { Account account = new Account( this.cloudName, this.apiKey, this.apiSecret); Cloudinary cloudinary = new Cloudinary(account); DeletionParams deletionParams = new DeletionParams(fileInfo.FileId); DeletionResult result = await cloudinary.DestroyAsync(deletionParams); if (result.StatusCode == System.Net.HttpStatusCode.OK) { return(true); } else { return(false); } } catch (Exception e) { this.Logger.LogError(e, e.Message); return(false); } }
public async Task <ActionResult> DeletePhoto(int photoId) { var user = await _mainRespositories.AppUserRespository.GetUserByUserNameAsync(User.GetUserName()); var photo = user.Photos.FirstOrDefault(x => x.Id == photoId); if (photo == null) { return(NotFound()); } if (photo.isMain) { return(BadRequest("You cannot delete the main photo.")); } if (photo.PublicId != null) { DeletionResult result = await _photoService.DeletePhotoAsync(photo.PublicId); if (result.Error != null) { return(BadRequest(result.Error.Message)); } } user.Photos.Remove(photo); if (await _mainRespositories.Complete()) { return(NoContent()); } return(BadRequest("Fail to delete photo")); }
public async Task <DeletionResult> DeletePhotoAsync(string publicId) { DeletionParams deleteParams = new DeletionParams(publicId); DeletionResult result = await _cloudinary.DestroyAsync(deleteParams); return(result); }
public async Task <DeletionResult> DeleteSong(Song song) { DeletionResult result = _cache.DeleteSong(song, ArtistGroupDictionary, AlbumGroupDictionary, SongGroupDictionary); await _cache.Serialize(); return(result); }
public string DeletePhoto(string publicId) { DeletionParams deleteParams = new DeletionParams(publicId); DeletionResult result = this.cloudinary.Destroy(deleteParams); return(result.Result == "ok" ? result.Result : null); }
public async Task <DeletionResult> DestroyAsync(DeletionParams parameters) { using ( var response = await Api.CallAsync(HttpMethod.Post, Api.ApiUrlImgUpV.ResourceType(Api.GetCloudinaryParam(parameters.ResourceType)).Action("destroy").BuildUrl(), parameters.ToParamsDictionary(), null, null)) { return(await DeletionResult.Parse(response)); } }
public bool DeleteBlob(string path) { String publicId = path.Substring(path.LastIndexOf('/') + 1); publicId = publicId.Substring(0, publicId.LastIndexOf('.')); publicId = $"{GetDefaultContainer().ToLower()}/{ publicId}"; DeletionParams deletionParams = new DeletionParams(publicId); DeletionResult result = cloudinary.Destroy(deletionParams); return(result.Result == "ok"); }
/// <summary> /// deletes image from cloudinary /// </summary> /// <param name="publicId">images public id</param> /// <returns></returns> public static async Task <HttpStatusCode> DeleteAsync(string publicId) { DeletionParams deletionParams = new DeletionParams(publicId); DeletionResult deletionResult = await _cloudinary.DestroyAsync(deletionParams); if (deletionResult.Result == "not found") { return(HttpStatusCode.NotFound); } return(deletionResult.StatusCode); }
/// <summary> /// Delete file from cloudinary /// </summary> /// <param name="parameters">Parameters for deletion of resource from cloudinary</param> /// <returns>Results of deletion</returns> public DeletionResult Destroy(DeletionParams parameters) { string uri = m_api.ApiUrlImgUpV.ResourceType( Api.GetCloudinaryParam <ResourceType>(parameters.ResourceType)). Action("destroy").BuildUrl(); using (HttpWebResponse response = m_api.Call(HttpMethod.POST, uri, parameters.ToParamsDictionary(), null)) { DeletionResult result = DeletionResult.Parse(response); return(result); } }
public async Task <IActionResult> DeletePhotoForUser(string username, int id) { string currentUser = User.FindFirstValue(ClaimTypes.Name); if (username != currentUser) { return(Unauthorized()); } User user = await _userRepository.GetUser(username); if (!user.Photos.Any(p => p.Id == id)) { return(Unauthorized()); } Photo photo = await _userRepository.GetPhoto(id); if (photo == null) { return(BadRequest("Photo does not exist!")); } else if (photo.IsMain) { return(BadRequest("Can't delete main photo!")); } if (photo.PublicId != null) { DeletionParams delParams = new DeletionParams(photo.PublicId); DeletionResult delResult = _cloudinary.Destroy(delParams); if (delResult.Result != "ok") { return(BadRequest("Failed to delete photo")); } } await _userRepository.DeletePhoto(id); int numChanges = await _userRepository.Save(); if (numChanges == 0) { throw new System.Exception("Could not delete your photo!"); } return(Ok()); }
public async Task <IActionResult> DeletePhoto(int userId, int id) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } User user = await _repo.GetUser(userId); if (!user.Photos.Any(p => p.Id == id)) { return(Unauthorized()); } Photo photoFromRepo = await _repo.GetPhoto(id); if (photoFromRepo.IsMain) { return(BadRequest("You cannot delete your main photo")); } if (photoFromRepo.PublicId != null) { DeletionParams deleteParams = new DeletionParams(photoFromRepo.PublicId); DeletionResult result = _cloudinary.Destroy(deleteParams); if (result.Result == "ok") { _repo.Delete(photoFromRepo); } } if (photoFromRepo.PublicId == null) { _repo.Delete(photoFromRepo); } if (await _repo.SaveAll()) { return(Ok()); } else { return(BadRequest("Failed to delete the photo")); } }
public async Task <bool> DeleteImagesAsync(List <string> publicIds) { var result = new DeletionResult(); foreach (var publicId in publicIds) { var deleteParams = new DeletionParams(publicId); result = await _cloudinary.DestroyAsync(deleteParams); if (result.Error != null) { throw new Exception(ExceptionMessages.ImageDeleteError); } } return(result.Result == "ok"); }
public IActionResult Destroy(string desc) { if (string.IsNullOrWhiteSpace(desc)) { return(BadRequest("The format of request data is not correct.")); } var deletionParam = new DeletionParams(desc); DeletionResult deletionResult = _cloudinary.Destroy(deletionParam); if (deletionResult.Result.Equals("ok")) { return(Ok()); } return(BadRequest("Deletion failed as server internal error.")); }
public async Task <IActionResult> DeletePhoto(int userId, int id) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } User user = await _datingRepository.GetUser(userId); if (!user.Photos.Any(p => p.Id == id)) { return(Unauthorized()); } Photo photoFromRepo = await _datingRepository.GetPhoto(id); if (photoFromRepo.IsMain) { return(BadRequest("Esta foto principal no puede ser eliminada")); } if (photoFromRepo.PublicId != null) { DeletionParams deleteParams = new DeletionParams(photoFromRepo.PublicId); DeletionResult result = await _cloudinary.DestroyAsync(deleteParams); if (result.Result == "ok") { _datingRepository.Delete(photoFromRepo); } } if (photoFromRepo.PublicId == null) { _datingRepository.Delete(photoFromRepo); } if (await _datingRepository.SaveAll()) { return(Ok()); } return(BadRequest("Ha fallado al eliminar la foto")); }
public async Task <IActionResult> DeletePhoto(Guid userId, Guid id) { if (userId != Guid.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } User user = await _repository.GetUser(userId, true); if (!user.Photos.Any(p => p.Id == id)) { return(Unauthorized()); } Photo photo = await _repository.GetPhoto(id); if (photo.IsMain) { return(BadRequest("You cannot delete your main photo")); } if (string.IsNullOrEmpty(photo.PublicId)) { _repository.Delete(photo); } else { DeletionParams deletionParams = new DeletionParams(photo.PublicId); DeletionResult deletionResult = _cloudinary.Destroy(deletionParams); if (deletionResult.Result == "ok") { _repository.Delete(photo); } } if (await _repository.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)) { return(Unauthorized()); } User user = await this.repository.GetUserAsync(userId); if (!user.Photos.Any(p => p.Id == id)) { return(Unauthorized()); } Photo photoToBeDelete = await this.repository.GetPhotoAsync(id); if (photoToBeDelete.IsMain) { return(BadRequest("You can not delete your main photo!")); } if (photoToBeDelete.PublicId != null) { DeletionParams deleteParams = new DeletionParams(photoToBeDelete.PublicId); DeletionResult result = this.cloudinary.Destroy(deleteParams); if (result.Result == "ok") { this.repository.Delete(photoToBeDelete); } } else { this.repository.Delete(photoToBeDelete); } if (await this.repository.SaveAllAsync()) { return(Ok()); } return(BadRequest("Failed to delete photo!")); }
public async Task <bool> DeletePhoto(Photo photo) { //Not a cloudinary photo or delete succeeded from cloudinary but failed in database if (photo.PublicId == null) { return(true); } DeletionParams deletionParams = new DeletionParams(photo.PublicId); DeletionResult result = await _cloudinary.DestroyAsync(deletionParams); if (result.Result == "ok") { return(true); } return(false); }
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); }
private async Task DeleteTodoItem() { bool isConfirmedToDelete = await _dialogsHelper.IsConfirmed(Strings.DeleteMessageDialog); if (!isConfirmedToDelete) { return; } //await _todoItemRepository.Delete<TodoItem>(_todoItemId); await _todoItemService.Delete(_todoItemId); // TODO : Refactor result. var deletionResult = new DeletionResult <TodoItem> { IsSucceded = true }; await _navigationService.Close(this, deletionResult); }
public void TestDestroyRawAsync() { RawUploadParams uploadParams = new RawUploadParams() { File = new FileDescription(m_testImagePath), Tags = m_apiTag }; RawUploadResult uploadResult = m_cloudinary.UploadAsync(uploadParams, Api.GetCloudinaryParam(ResourceType.Raw)).Result; Assert.NotNull(uploadResult); DeletionParams destroyParams = new DeletionParams(uploadResult.PublicId) { ResourceType = ResourceType.Raw }; DeletionResult destroyResult = m_cloudinary.DestroyAsync(destroyParams).Result; Assert.AreEqual("ok", destroyResult.Result); }
public async Task <IActionResult> DeletePhoto(int userId, int id) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var photoFromRepo = await _repository.GetPhoto(id); if (photoFromRepo == null) { return(NotFound()); } if (photoFromRepo.IsMain) { return(BadRequest("You cannot delete the main photo")); } DeletionResult result = null; if (photoFromRepo.PublicId != null) { var deleteParams = new DeletionParams(photoFromRepo.PublicId); result = _cloudinary.Destroy(deleteParams); } if (result.Result == "ok") { _repository.Delete(photoFromRepo); } if (await _repository.SaveAll()) { return(Ok()); } return(BadRequest("Failed to delete the photo")); }
private DeletionResult DeleteMessageFromOutboxHelper(DeleteMapiMailDefinition deleteMapiMailDefinition) { DeletionResult result = DeletionResult.Fail; string domainPartOfEmailAddress = MapiMessageSubmitter.GetDomainPartOfEmailAddress(deleteMapiMailDefinition.SenderEmailAddress); ExchangePrincipal mailboxOwner = ExchangePrincipal.FromProxyAddress(ADSessionSettings.RootOrgOrSingleTenantFromAcceptedDomainAutoDetect(domainPartOfEmailAddress), deleteMapiMailDefinition.SenderEmailAddress); QueryFilter queryFilter = new AndFilter(new List <QueryFilter>(2) { new TextFilter(ItemSchema.InternetMessageId, deleteMapiMailDefinition.InternetMessageId, MatchOptions.FullString, MatchFlags.IgnoreCase), new TextFilter(StoreObjectSchema.ItemClass, deleteMapiMailDefinition.MessageClass, MatchOptions.FullString, MatchFlags.IgnoreCase) }.ToArray()); using (MailboxSession mailboxSession = MailboxSession.OpenAsTransport(mailboxOwner, "Client=Monitoring;Action=MapiSubmitLAMProbe")) { using (Folder folder = Folder.Bind(mailboxSession, DefaultFolderType.Outbox)) { using (QueryResult queryResult = folder.ItemQuery(ItemQueryType.None, queryFilter, null, new PropertyDefinition[] { ItemSchema.Id })) { object[][] rows = queryResult.GetRows(1); if (rows == null || rows.Length == 0) { result = DeletionResult.NoMatchingMessage; } else { mailboxSession.Delete(DeleteItemFlags.HardDelete, new StoreId[] { ((VersionedId)rows[0][0]).ObjectId }); result = DeletionResult.Success; } } } } return(result); }
private async void deleteSong_Click(object sender, RoutedEventArgs e) { MenuFlyoutItem item = sender as MenuFlyoutItem; if (item != null) { Song song = item.DataContext as Song; if (song != null) { DeletionResult result = await song.Delete(); if (result == DeletionResult.Artist) { if (!Frame.Navigate(typeof(CollectionsHub), null)) { var resourceLoader = ResourceLoader.GetForCurrentView("Resources"); throw new Exception(resourceLoader.GetString("NavigationFailedExceptionMessage")); } } } } }
public IActionResult Put(int channelId, [FromForm] ChannelForUpdateDto channelForUpdate) { var dataResult = _channelService.GetById(channelId); if (dataResult.IsSuccessful) { if (string.IsNullOrEmpty(channelForUpdate.Name)) { return(BadRequest()); } if (channelForUpdate.File != null && channelForUpdate.File.Length > 0 && BusinessRules.ImageExtensionValidate(channelForUpdate.File.ContentType).IsSuccessful) { DeletionResult deletionResult = _photoUpload.ImageDelete(dataResult.Data.PublicId); ImageUploadResult imageUploadResult = _photoUpload.ImageUpload(channelForUpdate.File); dataResult.Data.ChannelPhotoUrl = imageUploadResult.Uri.ToString(); dataResult.Data.PublicId = imageUploadResult.PublicId; } IResult result = _channelService.CheckIfChannelNameExistsWithUpdate(channelForUpdate.Name, channelId); if (result.IsSuccessful) { return(BadRequest(result.Message)); } dataResult.Data.Name = channelForUpdate.Name; IDataResult <Channel> updateDataResult = _channelService.Update(dataResult.Data); if (dataResult.IsSuccessful) { var map = _mapper.Map <ChannelForDetailDto>(updateDataResult.Data); map.SubscribersCount = _countService.GetSubscriberCount(map.Id).Data; this.RemoveCache(); return(Ok(map)); } return(this.ServerError()); } return(NotFound(dataResult.Message)); }
public async Task <IActionResult> DisApprovePhoto(int id) { Photo photoToBeDelete = await this.context.Photos.FindAsync(id); if (photoToBeDelete == null) { return(NotFound("Photo not found")); } if (photoToBeDelete.PublicId != null) { DeletionParams deleteParams = new DeletionParams(photoToBeDelete.PublicId); DeletionResult result = this.cloudinary.Destroy(deleteParams); if (result.Result == "ok") { this.context.Photos.Remove(photoToBeDelete); } } else { this.context.Photos.Remove(photoToBeDelete); } try { await this.context.SaveChangesAsync(); return(Ok()); } catch (DbException ex) { return(BadRequest(ex.Message)); } }
private PhotoDeletionResult DefinePhotoDeletionResult(DeletionResult deletionResult) { return(deletionResult.Result == DeletionOkResult ? PhotoDeletionResult.Ok : PhotoDeletionResult.NotOk); }