public TeamRace Delete(TeamRace teamRace) { var result = _context.Remove(teamRace); _context.SaveChanges(); return(result.Entity); }
public TeamRace Create(TeamRace teamRace) { var result = _context.Add <TeamRace>(teamRace); _context.SaveChanges(); return(result.Entity); }
public TeamRace Post(TeamRaceDTO value) { TeamRace model = new TeamRace() { RaceId = value.Id_race, TeamId = value.Id_team }; return(ITeamRaceRepository.Create(model)); }
public void Post(TeamDTO value) { Team model = new Team() { Team_name = value.Team_name, RealeaseYear = value.RealeaseYear, Image = value.Image }; ITeamRepository.Create(model); if (value.Employees != null) { foreach (EmployeeDTO employee in value.Employees) { Employee newEmployee = new Employee() { TeamId = model.Id, First_name = employee.First_name, Second_name = employee.Second_name, Function = employee.Function, Age = employee.Age }; IEmployeeRepository.Create(newEmployee); } } if (value.ComponentsId != null) { for (int i = 0; i < value.ComponentsId.Count; i++) { TeamComponent newTeamComponent = new TeamComponent() { ComponentId = value.ComponentsId[i], TeamId = model.Id }; ITeamComponentRepository.Create(newTeamComponent); } } if (value.RacesId != null) { for (int i = 0; i < value.RacesId.Count; i++) { TeamRace newTeamRace = new TeamRace() { TeamId = model.Id, RaceId = value.RacesId[i] }; ITeamRaceRepository.Create(newTeamRace); } } }
public TeamRace Put(int id, TeamRaceDTO value) { TeamRace model = ITeamRaceRepository.Get(id); if (value.Id_race != 0) { model.RaceId = value.Id_race; } if (value.Id_team != 0) { model.TeamId = value.Id_team; } return(ITeamRaceRepository.Update(model)); }
public Race Put(int id, RaceDTO value) { Race model = IRaceRepository.Get(id); if (value.Duration > 0) { model.Duration = value.Duration; } if (value.Location != null) { model.Location = value.Location; } if (value.NumberOfSpectators > 0) { model.NumberOfSpectators = value.NumberOfSpectators; } if (value.Image != null) { model.Image = value.Image; } if (value.IdTeams != null) { IEnumerable <TeamRace> teamRaces = ITeamRaceRepository.GetAll().Where(x => x.RaceId == id); foreach (TeamRace teamRace in teamRaces) { ITeamRaceRepository.Delete(teamRace); } for (int i = 0; i < value.IdTeams.Count; i++) { TeamRace teamRace = new TeamRace() { TeamId = value.IdTeams[i], RaceId = model.Id }; ITeamRaceRepository.Create(teamRace); } } return(IRaceRepository.Update(model)); }
public void Post(RaceDTO value) { Race model = new Race() { Location = value.Location, Duration = value.Duration, NumberOfSpectators = value.NumberOfSpectators, Image = value.Image }; IRaceRepository.Create(model); for (int i = 0; i < value.IdTeams.Count; i++) { TeamRace teamRace = new TeamRace() { TeamId = value.IdTeams[i], RaceId = model.Id }; ITeamRaceRepository.Create(teamRace); } }
public Team Put(int id, TeamDTO value) { Team model = ITeamRepository.Get(id); if (value.RealeaseYear != 0) { model.RealeaseYear = value.RealeaseYear; } if (value.Team_name != null) { model.Team_name = value.Team_name; } if (value.Image != null) { model.Image = value.Image; } if (value.ComponentsId != null) { IEnumerable <TeamComponent> teamComponents = ITeamComponentRepository.GetAll().Where(x => x.TeamId == id); foreach (TeamComponent teamComponent in teamComponents) { ITeamComponentRepository.Delete(teamComponent); } for (int i = 0; i < value.ComponentsId.Count; i++) { TeamComponent newTeamComponent = new TeamComponent() { ComponentId = value.ComponentsId[i], TeamId = model.Id }; ITeamComponentRepository.Create(newTeamComponent); } } if (value.Employees != null) { IEnumerable <Employee> employees = IEmployeeRepository.GetAll().Where(x => x.TeamId == id); foreach (Employee employee in employees) { IEmployeeRepository.Delete(employee); } foreach (EmployeeDTO employee in value.Employees) { Employee newEmployee = new Employee() { TeamId = model.Id, First_name = employee.First_name, Second_name = employee.Second_name, Function = employee.Function, Age = employee.Age }; IEmployeeRepository.Create(newEmployee); } } if (value.RacesId != null) { IEnumerable <TeamRace> teamRaces = ITeamRaceRepository.GetAll().Where(x => x.TeamId == id); foreach (TeamRace teamRace in teamRaces) { ITeamRaceRepository.Delete(teamRace); } for (int i = 0; i < value.RacesId.Count; i++) { TeamRace newTeamRace = new TeamRace() { TeamId = model.Id, RaceId = value.RacesId[i] }; ITeamRaceRepository.Create(newTeamRace); } } return(ITeamRepository.Update(model)); }
public TeamRace Delete(int id) { TeamRace model = ITeamRaceRepository.Get(id); return(ITeamRaceRepository.Delete(model)); }
public TeamRace Update(TeamRace teamRace) { _context.Entry(teamRace).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.SaveChanges(); return(teamRace); }