// GET: api/Producto
        public IEnumerable <ProductoDto> Get([FromUri] FiltroProducto filtro)
        {
            using (var session = Database.SessionFactory.OpenSession())
            {
                var nombre      = filtro.Nombre ?? string.Empty;
                var descripcion = filtro.Descripcion ?? string.Empty;

                var productos = session
                                .CreateSQLQuery(
                    @"SELECT prod.IdProducto, prod.Nombre, prod.Descripcion, prod.Precio, prod.IdCategoria
                            FROM Producto prod 
                            WHERE prod.Nombre LIKE :nombre AND
                                  prod.Descripcion LIKE :descripcion AND
                                  (:idCategoria IS NULL OR prod.IdCategoria = :idCategoria)")
                                .AddEntity(typeof(Producto))
                                .SetParameter("nombre", "%" + nombre + "%")
                                .SetParameter("descripcion", "%" + descripcion + "%")
                                .SetParameter("idCategoria", filtro.IdCategoria)
                                .List <Producto>();

                return(productos.Select(producto => new ProductoDto
                {
                    Id = producto.Id,
                    Nombre = producto.Nombre,
                    Descripcion = producto.Descripcion,
                    CateagoriaId = producto.Categoria.Id,
                    CateagoriaNombre = producto.Categoria.Nombre
                }).ToList());
            }
        }
        public async Task <ActionResult <Response> > ListPublProducto(FiltroProducto filtroProducto)
        {
            Response response = new Response();
            object   rpta     = new object();

            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                filtroProducto = (FiltroProducto)BusinessLogic.Utilities.AuxiliarMethods.ValidateParameters(filtroProducto, filtroProducto.GetType());
                rpta           = await _muratserviceslogic.ListPublProducto(filtroProducto);

                if (rpta == null)
                {
                    return(NotFound());
                }
            }
            catch (Exception e)
            {
                response.Status  = Error500;
                response.Message = e.Message;
                return(Ok(response));
            }
            return(Ok(rpta));
        }
Example #3
0
        // GET: Articulo/Filtrar/5
        ////////////////

        public ActionResult Filtrar()
        {
            FiltroProducto res = new FiltroProducto();

            ViewData["controller"] = System.Web.HttpContext.Current.Session["controller"] as String;
            ViewData["action"]     = System.Web.HttpContext.Current.Session["action"] as String;
            ViewData["arg"]        = System.Web.HttpContext.Current.Session["arg"];
            //articuloAsembler.covert
            return(View(res));
        }
        // GET: api/Producto
        public IEnumerable <ProductoDto> Get([FromUri] FiltroProducto filtro)
        {
            using (var session = Database.SessionFactory.OpenSession())
            {
                var productos = session.Query <Producto>();

                // -- Opción 1

                if (!string.IsNullOrEmpty(filtro.Nombre))
                {
                    productos = productos.Where(prod => prod.Nombre.Contains(filtro.Nombre));
                }

                if (!string.IsNullOrEmpty(filtro.Descripcion))
                {
                    productos = productos.Where(prod => prod.Descripcion.Contains(filtro.Descripcion));
                }

                if (filtro.IdCategoria != null)
                {
                    productos = productos.Where(prod => prod.Categoria.Id == filtro.IdCategoria.Value);
                }

                // Opción 2

                //var productos = session.Query<Producto>()
                //    .Where(prod =>
                //        (string.IsNullOrEmpty(filtro.Nombre) || prod.Nombre.Contains(filtro.Nombre)) &&
                //        (string.IsNullOrEmpty(filtro.Descripcion) || prod.Descripcion.Contains(filtro.Descripcion)) &&
                //        (filtro.IdCategoria == null || prod.Categoria.Id == filtro.IdCategoria));

                // Opción 3

                //var productos = session.Query<Producto>()
                //    .Where(prod => string.IsNullOrEmpty(filtro.Nombre) || prod.Nombre.Contains(filtro.Nombre))
                //    .Where(prod => string.IsNullOrEmpty(filtro.Descripcion) || prod.Descripcion.Contains(filtro.Descripcion))
                //    .Where(prod => filtro.IdCategoria == null || prod.Categoria.Id == filtro.IdCategoria);

                return(productos.Select(producto => new ProductoDto
                {
                    Id = producto.Id,
                    Nombre = producto.Nombre,
                    Descripcion = producto.Descripcion,
                    CateagoriaId = producto.Categoria.Id,
                    CateagoriaNombre = producto.Categoria.Nombre
                }).ToList());
            }
        }
        public async Task <List <PublicadoProductoServ> > ListPublProducto(FiltroProducto filtroProducto)
        {
            var parameters = new DynamicParameters();

            parameters.Add("@TIPO", filtroProducto.Tipo);
            parameters.Add("@STAG", filtroProducto.STag);
            parameters.Add("@IDCATEGORIA", filtroProducto.IdCategoria);
            parameters.Add("@IDMARCA", filtroProducto.IdMarca);
            parameters.Add("@PRECIO_INI", filtroProducto.Precio_Ini);
            parameters.Add("@PRECIO_FIN", filtroProducto.Precio_Fin);

            using (var connection = new SqlConnection(_connectionString))
            {
                return((await connection.QueryAsync <PublicadoProductoServ>("[dbo].[SPE_LIST_PUB_PRODUCTO]", parameters, commandType: CommandType.StoredProcedure)).ToList());
            }
        }
