public async Task <List <TeamViewModel> > GetTeamsByLeagueId(string leagueID, CancellationToken ct = default(CancellationToken)) { // given league ID retrieve all teams List <TeamViewModel> teams = TeamConverter.ConvertList(await this._teamRepository.GetAllByLeagueIdAsync(leagueID, ct)); return(teams); }
public async Task <bool> DeleteTeamAsync(string id, CancellationToken ct = default(CancellationToken)) { TeamViewModel teamToDelete = TeamConverter.Convert(await this._teamRepository.GetByIdAsync(id, ct)); if (teamToDelete == null) { return(false); } return(await this._teamRepository.DeleteAsync(teamToDelete.Id, ct)); }
public async Task <List <TeamViewModel> > GetUnassignedTeams(CancellationToken ct = default(CancellationToken)) { List <TeamViewModel> unassignedTeams = TeamConverter.ConvertList(await this._teamRepository.GetUnassignedTeams(ct)); foreach (TeamViewModel team in unassignedTeams) { team.LeagueID = UNASSIGNED; } return(unassignedTeams); }
/// <summary> /// For internal OSBLE use. Do not expose directly as a web service. Instead, use /// GetMergedReviewDocument(int criticalReviewAssignmentId, string authToken) for /// that purpose. /// </summary> /// <param name="criticalReviewAssignmentId"></param> /// <returns></returns> public byte[] GetMergedReviewDocument(int criticalReviewAssignmentId, int userProfileId) { UserProfile profile = _db.UserProfiles.Find(userProfileId); Assignment criticalReviewAssignment = _db.Assignments.Find(criticalReviewAssignmentId); if (criticalReviewAssignment == null) { return(new byte[0]); } //were we handed a discussion assignment ID by accident? if (criticalReviewAssignment.Type == AssignmentTypes.CriticalReviewDiscussion) { if (criticalReviewAssignment.PreceedingAssignment.Type == AssignmentTypes.CriticalReview) { criticalReviewAssignment = criticalReviewAssignment.PreceedingAssignment; criticalReviewAssignmentId = criticalReviewAssignment.ID; } else { return(new byte[0]); } } //AC: The rules listed below are too convoluted for the average instructor to //remember. Commenting out for now. /* * if (criticalReviewAssignment.Type != AssignmentTypes.CriticalReviewDiscussion) * { * //only continue if: * // a: the assignment's due date has passed * // b: the assignment is set up to release critical reviews to students after * // the due date. * // c: the instructor has clicked the "Publish All Reviews" link on the * // assignment details page. (turned off for now) * if (criticalReviewAssignment.DueDate > DateTime.UtcNow || || (criticalReviewAssignment.CriticalReviewSettings != null && criticalReviewAssignment.CriticalReviewSettings.AllowDownloadAfterPublish == false) || ) ||{ || return new byte[0]; ||} ||} * */ //make sure that the user is enrolled in the course CourseUser courseUser = (from cu in _db.CourseUsers where cu.AbstractCourseID == criticalReviewAssignment.CourseID && cu.UserProfileID == profile.ID select cu).FirstOrDefault(); if (courseUser == null) { return(new byte[0]); } //Two possible scenarios: //1: we're dealing with a non-discussion based critical review. In this case, pull all // teams from the "review team" table //2: we're dealing with a discussion-based critical review. In this case, pull from the // "discussion team" table. Note that discussion teams are a superset of review teams // so that everything in a review team will also be inside a discussion team. Pulling // from discussion teams allows us to capture moderators and other observer-type // people that have been attached to the review process. //step 1: check to see if the critical review assignment has any discussion assignments attached Assignment discussionAssignment = (from a in _db.Assignments where a.PrecededingAssignmentID == criticalReviewAssignmentId && a.AssignmentTypeID == (int)AssignmentTypes.CriticalReviewDiscussion select a ).FirstOrDefault(); IList <IReviewTeam> authorTeams = new List <IReviewTeam>(); if (discussionAssignment != null) { //pull the more inclusive discussion teams List <DiscussionTeam> discussionTeams = (from dt in _db.DiscussionTeams join team in _db.Teams on dt.TeamID equals team.ID join member in _db.TeamMembers on team.ID equals member.TeamID where member.CourseUserID == courseUser.ID && dt.AssignmentID == discussionAssignment.ID select dt).ToList(); authorTeams = TeamConverter.DiscussionToReviewTeam(discussionTeams); } else { //pull critical review teams authorTeams = (from rt in _db.ReviewTeams join team in _db.Teams on rt.ReviewTeamID equals team.ID join member in _db.TeamMembers on team.ID equals member.TeamID where member.CourseUserID == courseUser.ID && rt.AssignmentID == criticalReviewAssignmentId select rt).ToList().Cast <IReviewTeam>().ToList(); } //no author team means that the current user isn't assigned to review anyone if (authorTeams.Count == 0) { return(new byte[0]); } using (ZipFile finalZip = new ZipFile()) { foreach (ReviewTeam authorTeam in authorTeams) { //get all reviewers (not just the current user's review team) List <ReviewTeam> reviewers = (from rt in _db.ReviewTeams where rt.AuthorTeamID == authorTeam.AuthorTeamID select rt).ToList(); //get original document MemoryStream finalStream = new MemoryStream(); string originalFile = OSBLE.Models.FileSystem.Directories.GetAssignmentSubmission( (int)criticalReviewAssignment.CourseID, (int)criticalReviewAssignment.PrecededingAssignmentID, authorTeam.AuthorTeamID).AllFiles().FirstOrDefault(); if (originalFile == null) { //author didn't submit a document to be reviewed. Skip the rest. continue; } FileStream originalFileStream = File.OpenRead(originalFile); originalFileStream.CopyTo(finalStream); originalFileStream.Close(); finalStream.Position = 0; //loop through each review team, merging documents foreach (ReviewTeam reviewer in reviewers) { string teamName = reviewer.ReviewingTeam.Name; if (criticalReviewAssignment.CriticalReviewSettings.AnonymizeCommentsAfterPublish == true) { teamName = string.Format("Anonymous {0}", reviewer.ReviewTeamID); } FileCollection allFiles = OSBLE.Models.FileSystem.Directories.GetReview( (int)criticalReviewAssignment.CourseID, criticalReviewAssignmentId, authorTeam.AuthorTeamID, reviewer.ReviewTeamID) .AllFiles(); foreach (string file in allFiles) { MemoryStream mergedStream = new MemoryStream(); FileStream studentReview = System.IO.File.OpenRead(file); //merge ChemProV.Core.CommentMerger.Merge(finalStream, "", studentReview, teamName, mergedStream); //rewind merged stream and copy over to final stream mergedStream.Position = 0; finalStream = new MemoryStream(); mergedStream.CopyTo(finalStream); finalStream.Position = 0; mergedStream.Close(); studentReview.Close(); } } //finally, zip up and add to our list string documentName = Path.GetFileName(originalFile); string authorTeamName = authorTeam.AuthorTeam.Name; if (criticalReviewAssignment.CriticalReviewSettings.AnonymizeAuthor == true) { authorTeamName = string.Format("Anonymous {0}", authorTeam.ReviewTeamID); } string filePath = string.Format("{0};{1}/{2}", authorTeam.AuthorTeamID, authorTeamName, documentName ); finalZip.AddEntry(filePath, finalStream); } MemoryStream zipStream = new MemoryStream(); finalZip.Save(zipStream); zipStream.Position = 0; byte[] zipBytes = zipStream.ToArray(); zipStream.Close(); return(zipBytes); } }
public async Task <TeamViewModel> GetTeamByIdAsync(string id, CancellationToken ct = default(CancellationToken)) { TeamViewModel team = TeamConverter.Convert(await this._teamRepository.GetByIdAsync(id)); return(team); }
public DbTeam ToDbTeam() { return(TeamConverter.ToDbTeam(this)); }
private void DoLoadMatchData(object ids) { try { sync.Execute(() => pictureBox1.Visible = true); ShowStatus("Загрузка данных матча...", 0); Web.GetTeamColorsKind(); var idm = Int32.Parse(ids.ToString()); SizeF sizef; game = Web.GetMatchInfo(idm, out sizef); if (game == null) { throw new Exception("Нет матча или выбран неверный тип игры!"); } if (game.Match.Team1 == null || game.Match.Team1.Id == 0) { throw new Exception("Нет команды 1"); } if (game.Match.Team2 == null || game.Match.Team2.Id == 0) { throw new Exception("Нет команды 2"); } if (!sizef.IsEmpty) { game.FieldSize = sizef; } ShowStatus("Загрузка игроков команды " + game.Match.Team2.ToString() + "...", 0); Web.GetPlayers(game.Match.Team2); if (game.Match.Team2.Players.Count == 0) { throw new Exception("Нет состава команды " + game.Match.Team2); } ShowStatus("Загрузка игроков команды " + game.Match.Team1.ToString() + "...", 0); Web.GetPlayers(game.Match.Team1); if (game.Match.Team1.Players.Count == 0) { throw new Exception("Нет состава команды " + game.Match.Team1); } ShowStatus("Загрузка параметров матча...", 0); game.Match.Team1.FinePlaces.Clear(); game.Match.Team1.FinePlayers.Clear(); game.Match.Team2.FinePlaces.Clear(); game.Match.Team2.FinePlayers.Clear(); Web.GetTeamColors(game.Match.Team1); Web.GetTeamColors(game.Match.Team2); var txt = game.Match.Team1.Name + " - " + game.Match.Team2.Name; game.Markers.Clear(); sync.Execute(() => { label1.Text = game.Match.Tournament + " " + game.Match.Date.ToShortDateString() + " " + game.Match.Date.ToLongTimeString(); textBox4.Text = txt; }); ShowStatus("Загрузка маркеров...", 0); var lstSrv = Web.GetMarkers(game, game.Match.Id); List <Marker> lstLoc = MarkerList.LoadFromFile(game, game.Match.Id); foreach (Game.Marker mk in lstLoc) { mk.game = game; } foreach (var mk in lstLoc.Where(o => !o.FlagDel).OrderBy(o => o.Half.Index).ThenBy(o => o.TimeVideo)) { var period = mk.Half.Index; var half = game.HalfList.FirstOrDefault(o => o.Index == period); mk.Half = half; } game.Union(lstLoc, lstSrv); foreach (Game.Marker mk in game.Markers) { mk.row = null; } ShowStatus("Синхронизация...", 0); var pl = game.Match.Team1.Players.Concat(game.Match.Team2.Players).ToList <Player>(); //Восстановление и контроль составов foreach (var mk in game.Markers.Where(o => o.ActionId == 16)) { Team tm = null; try { tm = GetTeam(mk.team1_id, mk); mk.Team1 = tm; } catch (TeamMarkerException ex) { mk.FlagDel = true; ShowStatus(ex.Message, FormShowStatusCode.Error); Thread.Sleep(100); continue; } if (pl.Exists(o => o.Id == mk.player1_id)) { var p = pl.First(o => o.Id == mk.player1_id); if (mk is Game.Marker) { var mkg = (Game.Marker)mk; if (mkg.Num > 0) { p.Number = mkg.Num; } } var tm2 = game.Match.Team1 == tm ? game.Match.Team2 : game.Match.Team1; if (tm2.Players.Exists(o => o.Id == p.Id)) { throw new Exception(String.Format((string)"Ошибка в маркере расстановки {0}. Игрок {1} был в составе {2}, а теперь указан в команде соперника", (object)mk.Id, (object)p, tm2)); } p.Team = tm; mk.Player1 = p; if (!tm.Players.Exists(o => o.Id == p.Id)) { tm.Players.Add(p); } } else { if (mk.player1_id <= 0) { continue; } var p = Web.GetPlayer(mk.player1_id); if (p != null) { p.Team = tm; mk.Player1 = p; if (!tm.Players.Exists(o => o.Id == p.Id)) { tm.Players.Add(p); } if (!pl.Exists(o => o.Id == p.Id)) { pl.Add(p); } } else { throw new Exception("Критическая ошибка: не могу загрузить игрока ID=" + mk.player1_id + " из состава команды " + tm.Name); } } } game.Match.Team1.Players.AddRange( pl.Where(o => o.Team != null && o.Team.Id == game.Match.Team1.Id && !game.Match.Team1.Players.Exists(o1 => o1.Id == o.Id))); game.Match.Team2.Players.AddRange( pl.Where(o => o.Team != null && o.Team.Id == game.Match.Team2.Id && !game.Match.Team2.Players.Exists(o1 => o1.Id == o.Id))); var errmklist = new List <Marker>(); foreach (var mk in game.Markers.Where(o => o.ActionId != 16)) { if (mk.player1_id > 0) { var pla = pl.FirstOrDefault(o => o.Id == mk.player1_id); if (pla == null) { try { mk.Player1 = Web.GetPlayer(mk.player1_id); } catch { mk.FlagDel = true; errmklist.Add(mk); } } else { mk.Player1 = pla; } } else if (mk.team1_id > 0) { try { mk.Team1 = GetTeam(mk.team1_id, mk); } catch (Exception ex) { } } if (mk.player2_id > 0) { var opp = pl.FirstOrDefault(o => o.Id == mk.player2_id); if (opp == null) { try { mk.Player2 = Web.GetPlayer(mk.player2_id);; } catch { mk.FlagDel = true; errmklist.Add(mk); } } else { mk.Player2 = opp; } } else if (mk.team2_id > 0) { try { mk.Team2 = GetTeam(mk.team2_id, mk); } catch (Exception ex) { } } } game.RefreshOvertimes(); sync.Execute(() => { label1.Text = game.Match.Tournament + " " + game.Match.Date.ToShortDateString() + " " + game.Match.Date.ToLongTimeString(); textBox4.Text = txt; }); TeamDataRestore(game.Match.Team1); TeamDataRestore(game.Match.Team2); PlayerConverter.RefreshData(game.Match); TeamConverter.RefreshData(game.Match); sync.Execute(() => { checkBox1.Checked = !game.Match.Team1.Tactics[1].IsValid; checkBox2.Checked = !game.Match.Team1.Tactics[1].IsValid; comboBox1.Items.Clear(); foreach (var tc in game.Match.Team1.TeamColorsKind.Values) { comboBox1.Items.Add(tc); if (tc.Kind == game.Match.Team1.Color.Kind) { comboBox1.SelectedItem = tc; } } comboBox2.Items.Clear(); foreach (var tc in game.Match.Team2.TeamColorsKind.Values) { comboBox2.Items.Add(tc); if (tc.Kind == game.Match.Team2.Color.Kind) { comboBox2.SelectedItem = tc; } } changed_colors = false; }); if (errmklist.Count > 0) { var errmks = String.Empty; for (var i = 0; i < errmklist.Count; i++) { if (i <= 2) { if (i > 0) { errmks += ","; } errmks += errmklist[i].Id; if (i == 2) { errmks += "..."; } } } ShowStatus(String.Format("Ошибочно указаны некоторые игроки. Эти маркеры {0} помечены на удаление.", errmks), FormShowStatusCode.Error); } else { } game.RecalcActualTime(game.Markers, null); sync.Execute(() => hockeyField1.Game = game); ShowStatus("Готово", 0); } catch (Exception ex) { game = null; ShowStatus(ex.Message, FormShowStatusCode.Error); HockeyGui.InvalidateRect(); } finally { sync.Execute(() => { HockeyGui.InvalidateRect(); pictureBox1.Visible = false; }); loading = false; UpdateUI(); } }
public DbTeamAlternateName CopyWithoutNavigationProperties() { return(TeamConverter.CopyWithoutNavigationProperties(this)); }