private void button2_Click(object sender, EventArgs e)
        {
            CCompra cCompra = new CCompra();

            cCompra.GuardarCompra(listado);
            this.Close();
        }
        public JsonResult Comprar(CProducto modelo)
        {
            try
            {
                if (modelo != null)
                {
                    CCompra compra = new CCompra()
                    {
                        persona  = (CPersona)Session["USUARIO"],
                        producto = modelo
                    };

                    IRestResponse WSR = Task.Run(() => api.Post("Operaciones/Compra", compra)).Result;
                    if (WSR.StatusCode == HttpStatusCode.OK)
                    {
                        return(new JsonResult()
                        {
                            Data = JObject.Parse(WSR.Content).ToObject <CTransaccion>(),
                            ContentType = "json",
                            MaxJsonLength = int.MaxValue,
                            JsonRequestBehavior = JsonRequestBehavior.AllowGet
                        });
                    }
                    else
                    {
                        return(new JsonResult()
                        {
                            Data = WSR.Content,
                            ContentType = "json",
                            MaxJsonLength = int.MaxValue,
                            JsonRequestBehavior = JsonRequestBehavior.AllowGet
                        });
                    }
                }
                else
                {
                    return(new JsonResult()
                    {
                        Data = "El modelo viene nulo",
                        ContentType = "json",
                        MaxJsonLength = int.MaxValue,
                        JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    });
                }
            }
            catch (Exception ex)
            {
                return(new JsonResult()
                {
                    Data = ex.Message,
                    ContentType = "json",
                    MaxJsonLength = int.MaxValue,
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
        }
示例#3
0
        public HttpResponseMessage Compra(CCompra pModelo)
        {
            HttpResponseMessage respuesta = null;

            try
            {
                CripMonEntities       db      = new CripMonEntities();
                PA_bsc_Empresa_Result Empresa = db.PA_bsc_Empresa(Convert.ToInt32(ConfigurationManager.AppSettings["Empresa"].ToString())).FirstOrDefault();

                CoinPayments payment = new CoinPayments(Empresa.Llave_Privada, Empresa.Llave_Publica);
                SortedList <string, string> parms = new SortedList <string, string>();
                parms.Add("amount", pModelo.producto.Monto.ToString());
                parms.Add("currency1", "ETH");
                parms.Add("currency2", "ETH");

                string jsonResult = null;
                Dictionary <string, object> result = payment.CreateTransaction(parms, out jsonResult);

                if (result["error"].ToString() == "ok")
                {
                    CCoinPaymentMessage cpRespuesta = (jsonResult == null) ? null : JObject.Parse(jsonResult).ToObject <CCoinPaymentMessage>();

                    db.PA_Transaccion(cpRespuesta.result.txn_id,
                                      Convert.ToInt32(ConfigurationManager.AppSettings["Monedero"].ToString()),
                                      null,
                                      pModelo.persona.Usuario,
                                      jsonResult,
                                      pModelo.producto.Producto,
                                      cpRespuesta.result.amount,
                                      Convert.ToInt32(cpRespuesta.result.timeout),
                                      cpRespuesta.result.status_url,
                                      cpRespuesta.result.qrcode_url,
                                      cpRespuesta.result.address);

                    respuesta = Request.CreateResponse(HttpStatusCode.OK, true);
                }
                else
                {
                    string errResult = null;

                    switch (result["error"].ToString())
                    {
                    case "HMAC signature does not match":
                        errResult = "Cartera no reconocida";
                        break;

                    default:
                        errResult = "Error desconocido.";
                        break;
                    }

                    respuesta = Request.CreateResponse(HttpStatusCode.NotImplemented, errResult);
                }
            }
            catch (Exception ex)
            {
                respuesta = Request.CreateErrorResponse(HttpStatusCode.Conflict, (ex.InnerException == null) ? ex.Message : ex.InnerException.Message);
            }

            return(respuesta);
        }
        public JsonResult Comprar(CProducto modelo)
        {
            try
            {
                if (modelo != null)
                {
                    CCompra compra = new CCompra()
                    {
                        persona  = (CPersona)Session["USUARIO"],
                        producto = modelo
                    };

                    IRestResponse WSR = Task.Run(() => api.Put("Registro/Compra", compra)).Result;
                    if (WSR.StatusCode == HttpStatusCode.OK)
                    {
                        bool result = false;
                        bool.TryParse(WSR.Content, out result);

                        Autenticar((CInicioSesion)Session["LOGIN"]);

                        if (result == true)
                        {
                            return(new JsonResult()
                            {
                                Data = true,
                                ContentType = "json",
                                MaxJsonLength = int.MaxValue,
                                JsonRequestBehavior = JsonRequestBehavior.AllowGet
                            });
                        }
                        else
                        {
                            return(new JsonResult()
                            {
                                Data = WSR.Content,
                                ContentType = "json",
                                MaxJsonLength = int.MaxValue,
                                JsonRequestBehavior = JsonRequestBehavior.AllowGet
                            });
                        }
                    }
                    else
                    {
                        return(new JsonResult()
                        {
                            Data = WSR.Content,
                            ContentType = "json",
                            MaxJsonLength = int.MaxValue,
                            JsonRequestBehavior = JsonRequestBehavior.AllowGet
                        });
                    }
                }
                else
                {
                    return(new JsonResult()
                    {
                        Data = "El modelo viene nulo",
                        ContentType = "json",
                        MaxJsonLength = int.MaxValue,
                        JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    });
                }
            }
            catch (Exception ex)
            {
                return(new JsonResult()
                {
                    Data = ex.Message,
                    ContentType = "json",
                    MaxJsonLength = int.MaxValue,
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
        }