Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, AmigoEntity amigoEntity)
        {
            if (id != amigoEntity.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var file = Request.Form.Files.SingleOrDefault();

                    await _domainService.UpdateAsync(amigoEntity, file?.OpenReadStream());
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AmigoEntityExists(amigoEntity.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(amigoEntity));
        }
Ejemplo n.º 2
0
        public async Task InsertAsync(AmigoEntity amigoEntity, Stream stream)
        {
            var newUri = await _blobService.UploadAsync(stream);

            amigoEntity.ImageUri = newUri;

            await _repository.InsertAsync(amigoEntity);
        }
Ejemplo n.º 3
0
 public ActionResult Edit(AmigoEntity amigo)
 {
     using (var contexto = new myDbContexto())
     {
         contexto.Entry(amigo).State = EntityState.Modified;
         contexto.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 4
0
 public ActionResult Create(AmigoEntity amigo)
 {
     using (var contexto = new myDbContexto())
     {
         contexto.Amigo.Add(amigo);
         contexto.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 5
0
        public ActionResult Edit(int id)
        {
            var amigo = new AmigoEntity();

            using (var contexto = new myDbContexto())
            {
                amigo = contexto.Amigo.FirstOrDefault(a => a.IdAmigo == id);
            }
            return(View(amigo));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Create(AmigoEntity amigoEntity, IFormFile ImageFile)
        {
            if (ModelState.IsValid)
            {
                await _domainService.InsertAsync(amigoEntity, ImageFile.OpenReadStream());

                return(RedirectToAction(nameof(Index)));
            }
            return(View(amigoEntity));
        }
Ejemplo n.º 7
0
        public async Task UpdateAsync(AmigoEntity amigoEntity, Stream stream)
        {
            if (stream != null)
            {
                await _blobService.DeleteAsync(amigoEntity.ImageUri);

                var newUri = await _blobService.UploadAsync(stream);

                amigoEntity.ImageUri = newUri;
            }

            await _repository.UpdateAsync(amigoEntity);
        }
Ejemplo n.º 8
0
        public async Task DeleteAsync(AmigoEntity amigoEntity)
        {
            await _blobService.DeleteAsync(amigoEntity.ImageUri);

            var email = new
            {
                Assunto   = $"Exclusão de amigo {amigoEntity.Nome}",
                Corpo     = $"Um amigo seu foi excluído. O nome do seu amigo excluído é: {amigoEntity.Nome}",
                EmailPara = "*****@*****.**"
            };

            //primeira forma de serializar objeto json/base64 (usando package Newtonsoft.Json)
            var    jsonEmail       = JsonConvert.SerializeObject(email);
            var    bytesJsonEmail  = UTF8Encoding.UTF8.GetBytes(jsonEmail);
            string jsonEmailBase64 = Convert.ToBase64String(bytesJsonEmail);

            //segunda forma de serializar objeto json/base64 (usando package System.Text.Json)
            //var jsonBytes = JsonSerializer.SerializeToUtf8Bytes(email);
            //string jsonEmailBase64 = Convert.ToBase64String(jsonBytes);

            await _queueService.SendAsync(jsonEmailBase64);

            await _repository.DeleteAsync(amigoEntity);
        }
 public async Task DeleteAsync(AmigoEntity amigoEntity)
 {
     _context.Remove(amigoEntity);
     await _context.SaveChangesAsync();
 }
 public async Task UpdateAsync(AmigoEntity amigoEntity)
 {
     _context.Update(amigoEntity);
     await _context.SaveChangesAsync();
 }
 public async Task InsertAsync(AmigoEntity amigoEntity)
 {
     _context.Add(amigoEntity);
     await _context.SaveChangesAsync();
 }