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));
        }
Пример #2
0
 public ActionResult <IEnumerable <TeamComponent> > Get()
 {
     return(ITeamComponentRepository.GetAll());
 }