public async Task <IActionResult> Create(HeroiEntity heroiEntity, IFormFile ImageFile) { if (ModelState.IsValid) { var stream = ImageFile.OpenReadStream(); byte[] data; using (var binaryReader = new BinaryReader(stream)) { data = binaryReader.ReadBytes((int)stream.Length); } ByteArrayContent bytes = new ByteArrayContent(data); var multiPart = new MultipartFormDataContent(); multiPart.Add(bytes, "file", "imagem.jpg"); multiPart.Add(new StringContent(heroiEntity.Id.ToString()), "Id"); multiPart.Add(new StringContent(heroiEntity.Nome), "Nome"); multiPart.Add(new StringContent(heroiEntity.Codinome), "Codinome"); multiPart.Add(new StringContent(heroiEntity.Lancamento.ToString()), "Lancamento"); multiPart.Add(new StringContent(heroiEntity.Poder.ToString()), "Parente"); multiPart.Add(new StringContent(heroiEntity.ImageUri == null ? "" : heroiEntity.ImageUri), "ImageUri"); var response = await _client.PostAsync(RESOURCE, multiPart); response.EnsureSuccessStatusCode(); return(RedirectToAction(nameof(Index))); } return(View(heroiEntity)); }
public async Task RemoveAsync(HeroiEntity heroiEntity) { var heroiToRemove = await GetByIdAsync(heroiEntity.Id); _bibliotecaContext.Herois.Remove(heroiToRemove); await _bibliotecaContext.SaveChangesAsync(); }
public async Task InsertAsync(HeroiEntity heroiEntity, Stream stream) { var newUri = await _blobService.UploadAsync(stream); heroiEntity.ImageUri = newUri; await _repository.InsertAsync(heroiEntity); }
public async Task <int> AddAsync(HeroiEntity heroiEntity) { var entityEntry = await _bibliotecaContext.Herois.AddAsync(heroiEntity); await _bibliotecaContext.SaveChangesAsync(); return(entityEntry.Entity.Id); }
public async Task <IActionResult> Put([FromForm] HeroiEntity heroi, [FromForm] IFormFile file) { if (await _service.GetByIdAsync(heroi.Id) == null) { return(NotFound()); } await _service.UpdateAsync(heroi, file?.OpenReadStream()); return(NoContent()); }
public async Task UpdateAsync(HeroiEntity heroiEntity, Stream stream) { if (stream != null) { await _blobService.DeleteAsync(heroiEntity.ImageUri); var newUri = await _blobService.UploadAsync(stream); heroiEntity.ImageUri = newUri; } await _repository.UpdateAsync(heroiEntity); }
public async Task <ActionResult <HeroiEntity> > Post([FromForm] HeroiEntity heroi, [FromForm] IFormFile file) { await _service.InsertAsync(heroi, file?.OpenReadStream()); return(CreatedAtAction(nameof(Get), new { id = heroi.Id }, heroi)); }
public async Task DeleteAsync(HeroiEntity heroiEntity) { _context.Remove(heroiEntity); await _context.SaveChangesAsync(); }
public async Task UpdateAsync(HeroiEntity heroiEntity) { _context.Update(heroiEntity); await _context.SaveChangesAsync(); }
public async Task InsertAsync(HeroiEntity heroiEntity) { _context.Add(heroiEntity); await _context.SaveChangesAsync(); }
public async Task DeleteAsync(HeroiEntity heroiEntity) { await _blobService.DeleteAsync(heroiEntity.ImageUri); await _repository.DeleteAsync(heroiEntity); }
public async Task RemoveAsync(HeroiEntity heroiEntity) { await _heroiRepository.RemoveAsync(heroiEntity); }
public async Task EditAsync(HeroiEntity heroiEntity) { await _heroiRepository.EditAsync(heroiEntity); }
public async Task <int> AddAsync(HeroiEntity heroiEntity) { return(await _heroiRepository.AddAsync(heroiEntity)); }
public async Task EditAsync(HeroiEntity heroiEntity) { _bibliotecaContext.Herois.Update(heroiEntity); await _bibliotecaContext.SaveChangesAsync(); }