Exemple #1
0
        public List <Producto_> BuscarProductoId(Stream JSONdataStream)
        {
            List <Producto_> result = new List <Producto_>();

            StreamReader         reader   = new StreamReader(JSONdataStream);
            string               JSONdata = reader.ReadToEnd();
            JavaScriptSerializer jss      = new JavaScriptSerializer();
            Producto_            obj      = jss.Deserialize <Producto_>(JSONdata);

            if (obj == null)
            {
                return(result.ToList());
            }

            if (obj.Id != 0)
            {
                var list = from p in BDUsuario.Producto
                           where (p.Id == obj.Id)

                           select new Producto_
                {
                    Id     = p.Id,
                    Nombre = p.Nombre,
                    Precio = p.Precio,
                };
                int count = list.Count();
                return(list.ToList());
            }
            else
            {
                var list = from p in BDUsuario.Producto

                           select new Producto_
                {
                    Id     = p.Id,
                    Nombre = p.Nombre,
                    Precio = p.Precio,
                };
                int count = list.Count();
                return(list.ToList());
            }
        }
Exemple #2
0
        public wsSQLResult CrearProducto(Stream JSONdataStream)
        {
            wsSQLResult result = new wsSQLResult();

            try
            {
                StreamReader         reader   = new StreamReader(JSONdataStream);
                string               JSONdata = reader.ReadToEnd();
                JavaScriptSerializer jss      = new JavaScriptSerializer();
                Producto_            obj      = jss.Deserialize <Producto_>(JSONdata);

                if (obj == null)
                {
                    result.WasSucceful = 0;
                    result.Exception   = "No se pudo deserializar el JSON";
                    return(result);
                }

                Producto newProduct = new Producto
                {
                    Nombre = obj.Nombre,
                    Precio = Convert.ToDouble(obj.Precio),
                };

                BDUsuario.Producto.InsertOnSubmit(newProduct);
                BDUsuario.SubmitChanges();

                result.WasSucceful = 1;
                result.Exception   = "";
                return(result);
            }
            catch (Exception ex)
            {
                result.WasSucceful = 0;
                result.Exception   = ex.Message;
                return(result);
            }
        }