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>
 /// Create a new CorrectionEntry object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="count">Initial value of the Count property.</param>
 /// <param name="deliveryEntityId">Initial value of the DeliveryEntityId property.</param>
 /// <param name="correctionId">Initial value of the CorrectionId property.</param>
 /// <param name="cost">Initial value of the Cost property.</param>
 public static CorrectionEntry CreateCorrectionEntry(global::System.Int32 id, global::System.Int32 count, global::System.Int32 deliveryEntityId, global::System.Int32 correctionId, global::System.Decimal cost)
 {
     CorrectionEntry correctionEntry = new CorrectionEntry();
     correctionEntry.Id = id;
     correctionEntry.Count = count;
     correctionEntry.DeliveryEntityId = deliveryEntityId;
     correctionEntry.CorrectionId = correctionId;
     correctionEntry.Cost = cost;
     return correctionEntry;
 }