コード例 #1
0
    private void check_price_deviation(SupplierProduct sp)
    {
        decimal priceThrshold, deviationPercentage;

        decimal.TryParse(Settings.GetSetting(Settings.Keys.DEVIATION_LOWEST_THRESHOLD), out priceThrshold);
        decimal.TryParse(Settings.GetSetting(Settings.Keys.DEVIATION_PERCENTAGE), out deviationPercentage);
        var  product    = Product.FetchByID(sp.ProductId);
        var  deviation  = PriceDeviation.FetchByID(sp.SupplierId, sp.ProductId);
        bool isDeviated = product.RecomendedPrice > priceThrshold && sp.Price < product.RecomendedPrice * (100 - deviationPercentage) / 100;

        if (isDeviated)
        {
            var supplier = AppSupplier.FetchByID(sp.SupplierId);
            deviation                     = deviation ?? new PriceDeviation();
            deviation.ProductId           = sp.ProductId;
            deviation.ProductName         = product.ProductName;
            deviation.RecommendedPrice    = product.RecomendedPrice;
            deviation.SupplierId          = supplier.SupplierId;
            deviation.SupplierName        = supplier.BusinessName;
            deviation.ActualPrice         = sp.Price;
            deviation.DeviationPercentage = 100 - 100 * sp.Price / product.RecomendedPrice;
            deviation.IsApproved          = false;
            deviation.TimeOfApproval      = DateTime.MinValue;
            deviation.Save();
        }
        else if (deviation != null)
        {
            PriceDeviation.Delete(sp.SupplierId, sp.ProductId);
        }
    }
コード例 #2
0
        protected void approveDeviation(object sender, EventArgs e)
        {
            LinkButton btn = (LinkButton)(sender);
            var        arguments = btn.CommandArgument.Split(',');
            int        supplierId, productId;

            Int32.TryParse(arguments[0], out supplierId);
            Int32.TryParse(arguments[1], out productId);
            var deviation = PriceDeviation.FetchByID(supplierId, productId);

            deviation.IsApproved     = true;
            deviation.TimeOfApproval = DateTime.Now;
            deviation.Save();
            Master.PageTitleHtml = string.Format(SuppliersStrings.GetText(@"DeleteSupplierPageTitle"), SupplierName);
        }