Exemple #1
0
        private JObject GetCreateInvoiceJsonStructure(InvoiceCreate invoiceProperties, Guid processId)
        {
            OperationResult result        = new OperationResult();
            JObject         jObject       = new JObject();
            CountryEntity   countryEntity = new CountryEntity();

            try
            {
                if (invoiceProperties != null)
                {
                    if (invoiceProperties.billDate != null)
                    {
                        DateTime date = DateTime.Parse(invoiceProperties.billDate);
                        jObject.Add($"{InvoiceFields.PurchaseDate}", date.ToString("yyyy-MM-dd"));
                    }


                    if (invoiceProperties.patientId > 0)
                    {
                        jObject.Add($"{InvoiceSchemas.CustomerIdSchema}@odata.bind", $"/{contactEntity.EntityPluralName}({ContactFields.IdAboxPatient}={invoiceProperties.patientId})");
                    }

                    if (invoiceProperties.patientId > 0)
                    {
                        jObject.Add($"{InvoiceSchemas.CustomerContactSchema}@odata.bind", $"/{contactEntity.EntityPluralName}({ContactFields.IdAboxPatient}={invoiceProperties.patientId})");
                    }


                    if (!(String.IsNullOrEmpty(invoiceProperties.billImageUrl)))
                    {
                        jObject.Add(InvoiceFields.InvoiceImageWebUrl, invoiceProperties.billImageUrl);
                    }



                    if (!(String.IsNullOrEmpty(invoiceProperties.pharmacyId)))
                    {
                        jObject.Add($"{InvoiceSchemas.Pharmacy}@odata.bind", $"/{pharmacyEntity.EntityPluralName}({PharmacyFields.Id}='{invoiceProperties.pharmacyId}')");
                    }

                    if (!(String.IsNullOrEmpty(invoiceProperties.billId)))
                    {
                        jObject.Add(InvoiceFields.InvoiceNumber, invoiceProperties.billId);
                    }


                    if (invoiceProperties.products != null)
                    {
                        var serialized = JsonConvert.SerializeObject(invoiceProperties.products);
                        jObject.Add($"{InvoiceFields.ProductsSelectedJson}", serialized);
                    }

                    if (invoiceProperties.nonAboxProducts != null)
                    {
                        var serialized = JsonConvert.SerializeObject(invoiceProperties.nonAboxProducts);
                        jObject.Add($"{InvoiceFields.NonAboxProductsSelectedJson}", serialized);
                    }

                    if (invoiceProperties.idFromDatabase != null)
                    {
                        jObject.Add($"{InvoiceFields.IdAboxInvoice}", invoiceProperties.idFromDatabase);
                    }

                    if (!(String.IsNullOrEmpty(invoiceProperties.country)))
                    {
                        jObject.Add($"{InvoiceSchemas.Country}@odata.bind", $"/{countryEntity.EntityPluralName}({CountryFields.IdCountry}='{invoiceProperties.country}')");
                    }

                    if (!String.IsNullOrEmpty(invoiceProperties.status))
                    {
                        int status = sharedMethods.GetInvoiceStatusValue(invoiceProperties.status);
                        if (status > -1)
                        {
                            jObject.Add(InvoiceFields.StatusCode, status);
                        }
                    }

                    if (!String.IsNullOrEmpty(invoiceProperties.statusReason))
                    {
                        jObject.Add(InvoiceFields.StatusReason, invoiceProperties.statusReason);
                    }

                    if (invoiceProperties.revisionTime1 != null && invoiceProperties.revisionTime1 > -1)
                    {
                        jObject.Add(InvoiceFields.RevisionTime1, invoiceProperties.revisionTime1);
                    }

                    if (invoiceProperties.revisionTime2 != null && invoiceProperties.revisionTime2 > -1)
                    {
                        jObject.Add(InvoiceFields.RevisionTime2, invoiceProperties.revisionTime2);
                    }

                    if (invoiceProperties.totalAmount != null)
                    {
                        jObject.Add(InvoiceFields.TotalAmount, invoiceProperties.totalAmount);
                    }

                    if (!String.IsNullOrEmpty(invoiceProperties.purchaseMethod))
                    {
                        int purchaseMethodCode = sharedMethods.GetInvoicePurchaseMethodValue(invoiceProperties.purchaseMethod);
                        if (purchaseMethodCode > -1)
                        {
                            jObject.Add(InvoiceFields.PurchaseMethod, purchaseMethodCode);
                        }
                    }



                    ////////////
                }

                return(jObject);
            }
            catch (Exception ex)
            {
                LogEventInfo log = new LogEventInfo(LogLevel.Error, Logger.Name, null, "", null, new Exception(ex.ToString()));
                log.Properties["ProcessID"]  = processId;
                log.Properties["AppID"]      = AboxDynamicsBase.Classes.Constants.ApplicationIdWebAPI;
                log.Properties["MethodName"] = System.Reflection.MethodBase.GetCurrentMethod().Name;
                Logger.Log(log);
                jObject = null;
                return(jObject);
            }
        }