Example #6
0
        public ActionResult Filtrar(FiltroProducto collection)
        {
            try
            {
                ProductoCEN        cen = new ProductoCEN();
                IList <ProductoEN> res = null, aux = null;
                // TODO: Add delete logic here
                res = cen.ReadAll(0, int.MaxValue);

                if (!(collection.Preciobol == false || collection.Preciomin <= 0 || collection.Preciomax <= 0 || collection.Preciomax <= collection.Preciomin))
                {
                    aux = cen.Filtroprecio(collection.Preciomin, collection.Preciomax);
                    res = res.Intersect(aux).ToList();
                }
                if (collection.Nombrebol == true && collection.Nombre != null)
                {
                    aux = cen.Filtronombre(collection.Nombre);
                    res = res.Intersect(aux).ToList();
                }
                if (collection.tallabol == true && collection.Talla != null)
                {
                    aux = cen.Filtrotalla(collection.Talla);
                    res = res.Intersect(aux).ToList();
                }

                if (collection.Valoracionbol == true && collection.Valoracion > 0 && collection.Valoracion < 6)
                {
                    aux = cen.Filtrovalor((SMPGenNHibernate.Enumerated.SMP.ValoracionEnum)collection.Valoracion);
                    res = res.Intersect(aux).ToList();
                }
                AssemblerProducto ass     = new AssemblerProducto();
                IList <Producto>  listart = ass.ConvertListENToModel(res);


                System.Web.HttpContext.Current.Session["resu"] = listart;

                return(RedirectToAction("Resultadobusqueda", "Producto", null));

                // return View("Resultadobusqueda", listart);
            }
            catch
            {
                return(View());
            }
        }
        internal static FiltroProducto ValidarFiltros(FiltroProducto filtroProducto)
        {
            filtroProducto.STag = filtroProducto.STag.Trim().ToUpper();
            if (!((filtroProducto.IdCategoria.Trim()).Length > 0))
            {
                filtroProducto.IdCategoria = "000";
            }

            if (!((filtroProducto.IdMarca.Trim()).Length > 0))
            {
                filtroProducto.IdMarca = "000";
            }

            if (filtroProducto.Precio_Fin == 0)
            {
                filtroProducto.Precio_Fin = 9999;
            }

            return(filtroProducto);
        }
Example #8
0
        public async Task <object> ListPublProducto(FiltroProducto filtroProducto)
        {
            Response response = new Response();

            try
            {
                var validado = AuxiliarMethods.ValidarFiltros(filtroProducto);

                List <PublicadoProductoServ> list = await _unitOfWork.Murat.ListPublProducto(validado);

                if (list.Count() > 0)
                {
                    string directory = _config.GetSection("AppSettings").GetSection("url_imagenes").Value;
                    foreach (var item in list)
                    {
                        if (item.SArchivo_Producto != "")
                        {
                            item.Url_Producto = AuxiliarMethods.GenerarURL(directory, "Producto", item.SArchivo_Producto);
                        }
                    }
                    response.Status  = Constant.Status;
                    response.Message = Constant.Ok;
                    response.Data    = list;
                }
                else
                {
                    response.Status  = Constant.Error400;
                    response.Message = Constant.Consult;
                }
            }
            catch (Exception e)
            {
                response.Status  = Constant.Error500;
                response.Message = e.Message;
            }
            return(response);
        }
            public List <Producto> BuscarTodos(FiltroProducto filtro)
            {
                List <Producto> listaProductos = new List <Producto>();

                using (SqlConnection conexion = GestionConexion.GetConexion())
                {
                    conexion.Open();
                    SqlCommand comando = new SqlCommand();
                    String     sql     = "select * from Productos";

                    bool compruebo = false;

                    if (filtro.Id != null)
                    {
                        sql += " where id = @Id";
                        comando.Parameters.AddWithValue("@Id", filtro.Id);
                        compruebo = true;
                    }
                    if (filtro.Nombre != null)
                    {
                        if (!compruebo)
                        {
                            sql      += " where nombre = @Nombre";
                            compruebo = true;
                        }
                        else
                        {
                            sql += " and nombre = @Nombre";
                        }
                        comando.Parameters.AddWithValue("@Nombre", filtro.Nombre);
                    }
                    if (filtro.Importe != 0.0)
                    {
                        if (!compruebo)
                        {
                            sql      += " where importe = @Importe";
                            compruebo = true;
                        }
                        else
                        {
                            sql += " and importe = @Importe";
                        }
                        comando.Parameters.AddWithValue("@Importe", filtro.Importe);
                    }
                    if (filtro.Categoria != null)
                    {
                        if (!compruebo)
                        {
                            sql      += " where categoria = @Categoria";
                            compruebo = true;
                        }
                        else
                        {
                            sql += " and categoria = @Categoria";
                        }
                        comando.Parameters.AddWithValue("@Categoria", filtro.Categoria);
                    }

                    comando.Connection  = conexion;
                    comando.CommandText = sql;

                    SqlDataReader lector = comando.ExecuteReader();
                    while (lector.Read())
                    {
                        listaProductos.Add(new Producto(
                                               lector["id"].ToString(),
                                               lector["nombre"].ToString(),
                                               Convert.ToDouble(lector["importe"]),
                                               lector["categoria"].ToString()));
                    }
                }
                return(listaProductos);
            }