private bool DoUpdates(ImportAthleteAction importAthleteAction) { if (importAthleteAction.Exception != null) { return(false); } var athleteMgmt = new AthleteManagement(Global.ConnectionString, SessionProps); if (!importAthleteAction.AthleteIsStored || !importAthleteAction.AthleteClubIsStored || !importAthleteAction.AthleteClubIsUpToDate) { Action <string, Guid> TweetAction = (tweet, athleteClubGuid) => { //no tweeting when mass importing }; athleteMgmt.SaveAthlete(importAthleteAction.AthleteClub.Inti_Athlete.FirstName, importAthleteAction.AthleteClub.Inti_Athlete.LastName, importAthleteAction.AthleteClub.Inti_Athlete.GUID, SelectedTournament, importAthleteAction.AthleteClub.ClubGUID, importAthleteAction.AthleteClub.PositionGUID, importAthleteAction.AthleteClub.Price ?? 0, true, importAthleteAction.AthleteClub.Inti_Club.ShortName, TweetAction); } return(true); }
protected void btnPocessImport_Click(object sender, EventArgs e) { ImportAthleteActions = new List <ImportAthleteAction>(); var counter = 0; foreach (GridViewRow row in grdAthletesToImport.Rows) { //is proceed checked? var proceedCheckBox = (CheckBox)row.FindControl("chkProceed"); if (proceedCheckBox.Checked && !String.IsNullOrEmpty(row.Cells[3].Text)) { var playerDetails = row.Cells[1].Text.Split(new string[] { "," }, StringSplitOptions.None); ImportAthleteAction importAthleteAction; var thisPlayerDetails = GetPlayerDetails(playerDetails); if (thisPlayerDetails != null) { importAthleteAction = GetOrCreateAthleteImportAction(SelectedTournament, thisPlayerDetails); } else { importAthleteAction = new ImportAthleteAction() { Exception = new Exception(String.Format("Input not valid for {0}", row.Cells[1].Text)) }; } //perpetuate in string importAthleteAction.InString = row.Cells[1].Text; ImportAthleteActions.Add(importAthleteAction); } counter++; } foreach (var importAthleteAction in ImportAthleteActions) { importAthleteAction.Done = DoUpdates(importAthleteAction); counter++; if (UpdateThePanel(counter)) { SetDataSource(false); } } //refresh datasource SetDataSource(true); }
protected void btnPocessImport_Click(object sender, EventArgs e) { ImportAthleteActions = new List<ImportAthleteAction>(); var counter = 0; foreach (GridViewRow row in grdAthletesToImport.Rows) { //is proceed checked? var proceedCheckBox = (CheckBox) row.FindControl("chkProceed"); if (proceedCheckBox.Checked && !String.IsNullOrEmpty(row.Cells[3].Text)) { var playerDetails = row.Cells[1].Text.Split(new string[] {","}, StringSplitOptions.None); ImportAthleteAction importAthleteAction; var thisPlayerDetails = GetPlayerDetails(playerDetails); if (thisPlayerDetails != null) { importAthleteAction = GetOrCreateAthleteImportAction(SelectedTournament,thisPlayerDetails); } else { importAthleteAction = new ImportAthleteAction() { Exception = new Exception(String.Format("Input not valid for {0}", row.Cells[1].Text)) }; } //perpetuate in string importAthleteAction.InString = row.Cells[1].Text; ImportAthleteActions.Add(importAthleteAction); } counter++; } foreach (var importAthleteAction in ImportAthleteActions) { importAthleteAction.Done = DoUpdates(importAthleteAction); counter++; if (UpdateThePanel(counter)) SetDataSource(false); } //refresh datasource SetDataSource(true); }
//private const int _firstName = 0; //private const int _lastName = 1; //private const int _club = 2; //private const int _position = 3; //private const int _price = 4; private void ProcessPlayerImportList(string players) { var playersArray = players.Split(new string[] { "\r\n", "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries); var counter = 0; var totalNumberOfPlayersToImport = playersArray.GetUpperBound(0); ImportAthleteActions = new List <ImportAthleteAction>(); foreach (var player in playersArray) { var playerDetails = player.Split(new string[] { "," }, StringSplitOptions.None); ImportAthleteAction athleteImportAction; var thisPlayerDetails = GetPlayerDetails(playerDetails); if (thisPlayerDetails != null) { athleteImportAction = GetOrCreateAthleteImportAction(SelectedTournament, thisPlayerDetails); } else { athleteImportAction = new ImportAthleteAction() { Exception = new Exception(String.Format("Input not valid for {0}", player)) }; } athleteImportAction.InString = player; athleteImportAction.Done = (athleteImportAction.AthleteIsStored && athleteImportAction.AthleteClubIsStored && athleteImportAction.AthleteClubIsUpToDate); ImportAthleteActions.Add(athleteImportAction); counter++; if (UpdateThePanel(counter)) { SetDataSource(false); } } SetDataSource(true); }
private string GetImportAction(ImportAthleteAction athleteImportAction) { string importActions = athleteImportAction.ImportAction ?? ""; if (!athleteImportAction.AthleteIsStored) { importActions += (String.IsNullOrEmpty(importActions) ? "" : "\r\n") + _addAthlete; } if (!athleteImportAction.AthleteClubIsStored) { importActions += (String.IsNullOrEmpty(importActions) ? "" : "\r\n") + _addAthleteInTournament; } if (!athleteImportAction.AthleteClubIsUpToDate) { importActions += (String.IsNullOrEmpty(importActions) ? "" : "\r\n") + _updateAthlete; } return(importActions); }
//private const int _firstName = 0; //private const int _lastName = 1; //private const int _club = 2; //private const int _position = 3; //private const int _price = 4; private void ProcessPlayerImportList(string players) { var playersArray = players.Split(new string[] {"\r\n", "\n", "\r"}, StringSplitOptions.RemoveEmptyEntries); var counter = 0; var totalNumberOfPlayersToImport = playersArray.GetUpperBound(0); ImportAthleteActions = new List<ImportAthleteAction>(); foreach (var player in playersArray) { var playerDetails = player.Split(new string[] {","}, StringSplitOptions.None); ImportAthleteAction athleteImportAction; var thisPlayerDetails = GetPlayerDetails(playerDetails); if (thisPlayerDetails != null) { athleteImportAction = GetOrCreateAthleteImportAction(SelectedTournament, thisPlayerDetails); } else { athleteImportAction = new ImportAthleteAction() { Exception = new Exception(String.Format("Input not valid for {0}", player)) }; } athleteImportAction.InString = player; athleteImportAction.Done = (athleteImportAction.AthleteIsStored && athleteImportAction.AthleteClubIsStored && athleteImportAction.AthleteClubIsUpToDate); ImportAthleteActions.Add(athleteImportAction); counter++; if (UpdateThePanel(counter)) SetDataSource(false); } SetDataSource(true); }
private ImportAthleteAction GetOrCreateAthleteImportAction(Guid selectedTournament, PlayerDetails playerDetails) { var importAthleteAction = new ImportAthleteAction(); try { //verify and get club var club = new ClubManagement(Global.ConnectionString, SessionProps).GetClubByCode(selectedTournament, playerDetails.ClubCode); //verify and get position Inti_Position position = null; if (!String.IsNullOrEmpty(playerDetails.PosCode)) position = new CommonDataFetches(Global.ConnectionString, SessionProps).GetPosition(playerDetails.PosCode); //try to get athlete var athlete = new AthleteManagement(Global.ConnectionString, SessionProps).GetAthleteByName(playerDetails.FirstName, playerDetails.LastName); importAthleteAction.AthleteIsStored = (athlete != null); if (athlete == null) { //athlete is added with full name? var searchString = String.IsNullOrEmpty(playerDetails.FirstName) ? playerDetails.LastName : String.Format("{0}, {1}", playerDetails.FirstName, playerDetails.LastName); IList<Inti_Athlete> matchingAthletes; using (var db = Global.GetConnection()) { matchingAthletes = Searching.SearchForAthletes(db, searchString); } if (matchingAthletes.Count == 0) { //do we have position? if (position != null) { //create new athlete athlete = new Inti_Athlete(); athlete.FirstName = playerDetails.FirstName; athlete.LastName = playerDetails.LastName; } else { importAthleteAction.Exception = new Exception("Ny spelare men position saknas. Ange med position"); } } else { if (matchingAthletes.Count ==1) { athlete = matchingAthletes[0]; importAthleteAction.ImportAction += "OBS, kontrollera namnet. "; } else { var message = "Flera spelare matchar namnet:"; foreach (var matchingAthlete in matchingAthletes) { message += (matchingAthlete.FirstName + " " + matchingAthlete.LastName).Trim() + ", "; } importAthleteAction.Exception = new Exception(message); } } } if (athlete != null) { //is the athlete already in tournament? var athleteClub = new AthleteManagement(Global.ConnectionString, SessionProps).GetAthleteClubByTournament(athlete.GUID, selectedTournament); importAthleteAction.AthleteClubIsStored = (athleteClub != null); importAthleteAction.AthleteClubIsUpToDate = true; if (athleteClub == null) { if(position != null) { athleteClub = new Inti_AthleteClub(); athleteClub.Inti_Athlete = athlete; athleteClub.Inti_Club = club; athleteClub.Inti_Position = position; athleteClub.Price = playerDetails.Price; } else { importAthleteAction.Exception = new Exception("Befintlig spelare men position saknas. Ange med position"); } } else { importAthleteAction.AthleteClubIsUpToDate = (athleteClub.Inti_Club.GUID == club.GUID); //new club if (athleteClub.Inti_Club.GUID != club.GUID) { athleteClub.Inti_Club = club; } if (position != null && athleteClub.Inti_Position.GUID != position.GUID) { importAthleteAction.Exception = new Exception(String.Format("Changed position from {0} to {1}, is it the correct player?", athleteClub.Inti_Position.ShortName, position.ShortName)); } if (athleteClub.Price != playerDetails.Price) { importAthleteAction.Exception = new Exception(String.Format("Changed price from {0} to {1}, is it the correct player?", athleteClub.Price, playerDetails.Price)); } } //set import action importAthleteAction.ImportAction += GetImportAction(importAthleteAction); importAthleteAction.AthleteClub = athleteClub; } } catch (Exception exception) { importAthleteAction.Exception = exception; } return importAthleteAction; }
private string GetImportAction(ImportAthleteAction athleteImportAction) { string importActions = athleteImportAction.ImportAction ?? ""; if(!athleteImportAction.AthleteIsStored) { importActions += (String.IsNullOrEmpty(importActions) ? "" : "\r\n") + _addAthlete; } if(!athleteImportAction.AthleteClubIsStored) { importActions += (String.IsNullOrEmpty(importActions) ? "" : "\r\n") + _addAthleteInTournament; } if(!athleteImportAction.AthleteClubIsUpToDate) { importActions += (String.IsNullOrEmpty(importActions) ? "" : "\r\n") + _updateAthlete; } return importActions; }
private bool DoUpdates(ImportAthleteAction importAthleteAction) { if(importAthleteAction.Exception != null) return false; var athleteMgmt = new AthleteManagement(Global.ConnectionString, SessionProps); if (!importAthleteAction.AthleteIsStored || !importAthleteAction.AthleteClubIsStored || !importAthleteAction.AthleteClubIsUpToDate) { Action<string, Guid> TweetAction = (tweet, athleteClubGuid) => { //no tweeting when mass importing }; athleteMgmt.SaveAthlete(importAthleteAction.AthleteClub.Inti_Athlete.FirstName, importAthleteAction.AthleteClub.Inti_Athlete.LastName, importAthleteAction.AthleteClub.Inti_Athlete.GUID, SelectedTournament, importAthleteAction.AthleteClub.ClubGUID, importAthleteAction.AthleteClub.PositionGUID, importAthleteAction.AthleteClub.Price ?? 0, true, importAthleteAction.AthleteClub.Inti_Club.ShortName, TweetAction); } return true; }
private ImportAthleteAction GetOrCreateAthleteImportAction(Guid selectedTournament, PlayerDetails playerDetails) { var importAthleteAction = new ImportAthleteAction(); try { //verify and get club var club = new ClubManagement(Global.ConnectionString, SessionProps).GetClubByCode(selectedTournament, playerDetails.ClubCode); //verify and get position Inti_Position position = null; if (!String.IsNullOrEmpty(playerDetails.PosCode)) { position = new CommonDataFetches(Global.ConnectionString, SessionProps).GetPosition(playerDetails.PosCode); } //try to get athlete var athlete = new AthleteManagement(Global.ConnectionString, SessionProps).GetAthleteByName(playerDetails.FirstName, playerDetails.LastName); importAthleteAction.AthleteIsStored = (athlete != null); if (athlete == null) { //athlete is added with full name? var searchString = String.IsNullOrEmpty(playerDetails.FirstName) ? playerDetails.LastName : String.Format("{0}, {1}", playerDetails.FirstName, playerDetails.LastName); IList <Inti_Athlete> matchingAthletes; using (var db = Global.GetConnection()) { matchingAthletes = Searching.SearchForAthletes(db, searchString); } if (matchingAthletes.Count == 0) { //do we have position? if (position != null) { //create new athlete athlete = new Inti_Athlete(); athlete.FirstName = playerDetails.FirstName; athlete.LastName = playerDetails.LastName; } else { importAthleteAction.Exception = new Exception("Ny spelare men position saknas. Ange med position"); } } else { if (matchingAthletes.Count == 1) { athlete = matchingAthletes[0]; importAthleteAction.ImportAction += "OBS, kontrollera namnet. "; } else { var message = "Flera spelare matchar namnet:"; foreach (var matchingAthlete in matchingAthletes) { message += (matchingAthlete.FirstName + " " + matchingAthlete.LastName).Trim() + ", "; } importAthleteAction.Exception = new Exception(message); } } } if (athlete != null) { //is the athlete already in tournament? var athleteClub = new AthleteManagement(Global.ConnectionString, SessionProps).GetAthleteClubByTournament(athlete.GUID, selectedTournament); importAthleteAction.AthleteClubIsStored = (athleteClub != null); importAthleteAction.AthleteClubIsUpToDate = true; if (athleteClub == null) { if (position != null) { athleteClub = new Inti_AthleteClub(); athleteClub.Inti_Athlete = athlete; athleteClub.Inti_Club = club; athleteClub.Inti_Position = position; athleteClub.Price = playerDetails.Price; } else { importAthleteAction.Exception = new Exception("Befintlig spelare men position saknas. Ange med position"); } } else { importAthleteAction.AthleteClubIsUpToDate = (athleteClub.Inti_Club.GUID == club.GUID); //new club if (athleteClub.Inti_Club.GUID != club.GUID) { athleteClub.Inti_Club = club; } if (position != null && athleteClub.Inti_Position.GUID != position.GUID) { importAthleteAction.Exception = new Exception(String.Format("Changed position from {0} to {1}, is it the correct player?", athleteClub.Inti_Position.ShortName, position.ShortName)); } if (athleteClub.Price != playerDetails.Price) { importAthleteAction.Exception = new Exception(String.Format("Changed price from {0} to {1}, is it the correct player?", athleteClub.Price, playerDetails.Price)); } } //set import action importAthleteAction.ImportAction += GetImportAction(importAthleteAction); importAthleteAction.AthleteClub = athleteClub; } } catch (Exception exception) { importAthleteAction.Exception = exception; } return(importAthleteAction); }