/// <summary>
 /// Create a new Correction object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="date">Initial value of the Date property.</param>
 /// <param name="correctionTypeId">Initial value of the CorrectionTypeId property.</param>
 public static Correction CreateCorrection(global::System.Int32 id, global::System.DateTime date, global::System.Int32 correctionTypeId)
 {
     Correction correction = new Correction();
     correction.Id = id;
     correction.Date = date;
     correction.CorrectionTypeId = correctionTypeId;
     return correction;
 }
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            var container = new DeliveryManagerModelContainer();

            Correction correction;
            var correctionIDParam = Request.QueryString[CorrectionConstants.IDParamName];
             if (correctionIDParam != null)
             {
                 int correctionID = Int32.Parse(correctionIDParam);
                 correction = container.Corrections.Single(d => d.Id == correctionID);
             }
             else
             {
                 correction = new Correction();
                 container.Corrections.AddObject(correction);
             }
             correction.Date = Calendar.SelectedDate;
             correction.CorrectionTypeId = Int32.Parse(CorrectionTypeList.SelectedValue);

             foreach (GridViewRow row in EntriesGridView.Rows)
             {
                 var hdnField = row.Cells[0].Controls.OfType<HiddenField>().Single();
                 var depotEntryId = Int32.Parse(hdnField.Value);
                 var depotEntry = container.Entries.Single(de => de.Id == depotEntryId) as DepotEntry;
                 var correctionEntry = correction.CorrectionEntries.SingleOrDefault(oe => oe.DepotEntry.Id == depotEntryId);

                 var chkBox = row.Cells[0].Controls.OfType<CheckBox>().Single();
                 if (chkBox.Checked)
                 {
                     var txtBox = row.Cells[0].Controls.OfType<TextBox>().Single();
                     int count;
                     if (!Int32.TryParse(txtBox.Text, out count) || count < 1)
                         count = 1;

                     if (correctionEntry == null)
                     {
                         correctionEntry = new CorrectionEntry
                         {
                             DepotEntry = depotEntry,
                             DeliveryEntityId = depotEntry.DeliveryEntityId,
                             Cost = depotEntry.DeliveryEntity.Cost
                         };
                         correction.CorrectionEntries.Add(correctionEntry);
                     }
                     correctionEntry.Count = count;
                 }
                 else
                 {
                     if (correctionEntry != null)
                     {
                         // return entities back
                         depotEntry.Count += correctionEntry.Count;
                         container.Entries.DeleteObject(correctionEntry);
                     }
                 }
             }

             container.SaveChanges();

             Response.Redirect("~/Corrections/CorrectionsList.aspx", true);
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Corrections EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCorrections(Correction correction)
 {
     base.AddObject("Corrections", correction);
 }