コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="_competition"></param>
        /// <returns></returns>
        public int SaveUniqueEntireCompetition(ICompetitionModel _competition, IPlayer playerLogic, ITeam teamLogic, IArea areaLogic)
        {
            try
            {
                if (_repositorio != null)
                {
                    if (_competition.Id != 0 && _repositorio.TraerUnoPorId(_competition.Id) == null)
                    {
                        //GUardamos el area de la competition

                        if (areaLogic.TraerUnoPorId(_competition.AreaId.Value) == null)
                        {
                            areaLogic.Adicionar(_competition.Area);
                        }

                        if (_repositorio.TraerUnoPorId(_competition.Id) == null)
                        {
                            _repositorio.Adicionar(_competition);
                        }
                        else
                        {
                            _repositorio.Modificar(_competition);
                        }

                        #region Team/Squad

                        foreach (TeamModel _team in _competition.Teams)
                        {
                            //Guardamos el Entity Model

                            if (teamLogic.TraerUnoPorId(_team.Id) == null)
                            {
                                teamLogic.Adicionar(_team);
                            }
                            else
                            {
                                teamLogic.Modificar(_team);
                            }

                            if (areaLogic.TraerUnoPorId(_team.AreaId.Value) == null)
                            {
                                areaLogic.Adicionar(_team.Area);
                            }
                            else
                            {
                                areaLogic.Modificar(_team.Area);
                            }
                            playerLogic.SavePlayerList(_team.Squad);
                        }

                        #endregion Team/Squad
                        return(1);
                    }
                    else
                    {
                        return(-1);
                    }
                }
                return(0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }