public List <string> GetVendorProductsEisSupplierSKUs(VendorProductFilterDto param)
        {
            IEnumerable <vendorproduct> vendorProducts = null;

            if (param.IsAllSelectedItems)
            {
                if (!string.IsNullOrEmpty(param.SearchString))
                {
                    vendorProducts = _context.vendorproducts
                                     .Where(x => x.SupplierSKU.Contains(param.SearchString) ||
                                            x.Name.Contains(param.SearchString));
                }
                else
                {
                    vendorProducts = searchVendorProducts(param.SearchString,
                                                          param.VendorId ?? -1,
                                                          param.CompanyId ?? -1,
                                                          param.WithEisSKULink ?? -1,
                                                          param.QuantityFrom ?? -1,
                                                          param.QuantityTo ?? -1,
                                                          param.withImages,
                                                          param.ExcludedModelIds);
                }
            }
            else
            {
                vendorProducts = _context.vendorproducts.Where(x => param.SelectedModelIds.Contains(x.EisSupplierSKU) &&
                                                               (!param.ExcludedModelIds.Any() || param.ExcludedModelIds.Contains(x.EisSupplierSKU)));
            }

            return(vendorProducts
                   .Select(x => x.EisSupplierSKU)
                   .ToList());
        }
Beispiel #2
0
        public JsonResult _DeleteBulkVendorProducts(VendorProductFilterDto model)
        {
            try
            {
                // get product's EIS SKU
                var eisSupplierSKUs = _vendorProductService.GetVendorProductsEisSupplierSKUs(model);

                var fileFullPath = string.Format("{0}\\BulkDeleteVendorProducts_{1:yyyyMMdd_HHmmss}.txt", _systemJobsRoot, DateTime.Now);

                using (var streamWriter = new StreamWriter(fileFullPath))
                {
                    var writer = new CsvHelper.CsvWriter(streamWriter);
                    foreach (var sku in eisSupplierSKUs)
                    {
                        // just write the vendor product's Id which we need to delete
                        writer.WriteField(sku);
                        writer.NextRecord();
                    }
                }

                // create new job for the Amazon Get Info for the asins
                var systemJob = new SystemJobDto
                {
                    JobType     = JobType.BulkDeleteVendorProduct,
                    Parameters  = fileFullPath,
                    SubmittedBy = User.Identity.Name
                };
                _systemJobService.CreateSystemJob(systemJob);

                return(Json("Bulk deletion of vendor products has been passed to EIS System Jobs for execution.", JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { Error = "Error in deleting vendor products! - Message: " + EisHelper.GetExceptionMessage(ex) },
                            JsonRequestBehavior.AllowGet));
            }
        }