public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Media).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MediaExists(Media.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { // Perform an initial check to catch FileUpload class // attribute violations. if (!ModelState.IsValid) { Photos = await _context.Photos.AsNoTracking().ToListAsync(); return(Page()); } var publicScheduleData = await FileHelpers.ProcessFormFile(FileUpload.UploadPublicSchedule, ModelState); // Perform a second check to catch ProcessFormFile method // violations. if (!ModelState.IsValid) { Photos = await _context.Photos.AsNoTracking().ToListAsync(); return(Page()); } var photo = new Photo() { PublicSchedule = publicScheduleData, Title = FileUpload.Title, UploadDT = DateTime.UtcNow }; _context.Photos.Add(photo); await _context.SaveChangesAsync(); return(RedirectToPage("./IndexFile")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Photos.Add(Photo); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Photo = await _context.Photos.FindAsync(id); if (Photo != null) { _context.Photos.Remove(Photo); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }