private static void HandleOrderItemDigitalGood(HttpContext context, HttpResponse Response, int orderItemDigitalGoodId)
        {
            OrderItemDigitalGood oidg = OrderItemDigitalGoodDataSource.Load(orderItemDigitalGoodId);

            // VERIFY DIGITAL GOOD IS VALID
            if (oidg != null)
            {
                // VERIFY REQUESTING USER PLACED THE ORDER
                OrderItem orderItem = oidg.OrderItem;
                if (orderItem != null)
                {
                    Order order = orderItem.Order;
                    if (order != null)
                    {
                        if (AbleContext.Current.UserId == order.User.Id)
                        {
                            // VERIFY THE DOWNLOAD IS VALID
                            if (oidg.DownloadStatus == DownloadStatus.Valid)
                            {
                                DigitalGood digitalGood = oidg.DigitalGood;
                                if (digitalGood != null)
                                {
                                    // RECORD THE DOWNLOAD
                                    Uri    referrer    = context.Request.UrlReferrer;
                                    string referrerUrl = (referrer != null) ? referrer.ToString() : string.Empty;
                                    oidg.RecordDownload(context.Request.UserHostAddress, context.Request.UserAgent, referrerUrl);
                                    DownloadHelper.SendFileDataToClient(context, digitalGood);
                                }
                                else
                                {
                                    Response.Write("The requested file could not be located.");
                                }
                            }
                            else
                            {
                                Response.Write("This download is expired or invalid.");
                            }
                        }
                        else
                        {
                            Response.Write("You are not authorized to download the requested file.");
                        }
                    }
                    else
                    {
                        Response.Write("The order could not be loaded.");
                    }
                }
                else
                {
                    Response.Write("The order item could not be loaded.");
                }
            }
            else
            {
                Response.Write("The requested item does not exist.");
            }
        }
 protected void Page_Init(object sender, EventArgs e)
 {
     _OrderItemDigitalGoodId = AlwaysConvert.ToInt(Request.QueryString["OrderItemDigitalGoodId"]);
     _OrderItemDigitalGood   = OrderItemDigitalGoodDataSource.Load(_OrderItemDigitalGoodId);
     if (_OrderItemDigitalGood == null)
     {
         Response.Redirect("MyAccount.aspx");
     }
     if ((_OrderItemDigitalGood.OrderItem.Order.UserId != AbleContext.Current.UserId) && (!AbleContext.Current.User.IsInRole(Role.OrderAdminRoles)))
     {
         Response.Redirect(AbleCommerce.Code.NavigationHelper.GetStoreUrl(this.Page, "Members/MyAccount.aspx"));
     }
     //UPDATE CAPTION
     Caption.Text       = String.Format(Caption.Text, _OrderItemDigitalGood.DigitalGood.Name);
     SerialKeyData.Text = _OrderItemDigitalGood.SerialKeyData;
 }
        protected void SaveKeyButton_Click(object sender, EventArgs e)
        {
            OrderItemDigitalGood oidg = OrderItemDigitalGoodDataSource.Load(AlwaysConvert.ToInt(this.OidgId.Value));

            if (oidg != null)
            {
                // WE NEED TO UPDATE THE CURRENT LOADED LIST TO AVOID DISPLAY ISSUES
                int i = _Order.Items.IndexOf(oidg.OrderItem.Id);
                int j = _Order.Items[i].DigitalGoods.IndexOf(oidg.Id);
                OrderItemDigitalGood tempOidg = _Order.Items[i].DigitalGoods[j];
                tempOidg.SetSerialKey(SerialKeyData.Text, true);
                tempOidg.Save();
                OidgId.Value = String.Empty;
                BindDigitalGoodsGrid();
                EditKeyPopup.Hide();
            }
        }