public static string Town(string townName, string countryName) { checkData = CheckDataIsNotEmpty(townName, "Town"); if (checkData != "Ok") { return(checkData); } try { using (soccerContext context = new soccerContext()) { var country = context.Countries.FirstOrDefault(c => c.Name == countryName); Town town = new Town { ui = Guid.NewGuid(), Country_ui = country.ui, Name = townName }; context.Towns.Add(town); context.SaveChanges(); return($"Town: {town.Name} is add to data!"); } } catch (Exception) { return($"There is problem to add Town {townName} "); } }
public static string Country(string countryName) { checkData = CheckDataIsNotEmpty(countryName, "Country"); if (checkData != "Ok") { return(checkData); } try { using (soccerContext context = new soccerContext()) { Country country = new Country { ui = Guid.NewGuid(), Name = countryName, }; context.Countries.Add(country); context.SaveChanges(); return($"Country: {country.Name} is add to data!"); } } catch (Exception) { return($"There is problem to add Competition {countryName} "); } }
public void Execute() { Game game = new Game { ui = Guid.NewGuid() }; using (soccerContext context = new soccerContext()) { Guid competitionGuid = new Guid(this.competition); Guid homeTeamGuid = new Guid(this.homeTeam); Guid awayTeamGuid = new Guid(this.awayTeam); Competition competitionData = context.Competitions.FirstOrDefault(c => c.ui == competitionGuid); Team teamHomeData = context.Teams.FirstOrDefault(t => t.ui == homeTeamGuid); Team teamAwayData = context.Teams.FirstOrDefault(t => t.ui == awayTeamGuid); game.Competition_ui = competitionData.ui; game.HomeTeam_ui = teamHomeData.ui; game.AwayTeam_ui = teamAwayData.ui; game.HomeTeamGoals = homeTeamGoals; game.AwayTeamGoals = awayTeamGoals; game.Date = dateOfGame.Date; try { context.Games.Add(game); context.SaveChanges(); } catch (Exception) { throw new ArgumentException("There is problem with Games Import!"); } } }
public void Execute() { int number = (int)((EnumColor)Enum.Parse(typeof(EnumColor), this.colourName)); Colour colour = new Colour { Name = number }; Guid guid = Guid.NewGuid(); colour.ui = guid; try { using (soccerContext context = new soccerContext()) { context.Colours.Add(colour); context.SaveChanges(); } } catch (Exception) { throw new ArgumentException("There is such colour in data"); } }
public void Execute() { Town town = new Town { Name = name, ui = Guid.NewGuid() }; soccerContext context = new soccerContext(); try { Country country = context.Countries.FirstOrDefault(c => c.Name == countryName); country.Towns.Add(town);//Add town to this country town.Country_ui = country.ui; context.SaveChanges(); } catch (Exception) { throw new System.InvalidOperationException("There is such town in data"); } }
public void Execute() { Competition competition = new Competition { ui = Guid.NewGuid(), Name = competitionName }; try { using (soccerContext context = new soccerContext()) { context.Competitions.Add(competition); context.SaveChanges(); } //Working! } catch (Exception) { throw new ArgumentException("There is such Competition name!"); } }
public void Execute() { Team team = new Team { Name = teamName, ui = Guid.NewGuid() }; using (soccerContext context = new soccerContext()) { Competition competition = context.Competitions.FirstOrDefault(c => c.Name == competitionName); //competition.Teams.Add(team); Town town = context.Towns.FirstOrDefault(t => t.Name == townName); //town.Teams.Add(team); team.Competition_ui = competition.ui; team.Town_ui = town.ui; int idFirst = int.Parse(primaryColour); int idSecond = int.Parse(secondaryColour); Colour colourOne = context.Colours.FirstOrDefault(c => c.Name == idFirst); Colour colourTwo = context.Colours.FirstOrDefault(c => c.Name == idSecond); team.Colour = colourOne; team.Colour1 = colourTwo; try { context.Teams.Add(team); context.SaveChanges(); } catch (Exception) { throw new ArgumentException("There is such team in data"); } } }