public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Staff = await _context.Staff.FindAsync(id); if (Staff != null) { _context.Staff.Remove(Staff); //await _context.SaveChangesAsync(); // Once a record is deleted, create an audit record if (await _context.SaveChangesAsync() > 0) { var auditrecord = new AuditRecord(); auditrecord.AuditActionType = "Delete Staff Record"; auditrecord.DateTimeStamp = DateTime.Now; auditrecord.KeyBookFieldID = Staff.ID; var userID = User.Identity.Name.ToString(); auditrecord.Username = userID; _context.AuditRecords.Add(auditrecord); await _context.SaveChangesAsync(); } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } Rating.RatingTime = DateTime.Now; _context.Rating.Add(Rating); //await _context.SaveChangesAsync(); // Once a record is added, create an audit record if (await _context.SaveChangesAsync() > 0) { // Create an auditrecord object var auditrecord = new AuditRecord(); auditrecord.AuditActionType = "Add Rating Record"; auditrecord.DateTimeStamp = DateTime.Now; auditrecord.KeyBookFieldID = 998; // Get current logged-in user var userID = User.Identity.Name.ToString(); auditrecord.Username = userID; _context.AuditRecords.Add(auditrecord); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Feedback = await _context.Feedback.FindAsync(id); if (Feedback != null) { _context.Feedback.Remove(Feedback); //await _context.SaveChangesAsync(); if (await _context.SaveChangesAsync() > 0) { var auditrecord = new AuditRecord(); auditrecord.AuditActionType = "Delete Feedback Record"; auditrecord.DateTimeStamp = DateTime.Now; auditrecord.KeyBookFieldID = 998; var userID = User.Identity.Name.ToString(); auditrecord.Username = userID; _context.AuditRecords.Add(auditrecord); await _context.SaveChangesAsync(); } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Feedback.Add(Feedback); // // Once a record is added, create an audit record if (await _context.SaveChangesAsync() > 0) { // Create an auditrecord object var auditrecord = new AuditRecord(); auditrecord.AuditActionType = "Add New Feedback Record"; auditrecord.DateTimeStamp = DateTime.Now; auditrecord.KeyBookFieldID = Feedback.feedbackId; // Get current logged-in user var userID = ""; auditrecord.Username = userID; _context.AuditRecords.Add(auditrecord); await _context.SaveChangesAsync(); } await _context.SaveChangesAsync(); return(RedirectToPage("../Index")); }
public async Task <IActionResult> OnPostAsync(string selectedusername, string selectedrolename) { //When the Assign button is pressed if ((selectedusername == null) || (selectedrolename == null)) { return(RedirectToPage("Manage")); } ApplicationUser AppUser = _context.Users.SingleOrDefault(u => u.UserName == selectedusername); ApplicationRole AppRole = await _roleManager.FindByNameAsync(selectedrolename); //AddToRoleAsync(user object, rolename) will assign the user to the specified role. If you check the database table dbo.AppNetUserRoles, a mapping of userid and roleid is added. IdentityResult roleResult = await _userManager.AddToRoleAsync(AppUser, AppRole.Name); if (roleResult.Succeeded) { TempData["message"] = selectedrolename + " Role added to " + selectedusername + " successfully"; // Create an auditrecord object var auditrecord = new AuditRecord(); auditrecord.AuditActionType = "Assigned user" + selectedusername + " to role, " + selectedrolename; auditrecord.DateTimeStamp = DateTime.Now; auditrecord.KeyBookFieldID = 888; // Get current logged-in user var userID = User.Identity.Name.ToString(); auditrecord.Username = userID; _context.AuditRecords.Add(auditrecord); await _context.SaveChangesAsync(); } return(RedirectToPage("Manage")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } Reservation.dueDate = (DateTime.Now.AddDays(21)); Reservation.dateBorrowed = DateTime.Now; Reservation.ISBN = Book.ISBN; Reservation.Title = Book.Title; Reservation.Author = Book.Author; Reservation.Summary = Book.Summary; Reservation.DatePublished = Book.DatePublished; Reservation.Genre = Book.Genre; Reservation.Language = Book.Language; Reservation.Characters = Book.Characters; Reservation.DateReceived = Book.DateReceived; Reservation.Location = Book.Location; Reservation.Availability = Book.Availability; // Get current logged-in user var userID = User.Identity.Name.ToString(); Reservation.Borrower = userID; _context.Reservation.Add(Reservation); _context.Attach(Book).State = EntityState.Modified; try { //await _context.SaveChangesAsync(); // Once a record is added, create an audit record if (await _context.SaveChangesAsync() > 0) { // Create an auditrecord object var auditrecord = new AuditRecord(); auditrecord.AuditActionType = "Add Reservation Record"; auditrecord.DateTimeStamp = DateTime.Now; auditrecord.KeyBookFieldID = Reservation.ReservationID; // Get current logged-in user var UserID = User.Identity.Name.ToString(); auditrecord.Username = UserID; _context.AuditRecords.Add(auditrecord); await _context.SaveChangesAsync(); } } catch (DbUpdateConcurrencyException) { if (!BookExists(Book.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("../Books/Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } ApplicationRole.CreatedDate = DateTime.UtcNow; ApplicationRole.IPAddress = Request.HttpContext.Connection.RemoteIpAddress.ToString(); //This class takes RoleManager as constructor parameter. ASP.NET Core Dependency Injection will take care of passing the instance of RoleManager into this razor page. IdentityResult roleRuslt = await _roleManager.CreateAsync(ApplicationRole); //This method has new ApplicationRole as a parameter and creates new role in the application.This will also return true or false on the whether the creation of new role is successful. // Create an auditrecord object var auditrecord = new AuditRecord(); auditrecord.AuditActionType = "Created new Role," + ApplicationRole; auditrecord.DateTimeStamp = DateTime.Now; auditrecord.KeyBookFieldID = 777; // Get current logged-in user var userID = User.Identity.Name.ToString(); auditrecord.Username = userID; _context.AuditRecords.Add(auditrecord); await _context.SaveChangesAsync(); return(RedirectToPage("Index")); }
public async Task <IActionResult> OnPostAsync(string id) { if (id == null) { return(NotFound()); } ApplicationRole = await _roleManager.FindByIdAsync(id); IdentityResult roleRuslt = await _roleManager.DeleteAsync(ApplicationRole); //This method has existing ApplicationRole as a parameter and delete the role in the application. // Create an auditrecord object var auditrecord = new AuditRecord(); auditrecord.AuditActionType = "Deleted " + ApplicationRole + " Role"; auditrecord.DateTimeStamp = DateTime.Now; auditrecord.KeyBookFieldID = 777; // Get current logged-in user var userID = User.Identity.Name.ToString(); auditrecord.Username = userID; _context.AuditRecords.Add(auditrecord); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } ApplicationRole appRole = await _roleManager.FindByIdAsync(ApplicationRole.Id); appRole.Id = ApplicationRole.Id; appRole.Name = ApplicationRole.Name; appRole.Description = ApplicationRole.Description; IdentityResult roleRuslt = await _roleManager.UpdateAsync(appRole); //When the form is posted with the data, the UpdateAsync method of the roleManager class which has existing ApplicationRole as a parameter will update the role in the application. if (roleRuslt.Succeeded) { // Create an auditrecord object var auditrecord = new AuditRecord(); auditrecord.AuditActionType = "Edited " + ApplicationRole + " Role"; auditrecord.DateTimeStamp = System.DateTime.Now; auditrecord.KeyBookFieldID = 777; // Get current logged-in user var userID = User.Identity.Name.ToString(); auditrecord.Username = userID; _context.AuditRecords.Add(auditrecord); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Staff).State = EntityState.Modified; try { //await _context.SaveChangesAsync(); // Once a record is edited, create an audit record if (await _context.SaveChangesAsync() > 0) { // Create an auditrecord object var auditrecord = new AuditRecord(); auditrecord.AuditActionType = "Edit Staff Record"; auditrecord.DateTimeStamp = DateTime.Now; auditrecord.KeyBookFieldID = Staff.ID; // Get current logged-in user var userID = User.Identity.Name.ToString(); auditrecord.Username = userID; _context.AuditRecords.Add(auditrecord); await _context.SaveChangesAsync(); } } catch (DbUpdateConcurrencyException) { if (!StaffExists(Staff.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { ReturnUrl = returnUrl; if (ModelState.IsValid) { var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure : true); if (result.Succeeded) { _logger.LogInformation("User logged in."); return(LocalRedirect(Url.GetLocalUrl(returnUrl))); } else { // Login failed attempt - create an audit record var auditrecord = new AuditRecord(); auditrecord.AuditActionType = "Failed Login"; auditrecord.DateTimeStamp = DateTime.Now; auditrecord.KeyBookFieldID = 999; // 999 – dummy record auditrecord.Username = Input.Email; // save the email used for the failed login _context.AuditRecords.Add(auditrecord); await _context.SaveChangesAsync(); } if (result.IsLockedOut) { _logger.LogWarning("User account locked out."); return(RedirectToPage("./Lockout")); } else { ModelState.AddModelError(string.Empty, "Invalid login attempt."); return(Page()); } } return(Page()); }