/// <summary>
 /// Create a new Disbursement object.
 /// </summary>
 /// <param name="disbursementID">Initial value of the DisbursementID property.</param>
 /// <param name="disburse_Date">Initial value of the Disburse_Date property.</param>
 /// <param name="status">Initial value of the Status property.</param>
 /// <param name="department_ReqID">Initial value of the Department_ReqID property.</param>
 /// <param name="department">Initial value of the Department property.</param>
 public static Disbursement CreateDisbursement(global::System.Int32 disbursementID, global::System.DateTime disburse_Date, global::System.String status, global::System.Int32 department_ReqID, global::System.String department)
 {
     Disbursement disbursement = new Disbursement();
     disbursement.DisbursementID = disbursementID;
     disbursement.Disburse_Date = disburse_Date;
     disbursement.Status = status;
     disbursement.Department_ReqID = department_ReqID;
     disbursement.Department = department;
     return disbursement;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Disbursements EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToDisbursements(Disbursement disbursement)
 {
     base.AddObject("Disbursements", disbursement);
 }
        public void Disburse()
        {
            bool flag = false;

            using (TransactionScope trans = new TransactionScope())
            {

                int id;
                List<int> disb_id = new List<int>();
                try
                {
                    var x = (from m in cntxt.DeptRequisitions where m.Status_Check == "current" select m).AsEnumerable<DeptRequisition>();

                    foreach (var d in x)
                    {
                        disb_id.Add(d.Dept_ReqID);
                        var p = (from m in cntxt.Departments
                                 where m.Department_Code == d.Department_Code
                                 select m).First<Department>();

                        Disbursement db = new Disbursement
                        {
                            Disburse_Date = DateTime.Now,
                            Status = "current",
                            Department_ReqID = d.Dept_ReqID,
                            Department = p.Department_Name,
                            Dispatch_Status = "pending"
                        };

                        cntxt.Disbursements.AddObject(db);
                        cntxt.SaveChanges();
                        id = db.DisbursementID;
                        var s = from m in cntxt.DepartmentViews
                                where m.Department_Code == p.Department_Code
                                select m;
                        foreach (var item in s)
                        {
                            DisbursementDetail dbd = new DisbursementDetail
                            {
                                DisbursementID = id,
                                Quantity = Convert.ToInt32(item.Requested_Quantity),
                                Item_Code = item.Item_Code,
                                Outstanding_Type = "pending",
                                Alloted = 0
                            };

                            cntxt.DisbursementDetails.AddObject(dbd);
                            cntxt.SaveChanges();
                        }
                    }

                    trans.Complete();
                    flag = true;
                }

                catch (TransactionException e)
                {
                    e.Message.ToString();
                }
            }
            if (flag)
            {
                cntxt.AcceptAllChanges();
            }
            else
            {
                cntxt.Dispose();
            }
        }