public async Task <IActionResult> OnPostAsync() { AppCondition app = await _context.AppCondition.FirstOrDefaultAsync(app => app.AppConditionId.Equals(1)); int teamid = Team.TeamId; //To delete a team we need to remove all the member of that team IList <Member> teamMembers = await _context.Member.Where(m => m.TeamID.Equals(teamid) && m.EventID.Equals(app.EventID)).ToListAsync(); foreach (var member in teamMembers) { _context.Member.Remove(member); await _context.SaveChangesAsync(); } //Now that team has been deleted we have to remove votes for that team in the event IList <Vote> teamVotes = await _context.Vote.Where(v => v.TeamID.Equals(Team.TeamId) && v.EventID.Equals(app.EventID)).ToListAsync(); foreach (var vote in teamVotes) { _context.Vote.Remove(vote); await _context.SaveChangesAsync(); } //we also need to remove the presentation of the team if any TeamPresentation teamPresentation = await _context.TeamPresentation.FirstOrDefaultAsync(tp => tp.TeamID.Equals(Team.TeamId)); if (teamPresentation != null) { //We need to remove the file from the folder as well. string storedFile = teamPresentation.FileName; var oldPath = Path.Combine(Directory.GetCurrentDirectory(), "Files", storedFile); if (System.IO.File.Exists(oldPath)) { System.IO.File.Delete(oldPath); _context.TeamPresentation.Remove(teamPresentation); await _context.SaveChangesAsync(); } else { _context.TeamPresentation.Remove(teamPresentation); await _context.SaveChangesAsync(); } } _context.Team.Remove(Team); await _context.SaveChangesAsync(); return(RedirectToPage("./Privacy")); }
public async Task <IActionResult> OnPostAsync(int?id) { //Here id refers to tiebreaker id as due to design flaws if (id == null) { return(RedirectToPage("PeopleWinnerList")); } AppCondition app = await _context.AppCondition.FirstOrDefaultAsync(app => app.AppConditionId.Equals(1)); TieBreaker tie = await _context.TieBreaker.FirstOrDefaultAsync(tie => tie.TieBreakerId.Equals(id) && tie.EventID.Equals(app.EventID)); if (tie == null) { //Something obviosuly went wrong return(RedirectToPage("PeopleVotes")); } Team = await _context.Team.FirstOrDefaultAsync(t => t.TeamId.Equals(tie.TeamID) && t.EventID.Equals(tie.EventID)); if (Team.TeamId != tie.TeamID) { //Which shouldn't be the case considering the OnGet function return(RedirectToPage("PeopleVotes")); } PeopleWinner peopleWinner = new PeopleWinner() { EventID = Team.EventID, TeamID = Team.TeamId, TeamName = Team.TeamName, UserID = Team.UserID }; _context.PeopleWinner.Add(peopleWinner); await _context.SaveChangesAsync(); //Now that winner has been found we need to remove the tie breaker teams IList <TieBreaker> tieBreakers = await _context.TieBreaker.ToListAsync(); foreach (var ties in tieBreakers) { _context.TieBreaker.Remove(ties); await _context.SaveChangesAsync(); } return(RedirectToPage("./PeopleWinnerList")); }
// 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()); } User user = await _context.User.FirstOrDefaultAsync(u => u.UserId.Equals(User.UserId)); user.FullName = User.FullName; user.Email = User.Email; user.Password = User.Password; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(User.UserId)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./AllUsers")); }
// 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() { string username = HttpContext.Session.GetString("username"); AppCondition app = await _context.AppCondition.FirstOrDefaultAsync(app => app.AppConditionId.Equals(1)); if (username == app.AdminName) { isAdmin = true; } else { isAdmin = false; } if (!ModelState.IsValid) { EventsList = await _context.Event.ToListAsync(); return(Page()); } _context.Theme.Add(Theme); 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(Team).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TeamExists(Team.TeamId)) { return(NotFound()); } else { throw; } } 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()); } AppCondition app = await _context.AppCondition.FirstOrDefaultAsync(a => a.AppConditionId.Equals(1)); Event eve = await _context.Event.FirstOrDefaultAsync(e => e.EventId.Equals(app.EventID)); if (eve == null) { //Something obviously went wrong //Such as admin might have deleted the event return(RedirectToPage("Privacy")); } Theme.EventID = eve.EventId; Theme.EventCode = eve.EventCode; Theme.EventName = eve.EventName; _context.Theme.Add(Theme); await _context.SaveChangesAsync(); return(RedirectToPage("./Privacy")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } TieBreaker tieBreaker = await _context.TieBreaker.FirstOrDefaultAsync(tie => tie.TieBreakerId.Equals(id)); Team team = await _context.Team.FirstOrDefaultAsync(t => t.TeamId.Equals(tieBreaker.TeamID)); if (team == null) { RedirectToPage("JudgeVotes"); } JudgeWinner judgeWinner = new JudgeWinner() { EventID = tieBreaker.EventID, TeamID = tieBreaker.TeamID, UserID = tieBreaker.EventID, TeamName = team.TeamName }; _context.JudgeWinner.Add(judgeWinner); await _context.SaveChangesAsync(); return(RedirectToPage("./JudgeWinnerList")); }
// 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()); } string username = User.UserName.Trim(); string name = User.FullName.Trim(); string email = User.Email.Trim(); string password = User.Password.Trim(); if (username == "") { Message = "Username is required!!"; return(Page()); } if (name == "") { Message = "Name is required!!"; return(Page()); } if (email == "") { Message = "Email is required!!"; return(Page()); } if (password == "") { Message = "Password cannot be left empty!!"; return(Page()); } bool usernameCheck = UserNameTaken(User.UserName); bool emailCheck = EmailTaken(User.Email); if (usernameCheck == true) { //That means the username is taken Message = "UserName is already Taken!!Try Again!!"; return(Page()); } if (emailCheck == true) { //That means the email is taken Message = "Email is already registered!!"; return(Page()); } _context.User.Add(User); await _context.SaveChangesAsync(); Success = "You have successfully registered."; 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()); } AppCondition app = await _context.AppCondition.FirstOrDefaultAsync(app => app.AppConditionId.Equals(1)); allUsers = await _context.User.ToListAsync(); allEvents = await _context.Event.ToListAsync(); //Before we go and update the data we need to make sure of certain things //Team Name if unique within the event //We search if there is a team with same name //IList<Team> allTeams = await _context.Team.Where(t => t.EventID.Equals(Team.EventID)).ToListAsync(); Team team1 = await _context.Team.FirstOrDefaultAsync(t => t.UserID.Equals(Team.TeamName) && t.EventID.Equals(app.EventID)); if (team1 != null) { Message = "Team with same name exists!!"; allUsers = await _context.User.ToListAsync(); allEvents = await _context.Event.ToListAsync(); allTeams = await _context.Team.ToListAsync(); Team = await _context.Team.FirstOrDefaultAsync(t => t.TeamId.Equals(Team.TeamId)); return(Page()); } //We prevent the admin from making changes to username, joincode and EventID //The reason being they have a lot of dependency and wrong changes can crash the system //So for now we just leave it and figure out an alternative for that if (ModelState.IsValid) { Team team = await _context.Team.FirstOrDefaultAsync(t => t.TeamId.Equals(Team.TeamId) && t.EventID.Equals(app.EventID)); team.ProjectName = Team.ProjectName; team.Idea = Team.Idea; //We are not going to edit theme here await _context.SaveChangesAsync(); return(RedirectToPage("AllTeams")); } Message = "Something went wrong!! Please try again!!"; return(Page()); }
// 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.VoteCount.Add(VoteCount); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (Event.EventCode.Trim() == "") { Message = "Event Code cannot be empty!!"; return(Page()); } Event eve = await _context.Event.FirstOrDefaultAsync(eve => eve.EventCode.Equals(Event.EventCode)); if (eve != null) { Message = "The event Code has to be unique!! try again"; return(Page()); } if (!ModelState.IsValid) { return(Page()); } _context.Event.Add(Event); await _context.SaveChangesAsync(); //Now we need to update the app event id with this new id AppCondition app = await _context.AppCondition.FirstOrDefaultAsync(app => app.AppConditionId.Equals(1)); Event newEvent = await _context.Event.FirstOrDefaultAsync(e => e.EventCode.Equals(Event.EventCode)); //Now the event id must be updated with the new event created app.EventID = newEvent.EventId; await _context.SaveChangesAsync(); return(RedirectToPage("./CreateNewThemeForEvent")); }
// 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() { // Checking user's logged in role string username = HttpContext.Session.GetString("username"); if (username == null) { return(RedirectToPage("/Privacy")); } AppCondition app = await _context.AppCondition.FirstOrDefaultAsync(app => app.AppConditionId.Equals(1)); if (username == app.AdminName) { isAdmin = true; } else { isAdmin = false; } if (!ModelState.IsValid) { EventsList = await _context.Event.ToListAsync(); return(Page()); } _context.Attach(Theme).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ThemeExists(Theme.ThemeId)) { return(NotFound()); } else { throw; } } 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()); } AppCondition app = await _context.AppCondition.FirstOrDefaultAsync(app => app.AppConditionId.Equals(1)); app.VotesAllowed = AppCondition.VotesAllowed; app.MemberPerTeam = AppCondition.MemberPerTeam; await _context.SaveChangesAsync(); return(RedirectToPage("./Privacy")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } TieBreaker = await _context.TieBreaker.FindAsync(id); if (TieBreaker != null) { _context.TieBreaker.Remove(TieBreaker); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Event = await _context.Event.FindAsync(id); if (Event != null) { _context.Event.Remove(Event); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } TeamPresentation = await _context.TeamPresentation.FindAsync(id); if (TeamPresentation != null) { _context.TeamPresentation.Remove(TeamPresentation); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(RedirectToPage("MyTeam")); } AppCondition app = await _context.AppCondition.FirstOrDefaultAsync(app => app.AppConditionId.Equals(1)); Member = await _context.Member.FirstOrDefaultAsync(m => m.MemberId.Equals(id) && m.EventID.Equals(app.EventID)); if (Member != null) { _context.Member.Remove(Member); await _context.SaveChangesAsync(); return(RedirectToPage("JoinTeam")); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { string username = HttpContext.Session.GetString("username"); if (username == null) { return(RedirectToPage("Privacy")); } AppCondition app = await _context.AppCondition.FirstOrDefaultAsync(app => app.AppConditionId.Equals(1)); //Now we have to find the user's memberId to remove it from the current team Member member = await _context.Member.FirstOrDefaultAsync(m => m.UserName.Equals(username) && m.EventID.Equals(app.EventID)); if (member != null) { _context.Member.Remove(member); await _context.SaveChangesAsync(); return(RedirectToPage("JoinTeam")); } return(RedirectToPage("./Privacy")); }
public async Task <IActionResult> OnPostAsync() { string username = HttpContext.Session.GetString("username"); AppCondition app = await _context.AppCondition.FirstOrDefaultAsync(app => app.AppConditionId.Equals(1)); //Since there is possibility of a tie we just get rid of the tie teams from before IList <TieBreaker> ties = await _context.TieBreaker.ToListAsync(); allEvents = await _context.Event.ToListAsync(); allUsers = await _context.User.ToListAsync(); if (ties != null) { foreach (var tie in ties) { _context.TieBreaker.Remove(tie); await _context.SaveChangesAsync(); } } if (username.Equals(app.AdminName)) { isAdmin = true; } else { isAdmin = false; return(RedirectToPage("Privacy")); } int highvotes = 0; IList <Judge> allJudges = await _context.Judge.Where(j => j.EventID.Equals(app.EventID)).ToListAsync(); if (Team == null) { Team = await _context.Team.Where(t => t.EventID.Equals(app.EventID)).ToListAsync(); foreach (var team in Team) { team.UserID = 0; } if (Team.Count() == 0) { //Which means no team has been created for the specific event Message = "Unfortunalty no team has been created for this event!!"; return(Page()); } if (app.AdminName.Equals(username)) { isAdmin = true; } else { isAdmin = false; } foreach (var judge in allJudges) { //We need to load all the votes each judge has made IList <Vote> allVotes = await _context.Vote.Where(v => v.UserID.Equals(judge.UserID) && v.EventID.Equals(app.EventID)).ToListAsync(); foreach (var vote in allVotes) { foreach (var team in Team) { if (vote.TeamID.Equals(team.TeamId)) { //So now that we have found the vote for the team //We wil just increment the vote for each team team.UserID += 1; } } } } } foreach (var team in Team) { if (team.UserID >= highvotes) { highvotes = team.UserID; } } JudgeWinner judgeWinner = await _context.JudgeWinner.FirstOrDefaultAsync(jw => jw.EventID.Equals(app.EventID)); if (judgeWinner != null) { Message = "Winner for the event has been finalized!!"; isAdmin = true; return(Page()); } foreach (var team in Team) { //Now we find how many teams have got the highest votes Team newTeam = await _context.Team.FirstOrDefaultAsync(t => t.TeamId.Equals(team.TeamId) && t.EventID.Equals(app.EventID)); if (team.UserID.Equals(highvotes)) { TieBreaker tieBreaker = new TieBreaker() { UserID = newTeam.UserID, EventID = newTeam.EventID, TeamID = newTeam.TeamId, }; //Then we store each team with the highest votes _context.TieBreaker.Add(tieBreaker); await _context.SaveChangesAsync(); } } //Now we perform checks wether there is a tie breaker or not //For that we load all the teams which have been aded for the event IList <TieBreaker> tieBreakers = await _context.TieBreaker.Where(tie => tie.EventID.Equals(app.EventID)).ToListAsync(); if (tieBreakers.Count() == 1) { Team team = await _context.Team.FirstOrDefaultAsync(t => t.TeamId.Equals(tieBreakers[0].TeamID) && t.EventID.Equals(tieBreakers[0].EventID)); JudgeWinner judgeWinner1 = new JudgeWinner() { EventID = team.EventID, TeamID = team.TeamId, TeamName = team.TeamName, UserID = team.UserID }; _context.JudgeWinner.Add(judgeWinner1); await _context.SaveChangesAsync(); //Now that we have saved the winner for the event to the judge winner list //Now we just have to delete the tie breaker before we exit _context.TieBreaker.Remove(tieBreakers[0]); await _context.SaveChangesAsync(); return(RedirectToPage("JudgeWinnerList")); } else { return(RedirectToPage("TieBreaakForJudgeWinner")); } }
public async Task <IActionResult> OnPostAsync() { string username = HttpContext.Session.GetString("username"); AppCondition app = await _context.AppCondition.FirstOrDefaultAsync(app => app.AppConditionId.Equals(1)); IList <TieBreaker> tiees = await _context.TieBreaker.Where(tie => tie.EventID.Equals(app.EventID)).ToListAsync(); if (tiees != null) { foreach (var tie in tiees) { _context.TieBreaker.Remove(tie); await _context.SaveChangesAsync(); } } if (username.Equals(app.AdminName)) { isAdmin = true; } else { //Since only admin is supposed to use this functionality we send the other user back isAdmin = false; return(RedirectToPage("Privacy")); } int highVotes = 0; if (Team == null) { Team = await _context.Team.Where(t => t.EventID.Equals(app.EventID)).ToListAsync(); IList <User> Users = await _context.User.ToListAsync(); foreach (var team in Team) { //WE will be using Userid as a place to store the total votes for a team team.UserID = 0; } User loginUser = await _context.User.FirstOrDefaultAsync(u => u.UserName.Equals(username)); if (app.AdminName.Equals(username)) { isAdmin = true; } else { isAdmin = false; } foreach (var user in Users) { //Firstly we need to fetch all the vote users has for this session IList <Vote> userVotes = await _context.Vote.Where(v => v.UserID.Equals(user.UserId) && v.EventID.Equals(app.EventID)).ToListAsync(); //Next based on the vote we assign or increment each vote by one based on the respective user votes foreach (var vote in userVotes) { foreach (var team in Team) { if (vote.TeamID.Equals(team.TeamId)) { //That is the user has voted for this team in the event //So we just increament the team vote by one team.UserID += 1; } } } } } foreach (var team in Team) { if (team.UserID >= highVotes) { highVotes = team.UserID; } } PeopleWinner peopleWinner = await _context.PeopleWinner.FirstOrDefaultAsync(peopleWin => peopleWin.EventID.Equals(app.EventID)); if (peopleWinner != null) { Message = "People Winner has already been decided before!! If you wish to change remove that team first"; isAdmin = true; return(Page()); } //Now that we have to the highest votes we need to find the teams which have recieve high votes foreach (var team in Team) { //We store the team details of each team in a dummy team object for later use Team newTeam = await _context.Team.FirstOrDefaultAsync(t => t.TeamId.Equals(team.TeamId) && t.EventID.Equals(app.EventID)); if (team.UserID.Equals(highVotes)) { TieBreaker tie = new TieBreaker() { UserID = newTeam.UserID, EventID = newTeam.EventID, TeamID = newTeam.TeamId, }; //Now that we know that a team has got highest votes we need to store it within tie breaker _context.TieBreaker.Add(tie); await _context.SaveChangesAsync(); } } //Now we load the team which have got the highest votes for the current event //So we check if we have a tie by checkingthe tie team for the current event IList <TieBreaker> ties = await _context.TieBreaker.Where(tie => tie.EventID.Equals(app.EventID)).ToListAsync(); if (ties.Count() == 1) { Team team = await _context.Team.FirstOrDefaultAsync(t => t.TeamId.Equals(ties[0].TeamID) && t.EventID.Equals(ties[0].EventID)); PeopleWinner people = new PeopleWinner() { EventID = ties[0].EventID, TeamID = ties[0].TeamID, TeamName = team.TeamName, UserID = ties[0].UserID }; _context.PeopleWinner.Add(people); await _context.SaveChangesAsync(); //Now that we know that we don't have a tie breaker for people winner //We will just have to remove the tie breaker teams IList <TieBreaker> tiebreakers = await _context.TieBreaker.Where(tie => tie.EventID.Equals(app.EventID)).ToListAsync(); foreach (var tie in tiebreakers) { _context.TieBreaker.Remove(tie); await _context.SaveChangesAsync(); } return(RedirectToPage("PeopleWinnerList")); } else { //Which would mean that there is same votes among current event teams return(RedirectToPage("TieBreak")); //So for now we won't delete teams but will do it later on } }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { //Which shouldn't be the case as only admin can access this page return(RedirectToPage("ManageJudges")); } AppCondition app = await _context.AppCondition.FirstOrDefaultAsync(app => app.AppConditionId.Equals(1)); Event eve = await _context.Event.FirstOrDefaultAsync(eve => eve.EventId.Equals(app.EventID)); EventCode = eve.EventCode; EventName = eve.EventName; //So there are few things to consider before we can assign judges //That is to make sure they haven't accidently created teams before they were assigned //If they have teams we need to make sure we delete teams and their members User user = await _context.User.FirstOrDefaultAsync(u => u.UserId.Equals(id)); if (user == null) { //Which can mean something went wrong //So we just send the admin back to the Judges management page return(RedirectToPage("ManageJudges")); } //Now we have to check if admin is trying to either remove or add this user to the judges table IList <Judge> judges = await _context.Judge.Where(j => j.EventID.Equals(app.EventID)).ToListAsync(); foreach (var judge in judges) { if (judge.UserID.Equals(user.UserId)) { //Which means the admin is trying to remvoe this user _context.Judge.Remove(judge); await _context.SaveChangesAsync(); return(RedirectToPage("ManageJudges")); } } //So now we make sure to delete their teams Team team = await _context.Team.FirstOrDefaultAsync(t => t.UserID.Equals(user.UserId) && t.EventID.Equals(app.EventID)); if (team != null) { //We need to check for the members of that team IList <Member> teamMemebers = await _context.Member.Where(m => m.TeamID.Equals(team.TeamId) && team.EventID.Equals(app.EventID)).ToListAsync(); foreach (var mem in teamMemebers) { _context.Member.Remove(mem); await _context.SaveChangesAsync(); } //Now we just have to delete the team _context.Team.Remove(team); await _context.SaveChangesAsync(); //WE also need to get rid of the votes for the judges team //Otherwise those will still be counted when counting total winner IList <Vote> allVotes = await _context.Vote.Where(v => v.TeamID.Equals(team.TeamId) && v.EventID.Equals(team.EventID)).ToListAsync(); foreach (var vote in allVotes) { _context.Vote.Remove(vote); await _context.SaveChangesAsync(); } } var themeid = Int32.Parse(Request.Form["themeid"]); Judge newJudge = new Judge() { EventID = app.EventID, UserID = user.UserId, UserName = user.UserName, ThemeID = themeid }; _context.Judge.Add(newJudge); await _context.SaveChangesAsync(); return(RedirectToPage("./ManageJudges")); }
public async Task <IActionResult> OnPostAsync() { AppCondition app = await _context.AppCondition.FirstOrDefaultAsync(app => app.AppConditionId.Equals(1)); AllTeams = await _context.Team.Where(t => t.EventID.Equals(app.EventID)).ToListAsync(); var themeid = Int32.Parse(Request.Form["themeid"]); //Before we save we need to make sure team name is unique among the team for a specific event foreach (var team in AllTeams) { if (team.TeamName.Equals(Team.TeamName)) { Message = "Team Name has to be Unique!! Try Again!!"; allThemes = await _context.Theme.Where(t => t.EventID.Equals(app.EventID)).Select( a => new SelectListItem { Value = a.ThemeId.ToString(), Text = a.ThemeName } ).ToListAsync(); return(Page()); } } //Since the user editted the theme we need to check Team theteam = await _context.Team.FirstOrDefaultAsync(t => t.TeamId.Equals(Team.TeamId) && t.EventID.Equals(app.EventID)); if (theteam.ThemeID != themeid) { //So that would mean that the team has changed their team theme //Because of that we need to remove all the judges votes for that team IList <Judge> allJudges = await _context.Judge.Where(j => j.EventID.Equals(app.EventID)).ToListAsync(); //Now that i have the judges need to check who voted for this team foreach (var judge in allJudges) { //Now we load all the votes made by this judge IList <Vote> allVotes = await _context.Vote.Where(v => v.UserID.Equals(judge.UserID) && v.EventID.Equals(app.EventID)).ToListAsync(); //If a vote is for this team //We will remove the votes otherwise not foreach (var vote in allVotes) { if (vote.TeamID.Equals(theteam.TeamId)) { _context.Vote.Remove(vote); await _context.SaveChangesAsync(); } } } } if (ModelState.IsValid) { theteam.ThemeID = themeid; theteam.ProjectName = Team.ProjectName; theteam.Idea = Team.Idea; await _context.SaveChangesAsync(); return(RedirectToPage("MyTeam")); } return(RedirectToPage("MyTeam")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Team = await _context.Team.FindAsync(id); if (Team == null) { return(RedirectToPage("Privacy")); } //Now that we are removing the team from the application database //we need to remove the traces of it as well otherwise they are likely to mess up with the //user experience and data management //1. We remove all the members of this team IList <Member> allMembers = await _context.Member.Where(m => m.TeamID.Equals(Team.TeamId)).ToListAsync(); foreach (var mem in allMembers) { _context.Member.Remove(mem); await _context.SaveChangesAsync(); } //2.We need to get rid of all the votes for this team IList <Vote> allVotes = await _context.Vote.Where(v => v.TeamID.Equals(Team.TeamId)).ToListAsync(); foreach (var vote in allVotes) { _context.Vote.Remove(vote); await _context.SaveChangesAsync(); } //3. We need to get rid of the presentation TeamPresentation teamPresentation = await _context.TeamPresentation.FirstOrDefaultAsync(tp => tp.TeamID.Equals(Team.TeamId)); if (teamPresentation != null) { //Before we remove from the table //We need to remove it from the Files folder string storedFile = teamPresentation.FileName; var oldPath = Path.Combine(Directory.GetCurrentDirectory(), "Files", storedFile); if (System.IO.File.Exists(oldPath)) { System.IO.File.Delete(oldPath); _context.TeamPresentation.Remove(teamPresentation); await _context.SaveChangesAsync(); } else { _context.TeamPresentation.Remove(teamPresentation); await _context.SaveChangesAsync(); } } //Now we just remove the team as a final step _context.Team.Remove(Team); await _context.SaveChangesAsync(); return(RedirectToPage("./AllTeams")); }
// 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()); } //Now we add userid, event id and joincode over here string username = HttpContext.Session.GetString("username"); User user = _context.User.FirstOrDefault(u => u.UserName.Equals(username)); var themeid = Int32.Parse(Request.Form["theme"]); ///Which will not be null as we checked earlier in get function AppCondition app = _context.AppCondition.FirstOrDefault(app => app.AppConditionId.Equals(1)); Team.UserID = user.UserId; Team.EventID = app.EventID; //Since we are going tp later create a join link for members //We need to make sure that the team joincode is unique //For a given team for a current event IList <Team> teams = _context.Team.Where(t => t.EventID.Equals(app.EventID)).ToList(); foreach (var team in teams) { if (team.TeamName.Equals(Team.TeamName)) { //That is team name is already taken Message = "The team name already exist!!Try Again!!"; return(Page()); } } //Not sure about the event id for now //Just have to perform the checks on it allThemes = await _context.Theme.Where(t => t.EventID.Equals(app.EventID)).Select(a => new SelectListItem { Value = a.ThemeId.ToString(), Text = a.ThemeName }).ToListAsync(); bool PasswordExist = true; while (PasswordExist) { RandomNumberGenerator random = new RandomNumberGenerator(); string joincode = random.RandomPassword(); PasswordExist = false; foreach (var team in teams) { if (team.JoinCode.Equals(joincode)) { PasswordExist = true; break; } } Team.JoinCode = joincode; } Team.ThemeID = themeid; _context.Team.Add(Team); await _context.SaveChangesAsync(); return(RedirectToPage("./Privacy")); }