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)); }
public async Task InsertAsync(AmigoEntity amigoEntity, Stream stream) { var newUri = await _blobService.UploadAsync(stream); amigoEntity.ImageUri = newUri; await _repository.InsertAsync(amigoEntity); }
public ActionResult Edit(AmigoEntity amigo) { using (var contexto = new myDbContexto()) { contexto.Entry(amigo).State = EntityState.Modified; contexto.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Create(AmigoEntity amigo) { using (var contexto = new myDbContexto()) { contexto.Amigo.Add(amigo); contexto.SaveChanges(); } return(RedirectToAction("Index")); }
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)); }
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)); }
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); }
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(); }