Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        public async Task RemoveAsync(HeroiEntity heroiEntity)
        {
            var heroiToRemove = await GetByIdAsync(heroiEntity.Id);

            _bibliotecaContext.Herois.Remove(heroiToRemove);

            await _bibliotecaContext.SaveChangesAsync();
        }
Esempio n. 3
0
        public async Task InsertAsync(HeroiEntity heroiEntity, Stream stream)
        {
            var newUri = await _blobService.UploadAsync(stream);

            heroiEntity.ImageUri = newUri;

            await _repository.InsertAsync(heroiEntity);
        }
Esempio n. 4
0
        public async Task <int> AddAsync(HeroiEntity heroiEntity)
        {
            var entityEntry = await _bibliotecaContext.Herois.AddAsync(heroiEntity);

            await _bibliotecaContext.SaveChangesAsync();

            return(entityEntry.Entity.Id);
        }
Esempio n. 5
0
        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());
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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));
        }
Esempio n. 8
0
 public async Task DeleteAsync(HeroiEntity heroiEntity)
 {
     _context.Remove(heroiEntity);
     await _context.SaveChangesAsync();
 }
Esempio n. 9
0
 public async Task UpdateAsync(HeroiEntity heroiEntity)
 {
     _context.Update(heroiEntity);
     await _context.SaveChangesAsync();
 }
Esempio n. 10
0
 public async Task InsertAsync(HeroiEntity heroiEntity)
 {
     _context.Add(heroiEntity);
     await _context.SaveChangesAsync();
 }
Esempio n. 11
0
        public async Task DeleteAsync(HeroiEntity heroiEntity)
        {
            await _blobService.DeleteAsync(heroiEntity.ImageUri);

            await _repository.DeleteAsync(heroiEntity);
        }
Esempio n. 12
0
 public async Task RemoveAsync(HeroiEntity heroiEntity)
 {
     await _heroiRepository.RemoveAsync(heroiEntity);
 }
Esempio n. 13
0
 public async Task EditAsync(HeroiEntity heroiEntity)
 {
     await _heroiRepository.EditAsync(heroiEntity);
 }
Esempio n. 14
0
 public async Task <int> AddAsync(HeroiEntity heroiEntity)
 {
     return(await _heroiRepository.AddAsync(heroiEntity));
 }
Esempio n. 15
0
        public async Task EditAsync(HeroiEntity heroiEntity)
        {
            _bibliotecaContext.Herois.Update(heroiEntity);

            await _bibliotecaContext.SaveChangesAsync();
        }