Example #1
0
        public FaturaDb ConverteApiEmDB(GetInvoiceResponse fatura)
        {
            try
            {
                var cliente  = clienteDal.GetClienteByIdApi(fatura.Customer.Id);
                var faturaDb = new FaturaDb
                {
                    CodCli          = Convert.ToInt32(cliente.Codigo),
                    IdApi           = fatura.Id,
                    Url             = fatura.Url,
                    Valor           = fatura.Amount / 100,
                    FormaPagamento  = fatura.PaymentMethod,
                    QuantParcelas   = fatura.Subscription.Installments,
                    Status          = fatura.Status,
                    DtCobranca      = fatura.DueAt,
                    DtVencimento    = fatura.Cycle.BillingAt,
                    DtCriacao       = fatura.CreatedAt,
                    IdAssinatura    = Convert.ToInt32(fatura.Subscription.Metadata["id"]),
                    TotalDescontos  = fatura.TotalDiscount / 100,
                    TotalAcrescimos = fatura.TotalIncrement / 100
                };

                if (fatura.CanceledAt != null)
                {
                    faturaDb.DtCancelamento = fatura.CanceledAt;
                }

                return(faturaDb);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public async Task <string> PrintInvoices(string[] ExtNumbers)
        {
            GetInvoiceResponse GetInvoiceResponse = await ApiMethods.GetInvoice(HttpContext.Session.GetString("BasePath"),
                                                                                HttpContext.Session.GetString("SessionID"),
                                                                                HttpContext.Session.GetString("ICN"),
                                                                                ExtNumbers);


            return(GetInvoiceResponse.Invoice);
        }
Example #3
0
        public int FaturaCanceladaAtualizaStatus(GetInvoiceResponse _response, int _id)
        {
            const string metodo = "FaturaCanceladaAtualizaStatus";

            try
            {
                var sql = new StringBuilder();
                int rowsAffected;

                sql.Append("update rec_fatura set status=@status, dt_cancelamento=@dtCancelamento where id = @id");

                using (var conn = ConexaoBd.GetConnection())
                {
                    using (var cmd = new SqlCommand(sql.ToString(), conn))
                    {
                        cmd.Parameters.Clear();
                        cmd.Parameters.AddWithValue("@id", _id);
                        cmd.Parameters.AddWithValue("@dtCancelamento", _response.CanceledAt);
                        cmd.Parameters.AddWithValue("@status", _response.Status);
                        rowsAffected = cmd.ExecuteNonQuery();
                    }
                }

                return(rowsAffected);
            }
            catch (SqlException sqlException)
            {
                string strMensagem = "";
                strMensagem = LogDatabaseErrorUtil.CreateErrorDatabaseMessage(sqlException);
                LogDatabaseErrorUtil.LogFileWrite(strMensagem, metodo);

                sqlException.Data["MensagemCustomizada"] = LogDatabaseErrorUtil.ValidateDataBaseErrorNumber(sqlException.Number);
                sqlException.Data["Metodo"] = metodo;
                sqlException.Data["Classe"] = Camada;
                sqlException.Data["Hora"]   = DateTime.Now;

                throw;
            }
            catch (Exception ex)
            {
                string strMensagem = "";

                strMensagem = LogDatabaseErrorUtil.CreateErrorMessage(ex);
                LogDatabaseErrorUtil.LogFileWrite(strMensagem, metodo);

                ex.Data["MensagemCustomizada"] = "Ocorreu um erro ao tentar executar a operação.";
                ex.Data["Metodo"] = metodo;
                ex.Data["Classe"] = Camada;
                ex.Data["Hora"]   = DateTime.Now;

                throw;
            }
        }
    public void ExampleDeserialization()
    {
        /**/
        InvoiceExampleItem item1 = new InvoiceExampleItem()
        {
            Name = "item1"
        };
        InvoiceExampleItem item2 = new InvoiceExampleItem()
        {
            Name = "item2"
        };
        InvoiceExampleItem item3 = new InvoiceExampleItem()
        {
            Name = "item3"
        };
        Items items = new Items();
        InvoiceExampleItem item21 = new InvoiceExampleItem()
        {
            Name = "item1"
        };
        InvoiceExampleItem item22 = new InvoiceExampleItem()
        {
            Name = "item2"
        };
        InvoiceExampleItem item23 = new InvoiceExampleItem()
        {
            Name = "item3"
        };

        items.list.Add(item21);
        items.list.Add(item22);
        items.list.Add(item23);
        Invoice mockInvoice = new Invoice()
        {
            items = items
        };
        /**/
        XmlDocument mockInvoiceSerialized = SerializeInvoice(mockInvoice);

        XmlDocument        mockResponseXml = GenerateXmlResponse(mockInvoiceSerialized);
        GetInvoiceResponse test            = new GetInvoiceResponse();
        GetInvoiceResponse response        = DeserializeXML <GetInvoiceResponse>(mockResponseXml.OuterXml);
        Invoice            resultInvoice   = response.Invoice;

        mockResponseXml.Save("C:\\Users\\360Imprimir\\Desktop\\mockResponseXml");
        mockInvoiceSerialized.Save("C:\\Users\\360Imprimir\\Desktop\\mockInvoiceSerialized.Xml");
        if (mockInvoice.items.list.Count != resultInvoice.items.list.Count)
        {
            throw new Exception("wrong number of items");
        }
    }
        public async Task <IHttpActionResult> Get([FromUri] Guid InvoiceId)
        {
            try
            {
                var result = await _repository.Get <Invoice>(InvoiceId);

                if (result == null)
                {
                    return(NotFound());
                }

                var response = new GetInvoiceResponse {
                    Result = result
                };

                return(Ok(response));
            }
            catch (Exception)
            {
                // TODO: Log exception
            }
            return(InternalServerError());
        }