示例#1
0
        static public List <PrecioProducto> ListaPrecioProducto()
        {
            SqlConnection         con = new SqlConnection();
            SqlCommand            com = new SqlCommand();
            SqlDataReader         dr;
            List <PrecioProducto> l = new List <PrecioProducto>();

            con.ConnectionString = "Server=DESKTOP-O06HVPI;Database=nota03;Integrated Security=SSPI";
            com.Connection       = con;
            com.CommandType      = CommandType.Text;
            com.CommandText      = "SELECT Precio_Id, Precio_Lista, Precio_Producto, Precio_Monto FROM dbo.PrecioProducto";
            con.Open();
            dr = com.ExecuteReader();

            while (dr.Read())
            {
                PrecioProducto p = new PrecioProducto();
                p.id       = dr.GetInt32(0);
                p.lista    = dr.GetInt32(1);
                p.producto = dr.GetInt32(2);
                p.monto    = dr.GetInt32(3);
                l.Add(p);
            }

            return(l);
        }
示例#2
0
        public PrecioProducto createPrecioProducto(PrecioProductoDto precio)
        {
            var entity = new PrecioProducto()
            {
                Precioreal  = precio.Precioreal,
                Precioventa = precio.Precioventa,
                Fecha       = DateTime.Now
            };

            repository.Agregar <PrecioProducto>(entity);
            return(entity);
        }
 // DELETE api/values/5
 public HttpResponseMessage Delete(string idCod, [FromBody] PrecioProducto precioProducto)
 {
     if (precioProducto.eliminarPrecioProducto(idCod))
     {
         var message = string.Format("Se eliminó el precio del producto");
         return(Request.CreateResponse(HttpStatusCode.OK, message));
     }
     else
     {
         var message = string.Format("No se eliminó el precio del producto, verifique los datos.");
         return(Request.CreateResponse(HttpStatusCode.NotAcceptable, message));
     }
 }
 // PUT api/values/5
 public HttpResponseMessage Put(string id, [FromBody] PrecioProducto precio_Producto)
 {
     if (precio_Producto.modificarPrecioProducto("Actualizar"))
     {
         var message = string.Format("Se actualizó el precio del producto");
         return(Request.CreateResponse(HttpStatusCode.OK, message));
     }
     else
     {
         var message = string.Format("No se actualizó precio del producto, verifique los datos.");
         return(Request.CreateResponse(HttpStatusCode.NotAcceptable, message));
     }
 }
 // POST api/values
 public HttpResponseMessage Post([FromBody] PrecioProducto precioProducto)
 {
     if (precioProducto.agregarPrecioProducto("Insertar"))
     {
         var message = string.Format("Se guardó el precio en el producto");
         return(Request.CreateResponse(HttpStatusCode.OK, message));
     }
     else
     {
         var message = string.Format("No se guardó el precio en el producto, verifique los datos.");
         return(Request.CreateResponse(HttpStatusCode.NotAcceptable, message));
     }
 }
示例#6
0
        public async Task <Producto> InsertarProductoPanel(InsertoProductoPanelDto producto)
        {
            var            db     = new QueryFactory(connection, compiler);
            ImagenProducto imagen = new ImagenProducto()
            {
                Nombre = producto.imagen
            };
            PrecioProducto precio = new PrecioProducto()
            {
                Precioreal  = producto.precioreal,
                Precioventa = producto.precioventa,
                Fecha       = DateTime.Now
            };
            Marca marca = new Marca()
            {
                Nombre = producto.marca
            };

            repository.Agregar <ImagenProducto>(imagen);
            repository.Agregar <PrecioProducto>(precio);
            repository.Agregar <Marca>(marca);

            var categoriaID = db.Query("categorias").
                              Select("Id").
                              Where("Descripcion", "=", producto.categoria).FirstOrDefault <int>();

            var imagenID = db.Query("imagenproducto").
                           Select("Id").
                           Where("nombre", "=", producto.imagen).FirstOrDefault <int>();

            var precioID = db.Query("precioproducto").
                           Select("Id").
                           Where("PrecioVenta", "=", producto.precioventa)
                           .Where("PrecioReal", "=", producto.precioreal).
                           FirstOrDefault <int>();

            var marcaID = db.Query("marca").
                          Select("Id").
                          Where("Nombre", "=", producto.marca).
                          FirstOrDefault <int>();


            Producto objeto = new Producto()
            {
                Nombre      = producto.nombre,
                Descripcion = producto.descripcion,
                ImagenID    = imagenID,
                PrecioID    = precioID,
                CategoriaID = categoriaID,
                MarcaID     = marcaID,
                Stock       = producto.stock
            };

            repository.Agregarr <Producto>(objeto);

            var ProductoID = db.Query("productos").
                             Select("Id").
                             Where("Nombre", "=", objeto.Nombre).
                             Where("CategoriaID", "=", objeto.CategoriaID).
                             Where("PrecioID", "=", objeto.PrecioID).
                             Where("MarcaID", "=", objeto.MarcaID).
                             Where("Stock", "=", objeto.Stock).
                             Where("Descripcion", "=", objeto.Descripcion).
                             FirstOrDefault <int>();

            InsertarPublicacionDto avg = new InsertarPublicacionDto()
            {
                productoID = ProductoID
            };



            string url = "https://localhost:44398/api/Publicacion/InsertarPublicacion";

            using (var httpClient = new HttpClient())
            {
                var json = Newtonsoft.Json.JsonConvert.SerializeObject(avg, Formatting.None);
                var data = new System.Net.Http.StringContent(json, Encoding.UTF8, "application/json");

                var result = await httpClient.PostAsync(url, data);

                string resultado = result.Content.ReadAsStringAsync().Result;
                //posts = JsonConvert.DeserializeObject<List<ProductoEspecificoDto>>(resultado);
            }


            return(objeto);
        }