// ReSharper disable once UnusedMember.Global --- AJAX public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _memorialContext.Attach(MemorialApplication).State = EntityState.Modified; try { await _memorialContext.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MemorialApplicationExists(MemorialApplication.MemorialApplicationId)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
// ReSharper disable once UnusedMember.Global --- AJAX public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { Result = "Please correct the form."; return(Page()); } // Save file in folder byte[] formFileContent = await FileHelpers.ProcessFormFile <IFormFile>( FileUpload, ModelState, _permittedExtensions, _fileSizeLimit); if (!ModelState.IsValid) { Result = "Please correct the form."; return(Page()); } // For the file name of the uploaded file stored server-side, use // Path.GetRandomFileName to generate a safe random file name. var trustedFileNameForFileStorage = Path.GetRandomFileName(); var folder = _targetFilePath + MemorialApplication.GetPath(); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } string filePath = Path.Combine(folder, trustedFileNameForFileStorage); while (System.IO.File.Exists(filePath)) { trustedFileNameForFileStorage = Path.GetRandomFileName(); filePath = Path.Combine(folder, trustedFileNameForFileStorage); } // **WARNING!** // In the following example, the file is saved without scanning the file's contents. In most production // scenarios, an anti-virus/anti-malware scanner API is used on the file before making the file available // for download or for use by other systems. For more information, see the topic that accompanies this sample. await using (var fileStream = System.IO.File.Create(filePath)) { await fileStream.WriteAsync(formFileContent); // To work directly with the FormFiles, use the following instead: //await FileUpload.CopyToAsync(fileStream); } // Set and Save Application in DB MemorialApplication.FilePath = MemorialApplication.GetPath(); MemorialApplication.FileName = trustedFileNameForFileStorage; MemorialApplication.UploadDate = DateTime.Now; await _context.MemorialApplications.AddAsync(MemorialApplication); await _context.SaveChangesAsync(); return(RedirectToPage("./Index", new { msg = "Application Successfully Added" })); }
// ReSharper disable once UnusedMember.Global --- AJAX public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } MemorialApplication = await _memorialContext.MemorialApplications.FindAsync(id); if (MemorialApplication != null) { _memorialContext.MemorialApplications.Remove(MemorialApplication); await _memorialContext.SaveChangesAsync(); } return(RedirectToPage("./Index")); }