private static bool TryValidate(this CsvOperationModel csvOperation, out ICollection <ValidationResult> validationResults)
        {
            validationResults = new List <ValidationResult>();

            if (!Validator.TryValidateObject(csvOperation, new ValidationContext(csvOperation), validationResults))
            {
                return(false);
            }

            if (csvOperation.CsvItem.Price == 0)
            {
                validationResults.Add(new ValidationResult("Price cannot be empty or zero", new string[] { nameof(csvOperation.CsvItem.Price) }));
            }

            if (csvOperation.CsvItem.DiscountPrice == 0)
            {
                validationResults.Add(new ValidationResult("Discounted Price cannot be empty or zero", new string[] { nameof(csvOperation.CsvItem.DiscountPrice) }));
            }

            if (csvOperation.CsvItem.DiscountPrice > csvOperation.CsvItem.Price)
            {
                validationResults.Add(new ValidationResult("Discounted Price cannot be larger than Price", new string[] { nameof(csvOperation.CsvItem.DiscountPrice) }));
            }

            return(!validationResults.Any());
        }
        public static Product ToProduct(this CsvOperationModel csvOperationModel, ProductFamily productFamily = null, Product product = null)
        {
            if (product == null)
            {
                product = new Product();
                product.ProductDetails = new List <ProductDetail>();
            }

            product.Price         = csvOperationModel.CsvItem.Price;
            product.DiscountPrice = csvOperationModel.CsvItem.DiscountPrice;
            product.Sku           = csvOperationModel.CsvItem.Sku;

            if (productFamily != null)
            {
                product.ProductFamily = productFamily;
            }
            else
            {
                product.ProductFamily = new ProductFamily
                {
                    Category = csvOperationModel.CsvItem.Category,
                    Code     = csvOperationModel.CsvItem.FamilyCode
                };
            }

            UpdateDetails(product, nameof(csvOperationModel.CsvItem.Brand), csvOperationModel.CsvItem.Brand);
            UpdateDetails(product, nameof(csvOperationModel.CsvItem.Color), csvOperationModel.CsvItem.Color);
            UpdateDetails(product, nameof(csvOperationModel.CsvItem.Delivery), csvOperationModel.CsvItem.Delivery);
            UpdateDetails(product, nameof(csvOperationModel.CsvItem.Size), csvOperationModel.CsvItem.Size);
            UpdateDetails(product, nameof(csvOperationModel.CsvItem.Type), csvOperationModel.CsvItem.Type);

            return(product);
        }
 public static Product ToProduct(this CsvOperationModel csvOperationModel, Product product = null)
 {
     return(csvOperationModel.ToProduct(product.ProductFamily, product));
 }