示例#1
0
        public string this[string columnName]
        {
            get
            {
                var field = (FieldNames)Enum.Parse(typeof(FieldNames), columnName);
                switch (field)
                {
                case FieldNames.Inventory:
                    if (Inventory < 0)
                    {
                        return("Inventory can not be less than zero");
                    }
                    break;

                case FieldNames.ModelName:
                    if (ModelName.Contains("XXX"))
                    {
                        return("Our Store does not support adult content.");
                    }
                    break;

                case FieldNames.Price:
                    if (Price < 0)
                    {
                        return("Price can not be less than zero");
                    }
                    break;

                case FieldNames.SalePrice:
                    if (Inventory > 50 && SalePrice > (Price * .9M))
                    {
                        return(ModelName + " must be marked down due to stock quantity greater than 50");
                    }
                    if (Inventory < 50 && SalePrice != Price)
                    {
                        return(ModelName + " must not be marked down if the quantity is less than 50");
                    }
                    break;

                default:
                    break;
                }
                return(string.Empty);
            }
        }
示例#2
0
        void CheckForErrors(ref string errorInfo, string propertyName)
        {
            switch (propertyName)
            {
            case "ModelNumber":
                if (ModelNumber != null && ModelNumber.Contains("XXX"))
                {
                    errorInfo = "ModelName can not contain adult content!";
                }
                break;

            case "ModelName":
                if (ModelName == null)
                {
                    errorInfo = "Can't be null";
                }
                else if (ModelName != null && ModelName.Contains("XXX"))
                {
                    errorInfo = "ModelName can not contain adult content!";
                }
                break;

            case "UnitCost":
                if (UnitCost < 0)
                {
                    errorInfo = "Unit Cost can not be negative";
                }
                break;

            case "Description":
                if (Description != null && Description.Contains("XXX"))
                {
                    errorInfo = "Description can not contain adult content!";
                }
                break;

            case "UnitsInStock":
                if (UnitsInStock < 0)
                {
                    errorInfo = "Stock count can not be negative!";
                }
                break;
            }
        }
        public override string this[string columnName]
        {
            get
            {
                switch (columnName)
                {
                case nameof(Inventory):
                    ClearErrors(columnName);
                    CheckSalePrice(columnName);
                    if (Inventory < 0)
                    {
                        AddError("Inventory can not be less than zero", columnName);
                    }
                    CheckSalePrice(nameof(SalePrice));

                    break;

                case nameof(ModelName):
                    if (ModelName.Contains("XXX"))
                    {
                        var errors = new List <string>()
                        {
                            "Our Store does not support adult content."
                        };
                        SetErrors(errors, columnName);
                    }
                    else
                    {
                        ClearErrors(columnName);
                    }
                    break;

                case nameof(Price):
                    if (Price < 0)
                    {
                        var errors = new List <string>()
                        {
                            "Price can not be less than zero"
                        };
                        SetErrors(errors, columnName);
                    }
                    else
                    {
                        ClearErrors(columnName);
                    }
                    break;

                case nameof(SalePrice):
                    ClearErrors(columnName);
                    CheckSalePrice(columnName);
                    if (SalePrice < 0)
                    {
                        AddError("Sale Price can not be less than zero", columnName);
                    }
                    CheckSalePrice(nameof(Inventory));
                    break;

                default:
                    break;
                }
                return(string.Empty);
            }
        }
示例#4
0
        public override string this[string columnName]
        {
            get
            {
                var field = (FieldNames)Enum.Parse(typeof(FieldNames), columnName);
                switch (field)
                {
                case FieldNames.Inventory:
                    ClearErrors(columnName);
                    CheckSalePrice(columnName);
                    if (SalePrice < 0)
                    {
                        AddError("Inventory can not be less than zero", columnName);
                    }
                    CheckSalePrice(FieldNames.SalePrice.ToString());

                    break;

                case FieldNames.ModelName:
                    if (ModelName.Contains("XXX"))
                    {
                        var errors = new List <string>()
                        {
                            "Our Store does not support adult content."
                        };
                        SetErrors(errors, columnName);
                    }
                    else
                    {
                        ClearErrors(columnName);
                    }
                    break;

                case FieldNames.Price:
                    if (Price < 0)
                    {
                        var errors = new List <string>()
                        {
                            "Price can not be less than zero"
                        };
                        SetErrors(errors, columnName);
                    }
                    else
                    {
                        ClearErrors(columnName);
                    }
                    break;

                case FieldNames.SalePrice:
                    ClearErrors(columnName);
                    CheckSalePrice(columnName);
                    if (SalePrice < 0)
                    {
                        AddError("Sale Price can not be less than zero", columnName);
                    }
                    CheckSalePrice(FieldNames.Inventory.ToString());
                    break;

                default:
                    break;
                }
                return(string.Empty);
            }
        }