title: Values not inserted in SQL Server database
body: <p>I have a really interesting case: in two views during my shopping process I have a partial view for displaying the total price of the order and delivery prices. </p>
  
  <p>This partial view is rendered by the <code>ShowCartDiscountsPrices</code> action. At the end I have to insert using Entity Framework in the database <code>MinDeliveryPrice</code>, <code>MinDeliveryPriceDDS</code>, <code>DeliveryPrice</code>, <code>DeliveryPriceDDS</code>. </p>
  
  <p>The strange problem is that in two cases last week in my SQL Server database, I have value only for <code>DeliveryPrice</code> AND SOMEHOW THE OTHER THREE COLUMNS ARE null in my SQL Server database. </p>
  
  <p>And when I look at the problem and make an order with the same articles for example an hour after that everything is fine and the four columns are populated and during this period of time nobody has made any changes in the database. </p>
  
  <p>I am wondering what can be the problem can I write some script for logging to see if some kind of mistakes occurs either in SQL Server or IIS maybe?</p>
  
  <pre><code>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 &amp;&amp; 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);
  }
  </code></pre>
  
  <p>And here are my helper functions that only iterate through a collection with articles and calculate the Total Delivery Prices.</p>
  
  <pre><code> 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;
          }
  </code></pre>