This question is locked. New answers and comments are not allowed.
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:
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:
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.
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.
Thanks,
Andrew
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:
public
static
Order CurrentOrder
{
get
{
if
(Session[Keys.CurrentOrder] ==
null
)
{
try
{
var ctx = Modules.OpenAccessContextModule.GetContext();
Session[Keys.CurrentOrder] = ctx.Orders.First(o => o.OrderID == CurrentOrderID);
}
catch
(Exception ex)
{
throw
new
CustomExceptions.InvalidOrder(ex);
}
}
return
(Order)Session[Keys.CurrentOrder];
}
}
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;
_ctx.SaveChanges();
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;
_ctx.SaveChanges();
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.
Thanks,
Andrew