【发布时间】:2018-10-28 08:33:33
【问题描述】:
我有一个非常有趣的案例:在我的购物过程中的两个视图中,我有一个部分视图用于显示订单的总价格和交货价格。
此部分视图由ShowCartDiscountsPrices 操作呈现。最后,我必须使用实体框架在数据库MinDeliveryPrice、MinDeliveryPriceDDS、DeliveryPrice、DeliveryPriceDDS 中插入。
奇怪的问题是,上周在我的 SQL Server 数据库中的两个案例中,我只有 DeliveryPrice 的值,而其他三列在我的 SQL Server 数据库中为空。
当我查看问题并使用相同的文章下订单时,例如一小时后,一切都很好,四列已填充,在此期间没有人对数据库进行任何更改。
我想知道可能是什么问题我可以编写一些脚本来记录是否在 SQL Server 或 IIS 中发生某种错误?
public ActionResult ShowCartDiscountsPrices(OrderDiscountPriceModel model, bool? ischange, int? deliverypreference)
{
var cart = ShoppingCart.GetCart(WebsiteContext.CurrentUser != null ? (int?)WebsiteContext.CurrentUser.UserID : null);
decimal mindeliveryprice = 0;
decimal mindeliverypricedds = 0;
if (deliverypreference != null || Session["DeliveryPreference"] != null)
{
var parsedelprice = deliverypreference.HasValue ? deliverypreference.Value == 1 ? Decimal.TryParse(Settings.GetSettingByName("Eshop_SpeedyMinDeliveryPrice"), out mindeliveryprice) :Decimal.TryParse(Settings.GetSettingByName("Eshop_HomeMinDeliveryPrice"), out mindeliveryprice) : Decimal.TryParse(Session["MinDeliveryPrice"].ToString(), out mindeliveryprice );
var parsedelpricedds = deliverypreference.HasValue ? deliverypreference.Value == 1 ? Decimal.TryParse(Settings.GetSettingByName("Eshop_SpeedyMinDeliveryPriceDDS"), out mindeliverypricedds) : Decimal.TryParse(Settings.GetSettingByName("Eshop_HomeMinDeliveryPriceDDS"), out mindeliverypricedds) : Decimal.TryParse(Session["MinDeliveryPriceDDS"].ToString(), out mindeliverypricedds );
decimal deliveryprice;
decimal deliverypricedds;
ShoppingCartHelper.CalculateArticlesDeliveryPrice(mindeliveryprice, mindeliverypricedds, cart.ComputeTotalTransport(), cart.ComputeTotalTransportDDS(), out deliveryprice, out deliverypricedds);
model.DeliveryPrice = deliveryprice;
model.DeliveryPriceDDS = deliverypricedds;
model.DeliveryPreference = deliverypreference.HasValue ? deliverypreference.Value : (int)Session["DeliveryPreference"];
model.MinDeliveryPrice = mindeliveryprice;
model.MinDeliveryPriceDDS = mindeliverypricedds;
model.FinalSum += deliverypricedds;
}
else
{
if (isFromLastStep != null && bool.Parse(isFromLastStep.ToString()) == true)
ViewBag.IncludeDelivery = true;
}
if (deliverypreference != null)
{
Session["DeliveryPreference"] = deliverypreference;
Session["MinDeliveryPrice"] = mindeliveryprice;
Session["MinDeliveryPriceDDS"] = mindeliverypricedds;
}
ViewData.TemplateInfo.HtmlFieldPrefix = "OrderDiscoutPrice";
return PartialView("_CartDiscountsPrices", model);
}
这是我的辅助函数,它们仅遍历包含文章的集合并计算总交付价格。
public decimal ComputeTotalTransport()
{
decimal totalarticletransport = 0;
decimal articletransport;
foreach (var article in lineCollection)
{
if (decimal.TryParse(article.Article.Transport.ToString(), out articletransport))
{
totalarticletransport += article.Article.Quantity * articletransport;
articletransport = 0;
}
}
return totalarticletransport;
}
public decimal ComputeTotalTransportDDS()
{
decimal totaltransportdds = 0;
decimal articletransportdds;
foreach (var article in lineCollection)
{
if (decimal.TryParse(article.Article.TransportDDS.ToString(), out articletransportdds))
{
totaltransportdds += article.Article.Quantity * articletransportdds;
articletransportdds = 0;
}
}
return totaltransportdds;
}
【问题讨论】:
-
好的,所以您的示例需要做一些工作。您显示了两个“计算...”函数,但这些函数似乎并未从您显示的操作代码中调用。您也不会在此处显示“模型”被实例化的任何代码,或者在任何将更改提交到您的数据库的地方。
-
同意 - 如果可以,请显示 (a) 推送到数据库的模型和 (b) 实际插入数据库的代码。我想知道这是否与模型结构和 ORM 有关系