public async Task <IActionResult> PutImage(Guid id, Image image) { if (id != image.Id) { return(BadRequest()); } _context.Entry(image).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ImageExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("PictureId,Description,Address,Storage,Status,Result")] Picture picture, IFormFile file) { var userId = GetCookie("key"); if (ModelState.IsValid) { if (picture.Storage) { if (file == null || file.Length == 0) { //retorna a viewdata com erro ViewData["Erro"] = "Error: Arquivo(s) não selecionado(s)"; return(View(ViewData)); } else { if (!file.IsImage()) { ViewData["Erro"] = "Error: Arquivo enviado não é imagem válida"; return(View(ViewData)); } string filename = System.IO.Path.GetFileName(file.FileName.Replace(" ", "")); var result = await AzureStorageLib.Services.AzureStorageService.UploadFileToStorage(_azureStorageConfig, file.OpenReadStream(), filename); picture.Address = filename; picture.Result = Newtonsoft.Json.JsonConvert.SerializeObject(result); } } picture.UserId = Guid.Parse(userId); _context.Add(picture); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(picture)); }