public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Pie = await _context.Pie.FindAsync(id); if (Pie != null) { _context.Pie.Remove(Pie); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } using (var stream = new System.IO.MemoryStream()) { file.CopyTo(stream); this.Image = stream.ToArray(); } Pie.Image = this.Image; Pie.ImageContentType = "file"; _context.Pie.Add(Pie); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Pie).State = EntityState.Modified; try { using (var stream = new System.IO.MemoryStream()) { file.CopyTo(stream); this.Image = stream.ToArray(); } Pie.Image = this.Image; Pie.ImageContentType = "file"; await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PieExists(Pie.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }