Ejemplo n.º 1
0
        public JsonResult GetSubCategoria(int IdCategoria)
        {
            {
                ML.SubCategoria subCategoria = new ML.SubCategoria();
                subCategoria.Categoria             = new ML.Categoria();
                subCategoria.Categoria.IdCategoria = IdCategoria;

                var result = BL.SubCategoria.GetByIdCategoria(subCategoria);

                // ML.Result resultProductoss = BL.SubCategoria.GetAllEF();


                List <SelectListItem> opciones = new List <SelectListItem>();

                opciones.Add(new SelectListItem {
                    Text = "--Selecciona--", Value = "0"
                });

                if (result.Objects != null)
                {
                    /*ML.Producto producto = new ML.Producto();
                     * producto.SubCategoria = new ML.SubCategoria();
                     * producto.SubCategoria.SubCategorias = resultProductoss.Objects;*/

                    foreach (ML.SubCategoria SubCategorias in result.Objects)
                    {
                        opciones.Add(new SelectListItem {
                            Text = SubCategorias.Nombre.ToString(), Value = SubCategorias.IdSubcategoria.ToString()
                        });
                    }
                }

                return(Json(new SelectList(opciones, "Value", "Text", JsonRequestBehavior.AllowGet)));
            }
        }
Ejemplo n.º 2
0
        public static ML.Result GetByIdCategoria(ML.SubCategoria subCategoria)
        {
            ML.Result result = new ML.Result();

            try
            {
                using (DL_EF.EcommerceRubenEntities context = new DL_EF.EcommerceRubenEntities())
                {
                    //var IdResult = new ObjectParameter("IdSubCategoria", typeof(int));
                    var Query = context.SubCategoriaGetByIdCategoria(subCategoria.Categoria.IdCategoria);



                    result.Objects = new List <object>();

                    if (Query != null)
                    {
                        foreach (var obj in Query)
                        {
                            ML.SubCategoria alumno = new ML.SubCategoria();
                            alumno.IdSubcategoria        = obj.IdSubCategoria;
                            alumno.Nombre                = obj.Nombre;
                            alumno.Categoria             = new ML.Categoria();
                            alumno.Categoria.IdCategoria = obj.IdCategoria;

                            result.Objects.Add(alumno);
                        }

                        result.Correct = true;
                    }
                    else
                    {
                        result.Correct      = false;
                        result.ErrorMessage = "No se encontraron registros.";
                    }
                }
            }
            catch (Exception ex)
            {
                result.Correct      = false;
                result.ErrorMessage = ex.Message;
            }

            return(result);
        }
Ejemplo n.º 3
0
        public static ML.Result GetAllEF()
        {
            ML.Result result = new ML.Result();

            try
            {
                using (DL_EF.EcommerceRubenEntities context = new DL_EF.EcommerceRubenEntities())
                {
                    var query = context.SubCategoriaGetAll().ToList();

                    result.Objects = new List <object>();

                    if (query != null)
                    {
                        foreach (var obj in query)
                        {
                            ML.SubCategoria alumno = new ML.SubCategoria();
                            alumno.IdSubcategoria        = obj.IdSubCategoria;
                            alumno.Nombre                = obj.Nombre;
                            alumno.Categoria             = new ML.Categoria();
                            alumno.Categoria.IdCategoria = obj.IdCategoria;

                            result.Objects.Add(alumno);
                        }

                        result.Correct = true;
                    }
                    else
                    {
                        result.Correct      = false;
                        result.ErrorMessage = "No se encontraron registros.";
                    }
                }
            }
            catch (Exception ex)
            {
                result.Correct      = false;
                result.ErrorMessage = ex.Message;
            }

            return(result);
        }