public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(AuditRecord).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AuditRecordExists(AuditRecord.Audit_ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } if (!(Listing.Photo == null)) { await UploadPhoto(); } //File Upload path var DirectoryPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/Uploads/Listings"); var FinalPath = Path.Combine(DirectoryPath, Listing.PhotoPath); //Validate uploaded photo if (GetImageType(FinalPath) == "") { TempData["notice"] = "Please upload a valid file"; return(Page()); } _context.Attach(Listing).State = EntityState.Modified; //try //{ // await _context.SaveChangesAsync(); //} //catch (DbUpdateConcurrencyException) //{ // if (!ListingExists(Listing.ID)) // { // return NotFound(); // } // else // { // throw; // } //} //if listing is edited, create record if (await _context.SaveChangesAsync() > 0) { var auditrecord = new AuditRecord(); auditrecord.AuditActionType = "Edit Listing"; auditrecord.DateTimeStamp = DateTime.Now; auditrecord.ListingID = Listing.ID; var userID = User.Identity.Name.ToString(); auditrecord.Username = userID; _context.AuditRecords.Add(auditrecord); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }