/// <summary>
 /// Deprecated Method for adding a new object to the RetrievalMasters EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToRetrievalMasters(RetrievalMaster retrievalMaster)
 {
     base.AddObject("RetrievalMasters", retrievalMaster);
 }
 /// <summary>
 /// Create a new RetrievalMaster object.
 /// </summary>
 /// <param name="retrievalID">Initial value of the RetrievalID property.</param>
 public static RetrievalMaster CreateRetrievalMaster(global::System.Int32 retrievalID)
 {
     RetrievalMaster retrievalMaster = new RetrievalMaster();
     retrievalMaster.RetrievalID = retrievalID;
     return retrievalMaster;
 }
        public void getRequests()
        {
            bool flag = false;
            using (TransactionScope trans = new TransactionScope())
            {
                try
                {
                    int id, ret_quant, pend_quant, avail_quant, quant;

                    RetrievalMaster rm = new RetrievalMaster
                    {
                        Retrieval_Date = DateTime.Now,
                        Status_Check = "current"

                    };
                    cntxt.RetrievalMasters.AddObject(rm);
                    cntxt.SaveChanges();
                    id = rm.RetrievalID;

                    var x = (from m in cntxt.ItemRequesteds select m).AsEnumerable<ItemRequested>();

                    foreach (var ir in x)
                    {
                        var y = cntxt.Stock_Item.FirstOrDefault(m => m.Item_Code == ir.Item_Code);
                        quant = Convert.ToInt32(ir.Requested_Quantity);
                        avail_quant = y.Quantity;

                        if (quant > avail_quant)
                        {
                            ret_quant = avail_quant;
                            pend_quant = quant - avail_quant;
                        }
                        else
                        {
                            ret_quant = quant;
                            pend_quant = 0;
                        }
                        RetrievalDetail rd = new RetrievalDetail
                        {
                            RetrievalID = id,
                            Item_Code = ir.Item_Code,
                            Quantity = quant,
                            Pending_Quantity = pend_quant,
                            Retrieved_Quantity = ret_quant
                        };
                        UpdateStock(ir.Item_Code, ret_quant);

                        cntxt.RetrievalDetails.AddObject(rd);
                        cntxt.SaveChanges();

                    }

                    trans.Complete();
                    flag = true;

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