Exemplo n.º 1
0
        public FileUploadResult ProcessUpload(HttpContext context)
        {
            var fileUploadResult = new FileUploadResult();

            if (!FileToUpload.HasFilesToUpload(context))
            {
                return(fileUploadResult);
            }

            var file = new FileToUpload(context);

            String assignedPath;

            Global.GetStore().SaveTemp("temp", out assignedPath, file.InputStream);

            file.InputStream.Position = 0;

            var jObject = ImportFromCSV.GetInfo(file.InputStream, context.Request["importSettings"]);

            jObject.Add("assignedPath", assignedPath);

            fileUploadResult.Success = true;
            fileUploadResult.Data    = Global.EncodeTo64(jObject.ToString());

            return(fileUploadResult);
        }
        public FileUploadResult ProcessUpload(HttpContext context)
        {
            if (!WebItemSecurity.IsAvailableForUser(ProductEntryPoint.ID.ToString(), SecurityContext.CurrentAccount.ID))
                throw CRMSecurity.CreateSecurityException();

            var fileUploadResult = new FileUploadResult();

            if (!FileToUpload.HasFilesToUpload(context)) return fileUploadResult;

            var file = new FileToUpload(context);

            String assignedPath;

            Global.GetStore().SaveTemp("temp", out assignedPath, file.InputStream);

            file.InputStream.Position = 0;

            var jObject = ImportFromCSV.GetInfo(file.InputStream, context.Request["importSettings"]);

            jObject.Add("assignedPath", assignedPath);

            fileUploadResult.Success = true;
            fileUploadResult.Data = Global.EncodeTo64(jObject.ToString());

            return fileUploadResult;
        }
        public static void DataInvoicesDetailsView(BasePage page, Invoice targetInvoice)
        {
            if (targetInvoice == null)
            {
                return;
            }

            var script = String.Format(@"var invoiceData = '{0}';", Global.EncodeTo64(targetInvoice.JsonData));

            var apiServer = new Api.ApiServer();
            var apiUrl    = String.Format("{0}crm/invoice/{1}.json", SetupInfo.WebApiBaseUrl, targetInvoice.ID);
            var invoice   = apiServer.GetApiResponse(apiUrl, "GET");

            page.RegisterInlineScript(script, onReady: false);
            page.JsonPublisher(invoice, "invoice");
        }
Exemplo n.º 4
0
        public FileUploadResult ProcessUploadFake(string fileTemp, string importSettingsJSON)
        {
            var fileUploadResult = new FileUploadResult();

            if (String.IsNullOrEmpty(fileTemp) || String.IsNullOrEmpty(importSettingsJSON))
            {
                return(fileUploadResult);
            }

            if (!_global.GetStore().IsFile("temp", fileTemp))
            {
                return(fileUploadResult);
            }

            JsonDocument jObject;

            //Read contents
            using (Stream storeStream = _global.GetStore().GetReadStream("temp", fileTemp))
            {
                using (var CSVFileStream = new MemoryStream())
                {
                    //Copy
                    var buffer = new byte[4096];
                    int readed;
                    while ((readed = storeStream.Read(buffer, 0, 4096)) != 0)
                    {
                        CSVFileStream.Write(buffer, 0, readed);
                    }
                    CSVFileStream.Position = 0;

                    jObject = _importFromCSV.GetInfo(CSVFileStream, importSettingsJSON);
                }
            }

            var jsonDocumentAsDictionary = JsonSerializer.Deserialize <Dictionary <string, string> >(jObject.ToString());

            jsonDocumentAsDictionary.Add("assignedPath", fileTemp);

            fileUploadResult.Success = true;
            fileUploadResult.Data    = Global.EncodeTo64(JsonSerializer.Serialize(jsonDocumentAsDictionary));

            return(fileUploadResult);
        }
        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");
        }