public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } FeedbackForm = await _context.FeedbackForm.FindAsync(id); if (FeedbackForm != null) { _context.FeedbackForm.Remove(FeedbackForm); if (await _context.SaveChangesAsync() > 0) { var auditrecord = new AuditRecord(); auditrecord.AuditActionType = "Feedback Form Deleted"; auditrecord.DateTimeStamp = DateTime.Now; auditrecord.ComputerID = FeedbackForm.ID; var userID = User.Identity.Name.ToString(); auditrecord.Username = userID; _context.AuditRecords.Add(auditrecord); await _context.SaveChangesAsync(); } } 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()); } if (ComputerImages != null) { var fileName = GetUniqueName(ComputerImages.FileName); var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "uploads"); var filePath = Path.Combine(uploads, fileName); ComputerImages.CopyTo(new FileStream(filePath, FileMode.Create)); Computer.Images = fileName; // Set the file name } _context.Computer.Add(Computer); if (await _context.SaveChangesAsync() > 0) { var auditrecord = new AuditRecord(); auditrecord.AuditActionType = "Created Computer Record"; auditrecord.DateTimeStamp = DateTime.Now; auditrecord.ComputerID = Computer.ID; var userID = User.Identity.Name.ToString(); auditrecord.Username = userID; _context.AuditRecords.Add(auditrecord); await _context.SaveChangesAsync(); } 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()); } _context.FeedbackForm.Add(FeedbackForm); if (await _context.SaveChangesAsync() > 0) { var auditrecord = new AuditRecord(); auditrecord.AuditActionType = "Feedback Form Created"; auditrecord.DateTimeStamp = DateTime.Now; auditrecord.ComputerID = FeedbackForm.ID; var userID = User.Identity.Name.ToString(); auditrecord.Username = userID; _context.AuditRecords.Add(auditrecord); await _context.SaveChangesAsync(); } 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()); } _context.Attach(FeedbackForm).State = EntityState.Modified; try { if (await _context.SaveChangesAsync() > 0) { var auditrecord = new AuditRecord(); auditrecord.AuditActionType = "Feedback Form Edited"; auditrecord.DateTimeStamp = DateTime.Now; auditrecord.ComputerID = FeedbackForm.ID; var userID = User.Identity.Name.ToString(); auditrecord.Username = userID; _context.AuditRecords.Add(auditrecord); await _context.SaveChangesAsync(); } } catch (DbUpdateConcurrencyException) { if (!FeedbackFormExists(FeedbackForm.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }