Skip to main content
edited tags
Link
Peter Csala
  • 10.8k
  • 1
  • 16
  • 36
Tweeted twitter.com/StackCodeReview/status/1613551381159223297
Removed from Network Questions by Mast
Question Protected by Mast
Became Hot Network Question
edited title
Link
Mast
  • 13.8k
  • 12
  • 57
  • 127

How CSV to avoid too many If elselist, map to database

deleted 612 characters in body
Source Link
Peter Csala
  • 10.8k
  • 1
  • 16
  • 36
        if (fileCSV == null && fileCSV.ContentLength == 0)
            {
                importModel.Error = "Error1";
                return importModel;
            }
            else
            {
                List<ImportModel> mappings = _importService.ImportCSVToList<ImportModel>(fileCSV);
                if (mappings.Count > 0)
                {
                    IEnumerable<ImportModel> duplicates = mappings.GroupBy(x => x.ProductSku).SelectMany(g => g.Skip(1)).ToList();
                    if (duplicates.Any())
                    {
                        importModel.Error = "Error2";
                        return importModel;
 
                    }
                    else
                    {
                        var products = _productService.GetProducts(productSkuList).ToList();
                        if (!importModel.InvalidSkuList.Any())
                        {
                            bool isImported = _productService.Import(mappings);
                            if (!isImported)
                            {
                                importModel.Error = "Error3";
                            }
                        }
                        else
                        {
                            return importModel;
                        }
                    }
                }
                else
                {
                    importModel.Error =  "Error4";
                    return importModel;
                }
            }
        if (fileCSV == null && fileCSV.ContentLength == 0)
            {
                importModel.Error = "Error1";
                return importModel;
            }
            else
            {
                List<ImportModel> mappings = _importService.ImportCSVToList<ImportModel>(fileCSV);
                if (mappings.Count > 0)
                {
                    IEnumerable<ImportModel> duplicates = mappings.GroupBy(x => x.ProductSku).SelectMany(g => g.Skip(1)).ToList();
                    if (duplicates.Any())
                    {
                        importModel.Error = "Error2";
                        return importModel;
 
                    }
                    else
                    {
                        var products = _productService.GetProducts(productSkuList).ToList();
                        if (!importModel.InvalidSkuList.Any())
                        {
                            bool isImported = _productService.Import(mappings);
                            if (!isImported)
                            {
                                importModel.Error = "Error3";
                            }
                        }
                        else
                        {
                            return importModel;
                        }
                    }
                }
                else
                {
                    importModel.Error =  "Error4";
                    return importModel;
                }
            }
if (fileCSV == null && fileCSV.ContentLength == 0)
{
    importModel.Error = "Error1";
    return importModel;
}
else
{
    List<ImportModel> mappings = _importService.ImportCSVToList<ImportModel>(fileCSV);
    if (mappings.Count > 0)
    {
        IEnumerable<ImportModel> duplicates = mappings.GroupBy(x => x.ProductSku).SelectMany(g => g.Skip(1)).ToList();
        if (duplicates.Any())
        {
            importModel.Error = "Error2";
            return importModel;
        }
        else
        {
            var products = _productService.GetProducts(productSkuList).ToList();
            if (!importModel.InvalidSkuList.Any())
            {
                bool isImported = _productService.Import(mappings);
                if (!isImported)
                {
                    importModel.Error = "Error3";
                }
            }
            else
            {
                return importModel;
            }
        }
    }
    else
    {
        importModel.Error =  "Error4";
        return importModel;
    }
}
edited title
Link
Optimus
  • 131
  • 4
Loading
Source Link
Optimus
  • 131
  • 4
Loading