// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Photo).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PhotoExists(Photo.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Photo = await _context.Photo.FindAsync(id); if (Photo != null) { var authorizationResult = await _authorizationService .AuthorizeAsync(User, Photo, "DeletePhoto"); if (authorizationResult.Succeeded) { _context.Photo.Remove(Photo); await _context.SaveChangesAsync(); } else if (User.Identity.IsAuthenticated) { return(new ForbidResult()); } else { return(new ChallengeResult()); } } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } Photo.DateUploaded = DateTime.Now; using MemoryStream memoryStream = new MemoryStream(); await ThePicture.CopyToAsync(memoryStream); Photo.Picture = memoryStream.ToArray(); Photo.ContentType = ThePicture.ContentType; _context.Photo.Add(Photo); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }