public bool InsertOrUpdateTimeGoals(ObservableCollection <TimeGoalsModel> dados) { if (dados == null || dados != null ? dados.Count() < 1 : true) { return(false); } try { using (var db = new SpeedOddsContext()) { foreach (var item in dados) { if (item.TimeGoalsId.HasValue) { //Update var timeGoal = db.TimeGoals.Where(t => t.TimeGoalsId == item.TimeGoalsId).FirstOrDefault(); if (timeGoal != null) { timeGoal.Goal15 = item.Goal15; timeGoal.Goal30 = item.Goal30; timeGoal.Goal45 = item.Goal45; timeGoal.Goal60 = item.Goal60; timeGoal.Goal75 = item.Goal75; timeGoal.Goal90 = item.Goal90; db.SaveChanges(); } } else { //Create TimeGoal timeGoal = new TimeGoal() { CompetitionId = item.CompetitionId.Value, TeamId = item.TeamId.Value, Goal15 = item.Goal15, Goal30 = item.Goal30, Goal45 = item.Goal45, Goal60 = item.Goal60, Goal75 = item.Goal75, Goal90 = item.Goal90 }; db.TimeGoals.Add(timeGoal); db.SaveChanges(); } } } return(true); } catch (Exception ex) { Console.WriteLine("Error saving TimeGoals in BD -> " + ex.ToString()); Console.WriteLine(ex.Message); return(false); } }
public bool ChangeFavoriteValue(int teamId, bool newVal) { try { using (var db = new SpeedOddsContext()) { var team = db.Teams.Where(x => x.TeamId == teamId).FirstOrDefault(); if (team != null) { team.IsFavorite = newVal; db.SaveChanges(); return(true); } return(false); } } catch (Exception ex) { Console.WriteLine("Error changing favorite team from BD -> " + ex.ToString()); Console.WriteLine(ex.Message); return(false); } }
public bool CreateTeam(string name, int competitionId, bool isFavorite) { try { using (var db = new SpeedOddsContext()) { Team team = new Team() { Name = name.Trim(), CompetitionId = competitionId, IsFavorite = isFavorite, CreateDate = DateTime.Now }; db.Teams.Add(team); db.SaveChanges(); return(true); } } catch (Exception ex) { Console.WriteLine("Error creating new team -> " + ex.ToString()); Console.WriteLine(ex.Message); return(false); } }
public bool RemoveTeam(int teamId) { try { using (var db = new SpeedOddsContext()) { var team = db.Teams.Where(x => x.TeamId == teamId).FirstOrDefault(); if (team != null) { db.Teams.Remove(team); db.SaveChanges(); return(true); } return(false); } } catch (Exception ex) { Console.WriteLine("Error removing team from BD -> " + ex.ToString()); Console.WriteLine(ex.Message); return(false); } }
public bool CreateCompetition(string name, int seasonId) { try { using (var db = new SpeedOddsContext()) { Competition comp = new Competition() { Name = name.Trim(), SeasonId = seasonId, CreateDate = DateTime.Now }; db.Competitions.Add(comp); db.SaveChanges(); return(true); } } catch (Exception ex) { Console.WriteLine("Error creating new competition -> " + ex.ToString()); Console.WriteLine(ex.Message); return(false); } }
public bool RemoveCompetition(int competitionId) { try { using (var db = new SpeedOddsContext()) { var comp = db.Competitions.Where(x => x.CompetitionId == competitionId).FirstOrDefault(); if (comp != null) { db.Competitions.Remove(comp); db.SaveChanges(); return(true); } return(false); } } catch (Exception ex) { Console.WriteLine("Error removing competition from BD -> " + ex.ToString()); Console.WriteLine(ex.Message); return(false); } }
public bool CreateSeason(int sy, int ey) { try { using (var db = new SpeedOddsContext()) { Season season = new Season() { Name = "Época " + sy.ToString() + "/ " + ey.ToString(), StartYear = sy, EndYear = ey, CreateDate = DateTime.Now }; db.Seasons.Add(season); db.SaveChanges(); return(true); } } catch (Exception ex) { Console.WriteLine("Error creating new season -> " + ex.ToString()); Console.WriteLine(ex.Message); return(false); } }