Exemplo n.º 1
0
 public Pricing CheckPrice(Pricing PricingInformation, NorthwindConfig northwindConfig)
 {
     Pricing result;
     Product product = new Product();
     result = product.CheckPrice(PricingInformation, northwindConfig);
     return result;
 }
Exemplo n.º 2
0
        public Pricing CheckPrice(Pricing PricingInformation, NorthwindConfig config)
        {
            int productId = 0;
            int recordCount;

            //TODO: did we need to check if Account exists?
            try
            {
                productId = int.Parse(PricingInformation.ProductId);
                if (productId == 0)
                    throw new ArgumentException();
            }
            catch (Exception)
            {
                PricingInformation.SynchMessage = Resources.ErrorMessages_ProductNotFound;
                return PricingInformation;
            }

            DataSets.Product product = new DataSets.Product();
            using (OleDbConnection connection = new OleDbConnection(config.ConnectionString))
            {
                DataSets.ProductTableAdapters.ProductsTableAdapter tableAdapter;
                tableAdapter = new DataSets.ProductTableAdapters.ProductsTableAdapter();
                tableAdapter.Connection = connection;
                recordCount = tableAdapter.FillBy(product.Products, productId);
            }
            if (recordCount == 0)
            {
                PricingInformation.SynchMessage = Resources.ErrorMessages_ProductNotFound;
                return PricingInformation;
            }

            DataSets.Product.ProductsRow row = product.Products[0];

            decimal listprice = row.IsUnitPriceNull() ? (decimal)0 : row.UnitPrice;

            PricingInformation.ListPrice = XmlConvert.ToString(listprice);

            PricingInformation.DiscountRate = 0;
            PricingInformation.Discount = 0;
            PricingInformation.DiscountSum = 0;

            if (PricingInformation.Quantity >= 10)
            {
                PricingInformation.DiscountRate = new decimal(10);
                PricingInformation.Discount = new decimal(10);
                PricingInformation.DiscountSum = listprice * new decimal(0.1);
            }

            decimal quotedPrice = listprice - PricingInformation.DiscountSum;

            PricingInformation.QuotedPrice = XmlConvert.ToString(quotedPrice);
            PricingInformation.QuotedPriceTotal = XmlConvert.ToString(PricingInformation.Quantity * quotedPrice);
            PricingInformation.Tax = 0;
            PricingInformation.TaxRate = 0;

            return PricingInformation;
        }