Exemple #1
0
        public IHttpActionResult GetAllCategoria()
        {
            var categorias = new CategoriaModel().GetAll().ToList();

            if (categorias != null)
            {
                categorias.ForEach(x =>
                {
                    x.Productos = ProductoModel.Instance._repository.FindBy(y => y.Categoria_Id == x.Id).ToList();
                    if (x.Productos != null)
                    {
                        x.Productos.ToList().ForEach(y =>
                        {
                            y.ProductoDescuentos = ProductoDescuentoModel.Instance._repository.FindBy(z => z.Producto_Id == y.Id).ToList();

                            if (y.ProductoDescuentos != null)
                            {
                                y.ProductoDescuentos.ToList().ForEach(r =>
                                {
                                    r.Descuento = DescuentoModel.Instance._repository.FindBy(t => t.Id == r.Descuento_Id).FirstOrDefault();
                                    if (r.Descuento != null)
                                    {
                                        y.Descuento += r.Descuento.Descu;
                                    }
                                });
                            }
                        });
                    }
                });
            }
            return(Json(categorias));
        }
Exemple #2
0
        public IHttpActionResult GetCategoria(int id)
        {
            List <Categoria> c = new CategoriaModel()._repository.FindBy(x => x.Id == 1).ToList();

            c.ForEach(x =>
            {
                x.Productos = new ProductoModel()._repository.FindBy(y => y.Categoria_Id == x.Id).ToList();
            });
            return(Json(c));

            /*
             * var categoria = new CategoriaModel
             * {
             *  Categoria = new CategoriaModel()._repository.FindBy(x=>x.Id == 1)
             * };
             * if (categoria.Categoria != null)
             * {
             *  categoria.Categoria.Productos = new ProductoModel()._repository.FindBy(x => x.Categoria_Id == id).ToList();
             *
             *  if (categoria.Categoria.Productos != null)
             *  {
             *      categoria.Categoria.Productos.ToList().ForEach(x =>
             *      {
             *          x.ProductoDescuentos = new ProductoDescuentoModel()._repository.FindBy(y => y.Producto_Id == x.Id).ToList();
             *          if (x.ProductoDescuentos != null)
             *          {
             *              x.ProductoDescuentos.ToList().ForEach(y =>
             *              {
             *                  y.Descuento = DescuentoModel.Instance._repository.FindBy(t => t.Id == y.Descuento_Id).FirstOrDefault();
             *                  if (y.Descuento != null)
             *                  {
             *                      x.Descuento += y.Descuento.Descu;
             *                  }
             *              });
             *          }
             *      });
             *  }
             *
             * }
             * return Json(categoria);
             */
        }