Beispiel #1
0
        public IHttpActionResult update([FromBody] ReglaTorneo regla)
        {
            reglas_torneo reglaDto = new reglas_torneo();

            try
            {
                reglaDto.id_regla    = (int)regla.id_regla;
                reglaDto.descripcion = regla.descripcion;
                reglaDto.id_torneo   = (int)regla.torneo.id_torneo;

                reglas_torneo reglas = db.reglas_torneo.Where(x => x.id_regla == regla.id_regla).FirstOrDefault();

                if (reglas != null)
                {
                    reglas.id_regla    = reglaDto.id_regla;
                    reglas.descripcion = reglaDto.descripcion;
                    reglas.id_torneo   = reglaDto.id_torneo;
                    db.SaveChanges();
                    return(Ok());
                }
                return(BadRequest());
            }
            catch (Exception e)
            {
                return(BadRequest(e.ToString()));
            }
        }
        public IHttpActionResult update([FromBody] Torneo torneo)
        {
            torneos       torneoDto   = new torneos();
            modalidades   modalidad   = new modalidades();
            reglas_torneo regla       = new reglas_torneo();
            categorias    categoria   = new categorias();
            tipos_torneos tipoTorneo  = new tipos_torneos();
            Boolean       transaccion = false;

            try
            {
                torneoDto.nombre       = torneo.nombre;
                torneoDto.id_torneo    = (int)torneo.id_torneo;
                torneoDto.descripcion  = torneo.descripcion;
                torneoDto.fecha_inicio = torneo.fecha_inicio;
                torneoDto.fecha_fin    = torneo.fecha_fin;
                torneoDto.id_modalidad = torneo.modalidad.id_modalidad;
                torneoDto.id_categoria = torneo.categoria.id_categoria;
                torneoDto.id_tipo      = torneo.tipoTorneo.id_tipo;
                torneoDto.id_regla     = torneo.regla.id_regla;

                var result = db.torneos.SingleOrDefault(b => b.id_torneo == torneoDto.id_torneo);
                if (result != null)
                {
                    result.nombre       = torneoDto.nombre;
                    result.id_torneo    = torneoDto.id_torneo;
                    result.descripcion  = torneoDto.descripcion;
                    result.fecha_inicio = torneoDto.fecha_inicio;
                    result.fecha_fin    = torneoDto.fecha_fin;
                    result.id_modalidad = torneoDto.id_modalidad;
                    result.id_categoria = torneoDto.id_categoria;
                    result.id_tipo      = torneoDto.id_tipo;
                    result.id_regla     = torneoDto.id_regla;
                    db.SaveChanges();
                    transaccion = true;
                }
                int id_torneo = torneoDto.id_torneo;
                foreach (Equipo e in torneo.lsEquipos)
                {
                    if (transaccion)
                    {
                        equipos equipoToUpdate = db.equipos.Where(x => x.id_equipo == e.id_equipo).FirstOrDefault();
                        equipoToUpdate.id_torneo = id_torneo;
                    }
                }

                db.SaveChanges();
                return(Ok());
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e.InnerException);
            }
        }
        public IHttpActionResult registrar([FromBody] Torneo torneo)
        {
            torneos       torneoDto   = new torneos();
            modalidades   modalidad   = new modalidades();
            reglas_torneo regla       = new reglas_torneo();
            categorias    categoria   = new categorias();
            tipos_torneos tipoTorneo  = new tipos_torneos();
            int           id_torneo   = 0;
            Boolean       transaccion = false;

            try
            {
                torneoDto.nombre       = torneo.nombre;
                torneoDto.descripcion  = torneo.descripcion;
                torneoDto.fecha_inicio = torneo.fecha_inicio;
                torneoDto.fecha_fin    = torneo.fecha_fin;
                torneoDto.id_modalidad = torneo.modalidad.id_modalidad;
                torneoDto.id_categoria = torneo.categoria.id_categoria;
                torneoDto.id_tipo      = torneo.tipoTorneo.id_tipo;
                torneoDto.id_regla     = torneo.regla.id_regla;

                torneos torneoCheck = db.torneos.Where(x => x.nombre.ToUpper().Equals(torneoDto.nombre.ToUpper())).FirstOrDefault();

                if (torneoCheck == null)
                {
                    db.torneos.Add(torneoDto);
                    db.SaveChanges();
                    id_torneo   = torneoDto.id_torneo;
                    transaccion = true;

                    categoria_equipos categoriaEquipo = new categoria_equipos();
                    categoriaEquipo.id          = id_torneo;
                    categoriaEquipo.descripcion = torneo.nombre;
                    db.categoria_equipos.Add(categoriaEquipo);
                }
                foreach (Equipo e in torneo.lsEquipos)
                {
                    if (transaccion)
                    {
                        equipos equipoToUpdate = db.equipos.Where(x => x.id_equipo == e.id_equipo).FirstOrDefault();
                        equipoToUpdate.id_torneo = id_torneo;
                    }
                }
                db.SaveChanges();
                return(Ok());
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e.InnerException);
            }
        }
Beispiel #4
0
        public IHttpActionResult registrar([FromBody] ReglaTorneo regla)
        {
            reglas_torneo reglaDto = new reglas_torneo();

            try
            {
                reglaDto.descripcion = regla.descripcion;
                reglaDto.id_torneo   = regla.torneo.id_torneo;

                db.reglas_torneo.Add(reglaDto);
                db.SaveChanges();
                return(Ok(true));
            }
            catch (Exception e)
            {
                return(BadRequest(e.ToString()));
            }
        }