Exemplo n.º 1
0
        public ActionResult SolicitarProductos()
        {
            var pedido = new Pedido
            {
                Fecha = DateTime.Now,
                UsuarioId = "10123456789",
                PedidoDetalle = PedidoDetalle
            };

            try
            {
                const string url = "http://localhost:27914/VentaService.svc/Pedidos";
                var pedidoCreado = HttpWebRequestHelper.DeserializePost<Pedido>(url, pedido);

                return View(pedidoCreado);
            }
            catch (WebException e)
            {
                if (e.Status == WebExceptionStatus.ConnectFailure)
                {
                    RegistrarCola(pedido);

                    ViewBag.Mensaje = "Pedido pendiente de regularizar";
                }
                else
                {
                    HttpStatusCode code = ((HttpWebResponse)e.Response).StatusCode;

                    if (code == HttpStatusCode.NoContent)
                    {
                        StreamReader reader2 = new StreamReader(e.Response.GetResponseStream());
                        string error = reader2.ReadToEnd();
                        JavaScriptSerializer js = new JavaScriptSerializer();

                        string mensaje = js.Deserialize<string>(error);

                        ViewBag.Mensaje = mensaje;
                    }
                }
            }

            return View();
        }
Exemplo n.º 2
0
 private void RegistrarPedidos(Pedido pedido)
 {
     try
     {
         const string url = "http://localhost:27914/VentaService.svc/Pedidos";
         var pedidoCreado = HttpWebRequestHelper.DeserializePost<Pedido>(url, pedido);
     }
     catch (WebException e)
     {
     }
 }
Exemplo n.º 3
0
        private void RegistrarCola(Pedido pedido)
        {
            const string rutaCola = @".\private$\asanchez_nnn";
            if (!MessageQueue.Exists(rutaCola))
            {
                MessageQueue.Create(rutaCola);
            }

            var oCola = new MessageQueue(rutaCola);
            var oMensaje = new Message()
            {
                Label = "Registro Pedido",
                Body = pedido
            };

            oCola.Send(oMensaje);
        }