/// <summary>
 /// Create a new CD object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="cost">Initial value of the Cost property.</param>
 /// <param name="price">Initial value of the Price property.</param>
 public static CD CreateCD(global::System.Int32 id, global::System.String name, global::System.Decimal cost, global::System.Decimal price)
 {
     CD cD = new CD();
     cD.Id = id;
     cD.Name = name;
     cD.Cost = cost;
     cD.Price = price;
     return cD;
 }
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            Decimal price;
            if (Decimal.TryParse(PriceTextBox.Text, out price))
            {
                var container = new DeliveryManagerModelContainer();

                DeliveryEntity deliveryEntity;
                var deliveryEntityIDParam = Request.QueryString[DeliveryEntityConstants.IDParamName];
                if (deliveryEntityIDParam != null)
                {
                    int deliveryEntityID = Int32.Parse(deliveryEntityIDParam);
                    deliveryEntity = container.DeliveryEntities.Single(de => de.Id == deliveryEntityID);
                    if (Page is AddEditBookPage)
                        (deliveryEntity as Book).ISBN = (Page as AddEditBookPage).ISBN;
                    else// if (Page is AddEditCDPage)
                        (deliveryEntity as CD).Format = (Page as AddEditCDPage).Format;
                }
                else
                {
                    if (Page is AddEditBookPage)
                        deliveryEntity = new Book { ISBN = (Page as AddEditBookPage).ISBN };
                    else// if (Page is AddEditCDPage)
                        deliveryEntity = new CD { Format = (Page as AddEditCDPage).Format };

                    container.DeliveryEntities.AddObject(deliveryEntity);
                }
                deliveryEntity.Name = NameTextBox.Text.Trim();

                deliveryEntity.Price = price;
                deliveryEntity.Cost = Decimal.Multiply(deliveryEntity.Price, 0.7m);

                container.SaveChanges();

                Response.Redirect("~/DeliveryEntities/DeliveryEntitiesList.aspx", true);
            }
            else
            {
                Label.ForeColor = Color.Red;
                Label.Text = "Check Price value";
            }
        }