Ejemplo n.º 1
0
        public async Task CreateCatalogItem(ItemForModeration item)
        {
            var newCatalogItem = new ProducerCatalogItem {
                EnName              = item.EnName,
                RuName              = item.RuName,
                ProducerId          = item.ProducerId,
                ProducerCode        = item.ProducerCode,
                ProducerCodeTrimmed = _producerCodeService.TrimCode(item.ProducerCode),
                SeoParameterId      = item.SeoParameterId
            };

            await _dbContext.AddAsync(newCatalogItem);

            await _dbContext.SaveChangesAsync();
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> DownloadCatalogsAsync()
        {
            var files = new List <FileModel> {
                new FileModel("Bosch", "01_Прайс_лист_Бош_Термотехника_08.xlsx"),
                new FileModel("Beretta", "02 BERETTA прайс.xlsx"),
                new FileModel("Wolf", "03_2017_03_20_WOLF_прайс_лист_на.xlsx"),
                new FileModel("Viessmann", "04 Viessmann от 01.03.2017.xlsx"),
                new FileModel("Buderus", "05 BUDERUS запчасти.xlsx"),
                new FileModel("Navien", "06 01042017 Navien.xlsx"),
                new FileModel("Thermona", "07 THERMONA прайс запчасти.xlsx"),
                new FileModel("Giersch", "08 GIERSCH прайс запчасти.xlsx"),
                new FileModel("ACV", "09 ACV прайс запчасти.xlsx"),
                new FileModel("ACV", "10 ACV цены запчасти Alfa Comfort.xlsx"),
                new FileModel("Rinnai", "15__АСЦ_прайс_запчасти_Rinnai_RUS.xlsx"),
                new FileModel("Baxi", "baxi.xlsx"),
                new FileModel("Protherm", "Protherm.xlsx"),
                new FileModel("Vaillant", "vaillant.xlsx")
            };

            try {
                string sWebRootFolder = _hostingEnvironment.WebRootPath + "./../files/catalogs/";
                foreach (var fileModel in files)
                {
                    var catalogs = new Collection <ProducerCatalogItem> ();
                    var fileName = fileModel.FileName;

                    FileInfo file = new FileInfo(Path.Combine(sWebRootFolder, fileName));

                    var producer = await _partProducerRepository.CreateProducerIfNotExist(fileModel.ProducerName);

                    using (ExcelPackage package = new ExcelPackage(file)) {
                        if (package.Workbook != null && package.Workbook.Worksheets != null)
                        {
                            foreach (var worksheet in package.Workbook.Worksheets)
                            {
                                if (worksheet != null)
                                {
                                    int rowCount = worksheet.Dimension != null ? worksheet.Dimension.Rows : 0;
                                    int ColCount = worksheet.Dimension != null ? worksheet.Dimension.Columns : 0;

                                    for (int row = 2; row <= rowCount; row++)
                                    {
                                        //if (!string.IsNullOrEmpty (worksheet.Cells[row, 1].Value.ToString ())) {
                                        var catalogItem = new ProducerCatalogItem();
                                        catalogItem.Producer = producer;

                                        for (int col = 1; col <= ColCount; col++)
                                        {
                                            switch (col)
                                            {
                                            case 1:
                                            {
                                                catalogItem.ProducerCode = worksheet.Cells[row, col]?.Value?.ToString().Trim();
                                                break;
                                            }

                                            case 2:
                                            {
                                                catalogItem.RuName = worksheet.Cells[row, col]?.Value?.ToString().Trim();
                                                break;
                                            }

                                            case 3:
                                            {
                                                catalogItem.EnName = worksheet.Cells[row, col]?.Value?.ToString().Trim();
                                                break;
                                            }
                                            }
                                        }
                                        catalogs.Add(catalogItem);
                                        //}
                                    }
                                }
                            }
                        }
                    }

                    await this._catalogItemRepository.AddRangeForProducer(catalogs, producer);
                }
            } catch (Exception ex) {
                return(Ok(ex.Message + "\n" + ex.StackTrace));
            }

            return(Ok(true));
        }