コード例 #1
0
        public async Task <IActionResult> BufferSetter(FileImportViewModel model)
        {
            string fileExtension = Path.GetExtension(model.CSVFile.FileName);

            if (fileExtension != ".csv")
            {
                ModelState.AddModelError("", "File must be a CSV type");
                return(View());
            }

            Dictionary <string, int> activeBufferProducts = await _fileReader.RetrieveSkuAndQty(model.CSVFile);

            Dictionary <string, int> productsToUpdate = await _skuVault.GetProductsToUpdate(activeBufferProducts);

            StringBuilder sb = new StringBuilder();

            foreach (var accountName in _channelAdvisor.GetAcctNames())
            {
                sb.Append(_fileReader.ConvertToStoreBufferSB(
                              sb.Length == 0,
                              productsToUpdate,
                              accountName));
            }

            byte[]            fileContent = new UTF8Encoding().GetBytes(sb.ToString());
            string            contentType = "text/csv";
            string            fileName    = $"StoreBuffer-{ DateTime.Now.ToShortDateString() }.csv";
            FileContentResult file        = File(fileContent, contentType, fileName);

            return(file);
        }