public static String UploadLogo(byte[] imageData, ImageFormat imageFormat)
        {
            var photoPath = BuildFilePath("." + Global.GetImgFormatName(imageFormat));

            return(ExecResizeImage(imageData, OrganisationLogoSize, Global.GetStore(), photoPath));
        }
        public static void DataInvoicesActionView(BasePage page, Invoice targetInvoice)
        {
            var daoFactory       = page.DaoFactory;
            var invoiceItems     = daoFactory.InvoiceItemDao.GetAll();
            var invoiceItemsJson = JsonConvert.SerializeObject(invoiceItems.ConvertAll(item => new
            {
                id               = item.ID,
                title            = item.Title,
                stockKeepingUnit = item.StockKeepingUnit,
                description      = item.Description,
                price            = item.Price,
                quantity         = item.Quantity,
                stockQuantity    = item.StockQuantity,
                trackInventory   = item.TrackInventory,
                invoiceTax1ID    = item.InvoiceTax1ID,
                invoiceTax2ID    = item.InvoiceTax2ID
            }));

            var invoiceTaxes     = daoFactory.InvoiceTaxDao.GetAll();
            var invoiceTaxesJson = JsonConvert.SerializeObject(invoiceTaxes.ConvertAll(item => new
            {
                id          = item.ID,
                name        = item.Name,
                rate        = item.Rate,
                description = item.Description
            }));

            var invoiceSettings     = Global.TenantSettings.InvoiceSetting ?? InvoiceSetting.DefaultSettings;
            var invoiceSettingsJson = JsonConvert.SerializeObject(new
            {
                autogenerated = invoiceSettings.Autogenerated,
                prefix        = invoiceSettings.Prefix,
                number        = invoiceSettings.Number,
                terms         = invoiceSettings.Terms
            });

            var presetContactsJson = string.Empty;
            var presetContactID    = UrlParameters.ContactID;

            if (targetInvoice == null && presetContactID != 0)
            {
                var targetContact = daoFactory.ContactDao.GetByID(presetContactID);
                if (targetContact != null)
                {
                    presetContactsJson = JsonConvert.SerializeObject(new
                    {
                        id                   = targetContact.ID,
                        displayName          = targetContact.GetTitle().HtmlEncode().ReplaceSingleQuote(),
                        smallFotoUrl         = ContactPhotoManager.GetSmallSizePhoto(targetContact.ID, targetContact is Company),
                        currencyAbbreviation = targetContact.Currency
                    });
                }
            }

            var currencyRates     = daoFactory.CurrencyRateDao.GetAll();
            var currencyRatesJson = JsonConvert.SerializeObject(currencyRates.ConvertAll(item => new
            {
                id           = item.ID,
                fromCurrency = item.FromCurrency,
                toCurrency   = item.ToCurrency,
                rate         = item.Rate
            }));

            var          apiServer    = new Api.ApiServer();
            const string apiUrlFormat = "{0}crm/contact/{1}/data.json";

            var contactInfoData   = string.Empty;
            var consigneeInfoData = string.Empty;

            if (targetInvoice != null)
            {
                if (targetInvoice.ContactID > 0)
                {
                    contactInfoData = apiServer.GetApiResponse(String.Format(apiUrlFormat, SetupInfo.WebApiBaseUrl, targetInvoice.ContactID), "GET");
                }
                if (targetInvoice.ConsigneeID > 0)
                {
                    consigneeInfoData = apiServer.GetApiResponse(String.Format(apiUrlFormat, SetupInfo.WebApiBaseUrl, targetInvoice.ConsigneeID), "GET");
                }
            }
            else if (presetContactID != 0)
            {
                contactInfoData = apiServer.GetApiResponse(String.Format(apiUrlFormat, SetupInfo.WebApiBaseUrl, presetContactID), "GET");
            }

            var apiUrl = String.Format("{0}crm/invoice/{1}.json",
                                       SetupInfo.WebApiBaseUrl,
                                       targetInvoice != null ? targetInvoice.ID.ToString(CultureInfo.InvariantCulture) : "sample");
            var invoiceData = apiServer.GetApiResponse(apiUrl, "GET");

            var script = String.Format(@"
                                        var invoiceItems = '{0}';
                                        var invoiceTaxes = '{1}';
                                        var invoiceSettings = '{2}';
                                        var invoicePresetContact = '{3}';
                                        var currencyRates = '{4}';
                                        var invoiceJsonData = '{5}';",
                                       Global.EncodeTo64(invoiceItemsJson),
                                       Global.EncodeTo64(invoiceTaxesJson),
                                       Global.EncodeTo64(invoiceSettingsJson),
                                       Global.EncodeTo64(presetContactsJson),
                                       Global.EncodeTo64(currencyRatesJson),
                                       targetInvoice != null ? Global.EncodeTo64(targetInvoice.JsonData) : ""
                                       );

            page.RegisterInlineScript(script, onReady: false);
            page.JsonPublisher(contactInfoData, "invoiceContactInfo");
            page.JsonPublisher(consigneeInfoData, "invoiceConsigneeInfo");
            page.JsonPublisher(invoiceData, "invoice");
        }