As my previous post a while ago mentioned, I am converting from SubSonic and have thus far been happy with the decision. However, I'm running into an issue and really need some assistance. I'm using the Custom HttpModule as demonstrated in your docs
I have a class called AMSession which is basically like a session helper. One method is called CurrentOrder which basically checks the session for an OrderID and, if one exists, it returns the Order object from the database. This way, I don't have to create a new Order object every time I need to retrieve/set properties.
Here's that bit of code:
var ctx = Modules.OpenAccessContextModule.GetContext();
Session[Keys.CurrentOrder] = ctx.Orders.First(o => o.OrderID == CurrentOrderID);
Now, I have a page called ViewCart.aspx. When the cart ListView is binded, I want to recalculate the SubTotal, Shipping, and GrandTotal. For that, I have this bit of code:
AMSession.CurrentOrder.Subtotal = AMSession.CurrentOrder.OrderProducts.Sum(op => (op.UnitPrice * op.Quantity));
AMSession.CurrentOrder.Shipping = OrderHelper.CalculateOrderShippingTotal(AMSession.CurrentOrder.OrderProducts);
AMSession.CurrentOrder.GrandTotal = AMSession.CurrentOrder.Subtotal + AMSession.CurrentOrder.Shipping;
However, this code doesn't actually save the order.
When I change the code to replace all the AMSession.CurrentOrder with an Order object created on that page, it saves just fine.
var CartOrder = _ctx.Orders.First(o => o.OrderID == AMSession.CurrentOrderID);
CartOrder.Subtotal = CartOrder.OrderProducts.Sum(op => (op.UnitPrice * op.Quantity));
CartOrder.Shipping = OrderHelper.CalculateOrderShippingTotal(CartOrder.OrderProducts);
CartOrder.GrandTotal = CartOrder.Subtotal + CartOrder.Shipping;
I'm open to suggestions on how I can solve this issue. If it means that I simply can't use AMSession.CurrentOrder to save information, then that's just something I'll need to do. However, I just didn't want to change my entire application if there's a better way to handle this scenario as I do something very similar in another project.
I sincerely appreciate your time and energy on this.