示例#1
0
        public async Task <CategoriasRepresentantes> ModificarCategoriaRepresentante(CategoriasRepresentantes categoriaReprensentateParaModificar)
        {
            CategoriasRepresentantes categoriaRepresentanteExistente = await _context.CategoriasRepresentantes.Where(x => x.Consecutivo == categoriaReprensentateParaModificar.Consecutivo).FirstOrDefaultAsync();

            categoriaRepresentanteExistente.CodigoCategoria = categoriaReprensentateParaModificar.CodigoCategoria;

            return(categoriaRepresentanteExistente);
        }
示例#2
0
        public async Task <IHttpActionResult> EliminarCategoriaRepresentante(CategoriasRepresentantes categoriaRepresanteParaBorrar)
        {
            if (categoriaRepresanteParaBorrar == null || categoriaRepresanteParaBorrar.Consecutivo <= 0)
            {
                return(BadRequest("categoriaRepresanteParaBorrar vacio y/o invalido!."));
            }

            try
            {
                WrapperSimpleTypesDTO wrapperEliminarCategoriaRepresentante = await _categoriasBusiness.EliminarCategoriaRepresentante(categoriaRepresanteParaBorrar);

                return(Ok(wrapperEliminarCategoriaRepresentante));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
示例#3
0
        public async Task <IHttpActionResult> ListarCategoriasDeUnRepresentante(CategoriasRepresentantes categoriaRepresentanteParaListar)
        {
            if (categoriaRepresentanteParaListar == null || categoriaRepresentanteParaListar.CodigoRepresentante <= 0 || categoriaRepresentanteParaListar.IdiomaBase == Idioma.SinIdioma)
            {
                return(BadRequest("categoriaRepresentanteAListar vacio y/o invalido!."));
            }

            try
            {
                List <CategoriasRepresentantesDTO> listaCategoriasRepresentantes = await _categoriasBusiness.ListarCategoriasDeUnRepresentantePorIdioma(categoriaRepresentanteParaListar);

                return(Ok(listaCategoriasRepresentantes));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
示例#4
0
        public async Task <IHttpActionResult> CrearCategoriaRepresentante(CategoriasRepresentantes categoriaRepresentanteParaCrear)
        {
            if (categoriaRepresentanteParaCrear == null || categoriaRepresentanteParaCrear.CodigoCategoria > 0 || categoriaRepresentanteParaCrear.CodigoRepresentante > 0)
            {
                return(BadRequest("categoriaRepresentanteParaCrear vacio y/o invalido!."));
            }

            try
            {
                WrapperSimpleTypesDTO wrapperCrearCategoriaRepresentante = await _categoriasBusiness.CrearCategoriaRepresentante(categoriaRepresentanteParaCrear);

                return(Ok(wrapperCrearCategoriaRepresentante));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public async Task <WrapperSimpleTypesDTO> ModificarCategoriaRepresentante(CategoriasRepresentantes categoriaReprensentateParaModificar)
        {
            using (SportsGoEntities context = new SportsGoEntities(false))
            {
                CategoriasRepository     categoriasRepo = new CategoriasRepository(context);
                CategoriasRepresentantes categoriaRepresentanteExistente = await categoriasRepo.ModificarCategoriaRepresentante(categoriaReprensentateParaModificar);

                WrapperSimpleTypesDTO wrapperModificarCategoriaRepresentante = new WrapperSimpleTypesDTO();

                wrapperModificarCategoriaRepresentante.NumeroRegistrosAfectados = await context.SaveChangesAsync();

                if (wrapperModificarCategoriaRepresentante.NumeroRegistrosAfectados > 0)
                {
                    wrapperModificarCategoriaRepresentante.Exitoso = true;
                }

                return(wrapperModificarCategoriaRepresentante);
            }
        }
        public async Task <WrapperSimpleTypesDTO> EliminarCategoriaRepresentante(CategoriasRepresentantes categoriaRepresanteParaBorrar)
        {
            using (SportsGoEntities context = new SportsGoEntities(false))
            {
                CategoriasRepository categoriasRepo = new CategoriasRepository(context);
                int?codigoRepresentante             = await categoriasRepo.BuscarCodigoCandidatoDeUnaCategoriaRepresentante(categoriaRepresanteParaBorrar.Consecutivo);

                if (!codigoRepresentante.HasValue)
                {
                    throw new InvalidOperationException("No se pudo hallar el codigo del representante para borrar la categoria y modificar el plan!.");
                }

                categoriasRepo.EliminarCategoriaRepresentante(categoriaRepresanteParaBorrar);

                PlanesRepository planRepo = new PlanesRepository(context);
                int?codigoPlanExistente   = await planRepo.BuscarCodigoPlanUsuarioPorCodigoRepresentante(codigoRepresentante.Value);

                if (!codigoPlanExistente.HasValue)
                {
                    throw new InvalidOperationException("No se pudo hallar el plan del representante para crear la categoria para el!.");
                }

                // Se "BAJA" el contador de categorias 1
                PlanesUsuarios planUsuarioExistente = await planRepo.ModificarNumeroCategoriasUsadas(codigoPlanExistente.Value, -1);

                WrapperSimpleTypesDTO wrapperEliminarCategoriaRepresentante = new WrapperSimpleTypesDTO();

                wrapperEliminarCategoriaRepresentante.NumeroRegistrosAfectados = await context.SaveChangesAsync();

                if (wrapperEliminarCategoriaRepresentante.NumeroRegistrosAfectados > 0)
                {
                    wrapperEliminarCategoriaRepresentante.Exitoso = true;
                }

                return(wrapperEliminarCategoriaRepresentante);
            }
        }
        public async Task <List <CategoriasRepresentantesDTO> > ListarCategoriasDeUnRepresentantePorIdioma(CategoriasRepresentantes categoriaRepresentanteParaListar)
        {
            using (SportsGoEntities context = new SportsGoEntities(false))
            {
                CategoriasRepository categoriasRepo = new CategoriasRepository(context);
                List <CategoriasRepresentantesDTO> listaCategoriasRepresentantes = await categoriasRepo.ListarCategoriasDeUnRepresentantePorIdioma(categoriaRepresentanteParaListar);

                return(listaCategoriasRepresentantes);
            }
        }
        public async Task <CategoriasRepresentantesDTO> BuscarCategoriaRepresentantePorConsecutivoAndIdioma(CategoriasRepresentantes categoriaRepresentantesParaBuscar)
        {
            using (SportsGoEntities context = new SportsGoEntities(false))
            {
                CategoriasRepository        categoriasRepo = new CategoriasRepository(context);
                CategoriasRepresentantesDTO categoriaRepresentanteBuscada = await categoriasRepo.BuscarCategoriaRepresentantePorConsecutivoAndIdioma(categoriaRepresentantesParaBuscar);

                return(categoriaRepresentanteBuscada);
            }
        }
示例#9
0
        public async Task <IHttpActionResult> BuscarCategoriaRepresentantePorConsecutivoAndIdioma(CategoriasRepresentantes categoriaRepresentantesParaBuscar)
        {
            if (categoriaRepresentantesParaBuscar == null || categoriaRepresentantesParaBuscar.Consecutivo <= 0 || categoriaRepresentantesParaBuscar.IdiomaBase == Idioma.SinIdioma)
            {
                return(BadRequest("categoriaRepresentantesParaBuscar vacio y/o invalido!."));
            }

            try
            {
                CategoriasRepresentantesDTO categoriaEventoBuscada = await _categoriasBusiness.BuscarCategoriaRepresentantePorConsecutivoAndIdioma(categoriaRepresentantesParaBuscar);

                return(Ok(categoriaEventoBuscada));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
示例#10
0
 public void EliminarCategoriaRepresentante(CategoriasRepresentantes categoriaRepresanteParaBorrar)
 {
     _context.CategoriasRepresentantes.Attach(categoriaRepresanteParaBorrar);
     _context.CategoriasRepresentantes.Remove(categoriaRepresanteParaBorrar);
 }
示例#11
0
        public async Task <List <CategoriasRepresentantesDTO> > ListarCategoriasDeUnRepresentantePorIdioma(CategoriasRepresentantes categoriaRepresentanteParaListar)
        {
            IQueryable <CategoriasRepresentantes> queryRepresentantes = _context.CategoriasRepresentantes.Where(x => x.CodigoRepresentante == categoriaRepresentanteParaListar.CodigoRepresentante).AsQueryable();

            List <CategoriasRepresentantesDTO> listaCategoriasRepresentantes = await queryRepresentantes
                                                                               .Select(x => new CategoriasRepresentantesDTO
            {
                Consecutivo         = x.Consecutivo,
                CodigoCategoria     = x.CodigoCategoria,
                CodigoRepresentante = x.CodigoRepresentante,
                Categorias          = new CategoriasDTO
                {
                    Consecutivo              = x.Categorias.Consecutivo,
                    CodigoArchivo            = x.Categorias.CodigoArchivo,
                    DescripcionIdiomaBuscado = x.Categorias.CategoriasContenidos.Where(y => y.CodigoIdioma == categoriaRepresentanteParaListar.CodigoIdiomaUsuarioBase).Select(y => y.Descripcion).FirstOrDefault(),
                    CategoriasContenidos     = x.Categorias.CategoriasContenidos.Where(y => y.CodigoIdioma == categoriaRepresentanteParaListar.CodigoIdiomaUsuarioBase)
                                               .Select(z => new CategoriasContenidosDTO
                    {
                        Consecutivo  = z.Consecutivo,
                        Descripcion  = z.Descripcion,
                        CodigoIdioma = z.CodigoIdioma
                    }).ToList()
                }
            })
                                                                               .AsNoTracking()
                                                                               .ToListAsync();

            return(listaCategoriasRepresentantes);
        }
示例#12
0
 public void CrearCategoriaRepresentante(CategoriasRepresentantes categoriaRepresentanteParaCrear)
 {
     _context.CategoriasRepresentantes.Add(categoriaRepresentanteParaCrear);
 }