public async Task <IActionResult> OnPostAsync() { //good ol hacky solution, but it works for now: I couldnt' seem to get the form data properly otherwise :( ) var thing = Request.Form["TeamLeader"]; int.TryParse(thing, out int TLID); var newTeamLead = await _context.ClubMember.FirstOrDefaultAsync(tl => tl.MemberID == TLID); var newTeam = new Teams { ProjectDescription = projectDescription, ProjectName = projectName, TeamLeader = newTeamLead, TeamMembers = teamMembers }; try { _context.Teams.Add(newTeam); await _context.SaveChangesAsync(); return(RedirectToPage("Team")); } catch (Exception e) { _logger.LogWarning(e, "Error creating Team"); return(Page()); } }
//when passing the id back from JS script, the var apparently has to be the same name the model function is looking for: public async Task <IActionResult> OnPost(int?MemberId) { _logger.LogInformation($"On post fired...{MemberId.ToString()}"); if (MemberId == null) { return(NotFound()); } ClubMember MemberToDelete = await _context.ClubMember.FindAsync(MemberId); if (MemberToDelete == null) { _logger.LogWarning($"Club member not found in database \nID: {MemberId}"); return(NotFound()); } else { try { _context.ClubMember.Remove(MemberToDelete); await _context.SaveChangesAsync(); } catch (Exception e) { _logger.LogWarning(e, "Error removing Member"); } } return(RedirectToPage("./Members")); }
public async Task <IActionResult> OnPostAsync(int?TeamID) { if (TeamID == null) { return(NotFound()); } Teams teamToDelete = await _context.Teams.FindAsync(TeamID); try { _context.Teams.Remove(teamToDelete); await _context.SaveChangesAsync(); } catch (Exception e) { _logger.LogWarning(e, "Error deleting Team."); } return(RedirectToPage("Team")); }
public async Task <IActionResult> OnPost() { var newMember = new ClubMember { FName = fName, LName = lName, ClubTitle = "Prospect", IsAdmin = false, DuesPaid = false }; try { _context.ClubMember.Add(newMember); await _context.SaveChangesAsync(); _logger.LogInformation($"Added new member {newMember}"); } catch (Exception e) { _logger.LogWarning(e, "Error saving newMember to db"); } return(RedirectToPage("Members")); }