/// <summary>
        /// Adds a new Procurement to the Procurements collection
        /// </summary>
        /// <param name="procurement">Instance of Procurement object to add to collection.</param>
        /// <returns>Newly added Procurement_ID</returns>
        public int AddProcurement(Procurement procurement)
        {
            if (procurement == null)
            {
                throw new ArgumentException("procurement was null", "procurement");
            }

            dc.Procurements.InsertOnSubmit(procurement);

            dc.SubmitChanges();

            return procurement.Procurement_ID;
        }
 partial void DeleteProcurement(Procurement instance);
 partial void UpdateProcurement(Procurement instance);
 partial void InsertProcurement(Procurement instance);
		private void detach_Procurements(Procurement entity)
		{
			this.SendPropertyChanging();
			entity.ProcurementType = null;
		}
		private void attach_Procurements(Procurement entity)
		{
			this.SendPropertyChanging();
			entity.ProcurementType = this;
		}
        /// <summary>
        /// Saves changes to the Procurement object passed
        /// </summary>
        /// <param name="procurement">Procurement object with changes to be saved</param>
        /// <returns>True if save was successful, false if it was not.</returns>
        public bool SaveProcurement(Procurement procurement)
        {
            if (procurement == null)
            {
                throw new ArgumentException("procurement was null", "procurement");
            }

            var old = GetProcurement(procurement.Procurement_ID);

            old = procurement;

            dc.SubmitChanges();

            // TODO: Compare object properties here
            return true;
        }
        private void UpdateProcurementDonors(Procurement procurement, FormCollection collection)
        {
            var donorKeys = collection.AllKeys.Where(x => x.StartsWith("DonorId")).ToList();

            var donors = new List<string>();
            donorKeys.ForEach(x => donors.AddRange(collection[x].Split(',').Where(y => !string.IsNullOrEmpty(y))));

                         //collection["DonorId"].Split(',').Where(x => !string.IsNullOrEmpty(x)).ToList());

            if (donors == null) return;

            var newDonors = donors.Where(x => procurement.ProcurementDonors.Count(y => y.Donor_ID.ToString() == x ) == 0).ToList();

            var removedDonors = procurement.ProcurementDonors.Where(x => !donors.Contains(x.Donor_ID.ToString())).ToList();

            newDonors.ForEach(id => procurement.ProcurementDonors.Add(new ProcurementDonor
                                                                          {
                                                                              Donor       = Repository.GetDonor(int.Parse(id)),
                                                                              Procurement = procurement
                                                                          }));

            removedDonors.ForEach(donor => procurement.ProcurementDonors.Remove(donor));
        }
        private void SetupProcurementDonors(Procurement procurement, FormCollection collection)
        {
            var donors = GetDonorsFromFormCollection(collection, "DonorId");

            if (donors == null) return;

            donors.ForEach(id => procurement.ProcurementDonors.Add(new ProcurementDonor
                                                                        {
                                                                            Donor = Repository.GetDonor(int.Parse(id)),
                                                                            Procurement = procurement
                                                                        }));

            // this is required until the ContactProcurement.Donor_ID column has been retired GH-15
            procurement.ContactProcurement.Donor_ID = procurement.ProcurementDonors.First().Donor_ID;
        }