public async Task <IActionResult> DeleteMovie( [HttpTrigger(AuthorizationLevel.Function, "delete", Route = "movies/{id}")] HttpRequest req, ILogger log, string id) { try { string apiKey = req.Headers["x-api-key"]; string encryptedApiKey = StaticMethods.Hash(apiKey); if (encryptedApiKey == await _apiKeyRepository.Get()) { await _repository.Delete(id); await _movieImageCrudRepository.DeleteFolder(id); return(new NoContentResult()); } else { var result = new ObjectResult("Api Key Invalid"); result.StatusCode = StatusCodes.Status401Unauthorized; return(result); } } catch (Exception exception) { log.LogError(exception.ToString()); var result = new ObjectResult(exception.Message); result.StatusCode = StatusCodes.Status500InternalServerError; return(result); } }
public async Task Run([QueueTrigger("movies", Connection = "AzureWebJobsStorage")] string myQueueItem, ILogger log) { try { Movie movie = JsonConvert.DeserializeObject <Movie>(myQueueItem); MovieEntity movieEntity = new MovieEntity(movie); if (movieEntity.Title != "") { //Download the image from the Url var imageBytes = StaticMethods.GetImageFromUrl(movieEntity.ImageUrl); //Add or update entity to the storage table movies await _movieEntityCrudRepository.AddOrUpdate(movieEntity); //Add image to the storage blob imagemovies await _movieImageCrudRepository.Add(imageBytes, movieEntity.Id + "/" + DateTime.UtcNow.Ticks.ToString()); } else { //Delete the entity from the storage table movies await _movieEntityCrudRepository.Delete(movieEntity.Id); //Delete the image from the storage blob movieimages await _movieImageCrudRepository.DeleteFolder(movieEntity.Id); } } catch (Exception exception) { log.LogError(exception.Message); } }