private void TestMethod()
        {
            requisition.CreatedBy = 1;
            requisition.DepartmentID = 1;
            requisition.RequisitionForm = "dds/111/11";
            requisition.StatusID = 1;
            requisition.UrgencyID = 1;
            requisition.DateRequested = DateTime.Now;

            SpecialRequisitionItem splItem = new SpecialRequisitionItem()
            {
                QuantityIssued = 0,
                QuantityRequested = 10,
                Name = "test",
                Description = "desc",
                RemarkByRequester = "remarks",
                Price = 0
            };

            RequisitionItem item = new RequisitionItem()
            {
                StationeryID = 1,
                QuantityRequested = 12,
                QuantityIssued = 0,
                Price = 0
            };

            requisition.RequisitionItems.Add(item);
            requisition.SpecialRequisitionItems.Add(splItem);

            try
            {
                rDAO.CreateRequisition(requisition);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// Update the special requisitionItem
        /// </summary>
        /// <param name="requisitionItem">specialRequisitionItem object</param>
        public void UpdateSpecialRequisitionItem(SpecialRequisitionItem specialRequisitionItem)
        {
            try
            {
                var temp = (from ri in context.SpecialRequisitionItems
                            where ri.SpecialRequisitionItemsID == specialRequisitionItem.SpecialRequisitionItemsID
                            select ri).FirstOrDefault<SpecialRequisitionItem>();

                temp.SpecialStationery = specialRequisitionItem.SpecialStationery;
                temp.QuantityRequested = specialRequisitionItem.QuantityRequested;
                temp.Price = specialRequisitionItem.Price;

                context.SaveChanges();
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// Get special RequisitionItems by primary key
        /// </summary>
        /// <param name="requisitionItem">requisitionItem object</param>
        /// <returns></returns>
        public SpecialRequisitionItem GetSpecialRequisitionItemsByID(SpecialRequisitionItem specialRequisitionItem)
        {
            try
            {
                return (from ri in context.SpecialRequisitionItems
                        where ri.SpecialRequisitionItemsID == specialRequisitionItem.SpecialRequisitionItemsID
                        select ri).FirstOrDefault<SpecialRequisitionItem>();
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// Delete the special requisitionItem
        /// </summary>
        /// <param name="requisitionItem">specialRequisitionItem object</param>
        public void DeleteSpecialRequisitionItem(SpecialRequisitionItem requisitionItem)
        {
            try
            {
                var temp = (from ri in context.SpecialRequisitionItems
                            where ri.SpecialRequisitionItemsID == requisitionItem.SpecialRequisitionItemsID
                            select ri).FirstOrDefault<SpecialRequisitionItem>();

                if (temp != null)
                {
                    context.SpecialRequisitionItems.DeleteObject(temp);
                    context.SaveChanges();
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// Create a new specialRequisitionItem
        /// </summary>
        /// <param name="requisitionItem">specialRequisitionItem object</param>
        public void CreateSpecialSpecialRequisitionItem(SpecialRequisitionItem specialRequisitionItem)
        {
            try
            {
                context.AddToSpecialRequisitionItems(specialRequisitionItem);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// Update the special requisitionItem
        /// </summary>
        /// <param name="requisitionItem">specialRequisitionItem object</param>
        public void UpdateSpecialRequisitionItem(SpecialRequisitionItem specialRequisitionItem)
        {
            try
            {
                SpecialRequisitionItem temp = requisitionDAO.GetSpecialRequisitionItemsByID(specialRequisitionItem);

                if (temp != null)
                {
                    temp.SpecialStationery = specialRequisitionItem.SpecialStationery;
                    temp.QuantityRequested = specialRequisitionItem.QuantityRequested;
                    temp.Price = specialRequisitionItem.Price;
                    requisitionDAO.UpdateSpecialRequisitionItem(temp);
                }
                else
                {
                    ErrorMessage("Update special requisition failed");
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// Get special RequisitionItems by primary key
        /// </summary>
        /// <param name="requisitionItem">requisitionItem object</param>
        /// <returns></returns>
        public SpecialRequisitionItem GetSpecialRequisitionItemsByID(SpecialRequisitionItem specialRequisitionItem)
        {
            try
            {
                var temp = requisitionDAO.GetSpecialRequisitionItemsByID(specialRequisitionItem);
                if (temp != null)
                {
                    return temp;
                }
                ErrorMessage("Result Not Found");
                return null;
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// Delete the special requisitionItem
        /// </summary>
        /// <param name="requisitionItem">specialRequisitionItem object</param>
        public void DeleteSpecialRequisitionItem(SpecialRequisitionItem specialRequisitionItem)
        {
            try
            {
                SpecialRequisitionItem temp = requisitionDAO.GetSpecialRequisitionItemsByID(specialRequisitionItem);

                if (temp != null && ValidateSpecialRequisitionItem(specialRequisitionItem, RequisitionMethod.Delete))
                {
                    requisitionDAO.DeleteSpecialRequisitionItem(temp);
                }
                else
                {
                    ErrorMessage("Delete special requisition failed");
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
 /// <summary>
 /// Create a new specialRequisitionItem
 /// </summary>
 /// <param name="requisitionItem">specialRequisitionItem object</param>
 public void CreateSpecialSpecialRequisitionItem(SpecialRequisitionItem specialRequisitionItem)
 {
     try
     {
         if (specialRequisitionItem != null && ValidateSpecialRequisitionItem(specialRequisitionItem, RequisitionMethod.Create))
         {
             requisitionDAO.CreateSpecialSpecialRequisitionItem(specialRequisitionItem);
         }
         else
         {
             ErrorMessage("Create Special Requisition Item Failed");
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
        /// <summary>
        /// Validate SpecialRequisitionItem
        /// </summary>
        /// <param name="specialRequisitionItem">specialRequisitionItem object</param>
        /// <param name="requisitionMethod">enum requisitionMethod</param>
        /// <returns>boolean</returns>
        private bool ValidateSpecialRequisitionItem(SpecialRequisitionItem specialRequisitionItem, RequisitionMethod requisitionMethod)
        {
            try
            {
                if (specialRequisitionItem != null)
                {
                    if (requisitionMethod == RequisitionMethod.Create)
                    {
                        if ((specialRequisitionItem.RequisitionID != 0 || specialRequisitionItem.Requisition != null) &&
                           (specialRequisitionItem.SpecialStationeryID != 0 || specialRequisitionItem.SpecialStationeryID != null) &&
                           (specialRequisitionItem.QuantityRequested > 0))
                        {
                            return true;
                        }
                    }

                    if (requisitionMethod == RequisitionMethod.Update)
                    {
                        if ((specialRequisitionItem.RequisitionID != 0 || specialRequisitionItem.Requisition != null) &&
                         (specialRequisitionItem.SpecialStationeryID != 0 || specialRequisitionItem.SpecialStationery != null) &&
                         (specialRequisitionItem.SpecialStationery.IsApproved == false) &&
                         (specialRequisitionItem.QuantityRequested > 0))
                        {
                            return true;
                        }
                    }

                    if (requisitionMethod == RequisitionMethod.Delete)
                    {
                        if (specialRequisitionItem.SpecialRequisitionItemsID != 0)
                        {
                            return true;
                        }
                    }
                }
                return false;
            }
            catch (Exception)
            {
                throw;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //Create instance of new requisition
            Requisition r = new Requisition();

            UserDAO user = new UserDAO();
            RequisitionManager rq = new RequisitionManager();
            CatalogDAO cat = new CatalogDAO();

            //set the properties of requisition object
            r.DepartmentID = user.GetDepartmentByID(1).DepartmentID;
            r.CreatedBy = user.GetUserByID(1).UserID;
            r.StatusID = rq.GetStatusByID(new Status() { StatusID = 1}).StatusID;
            r.ApprovedBy = user.GetUserByID(2).UserID;
            r.UrgencyID = rq.GetUrgencyByID(new Urgency() { UrgencyID = 1 }).UrgencyID;
            r.RequisitionForm = "test";
            r.DateRequested = DateTime.Now;
            //r.DateApproved = DateTime.Now;

            //Create a new requisitionitem for the current requisition
            RequisitionItem rqi = new RequisitionItem()
            {
                RequisitionID = r.RequisitionID,
                StationeryID = cat.GetAllStationeries().FirstOrDefault<Stationery>().StationeryID,
                QuantityRequested = 10,
                QuantityIssued = 10,
                Price = 5

            };

            //Create a new specialrequisitionitem for the current requisition
            SpecialRequisitionItem spi = new SpecialRequisitionItem()
            {
                RequisitionID = r.RequisitionID,
                SpecialStationeryID = 1,
                QuantityRequested = 10,
                QuantityIssued = 10,
                Price = 5,
                Name = "arav",
                Description = "test"

            };

            //Add Child objects of the requisition objects
            //Add requisitionitem to requisition object
            r.RequisitionItems.Add(rqi);

            //Add specialitem to requisition object
            r.SpecialRequisitionItems.Add(spi);

            //Persist requisition to database
            //EF is very intelligent. It will also persist to requistionitem and specialrequistionitem
            rq.CreateRequisition(r);

            r = rq.GetAllRequisition().Last<Requisition>();
            r.RequisitionItems.Last<RequisitionItem>().QuantityIssued = 6;

            rq.UpdateRequisition(r);

            spi = rq.GetAllSpecialRequisitionItems(r).Last<SpecialRequisitionItem>();

            rq.DeleteSpecialRequisitionItem(spi);

            //Testing databinding after creation of requisitions
            if (!IsPostBack)
            {
                GridView1.DataSource = rq.GetAllRequisitionItems(r);
                GridView1.DataBind();

                if (r != null)
                {
                    GridView2.DataSource = rq.GetAllRequisition();
                    GridView2.DataBind();
                }
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the SpecialRequisitionItems EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToSpecialRequisitionItems(SpecialRequisitionItem specialRequisitionItem)
 {
     base.AddObject("SpecialRequisitionItems", specialRequisitionItem);
 }
 /// <summary>
 /// Create a new SpecialRequisitionItem object.
 /// </summary>
 /// <param name="specialRequisitionItemsID">Initial value of the SpecialRequisitionItemsID property.</param>
 /// <param name="requisitionID">Initial value of the RequisitionID property.</param>
 /// <param name="quantityRequested">Initial value of the QuantityRequested property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="price">Initial value of the Price property.</param>
 public static SpecialRequisitionItem CreateSpecialRequisitionItem(global::System.Int32 specialRequisitionItemsID, global::System.Int32 requisitionID, global::System.Int32 quantityRequested, global::System.String name, global::System.Decimal price)
 {
     SpecialRequisitionItem specialRequisitionItem = new SpecialRequisitionItem();
     specialRequisitionItem.SpecialRequisitionItemsID = specialRequisitionItemsID;
     specialRequisitionItem.RequisitionID = requisitionID;
     specialRequisitionItem.QuantityRequested = quantityRequested;
     specialRequisitionItem.Name = name;
     specialRequisitionItem.Price = price;
     return specialRequisitionItem;
 }
        protected void DetailsView2_ItemInserting(object sender, DetailsViewInsertEventArgs e)
        {
            SpecialRequisitionItem splItem = new SpecialRequisitionItem();

            //splItem.SpecialStationeryID = 1;
            splItem.QuantityRequested = Convert.ToInt32(((TextBox)DetailsView2.FindControl("QtyNeededTextBox")).Text);
            splItem.QuantityIssued = 0;
            splItem.Name = ((TextBox)DetailsView2.FindControl("itemNameTextBox")).Text;
            splItem.Description = ((TextBox)DetailsView2.FindControl("DescriptionTextBox")).Text;
            splItem.RemarkByRequester = ((TextBox)DetailsView2.FindControl("ReasonTextBox")).Text;
            splItem.Price = 0;

            requisition.SpecialRequisitionItems.Add(splItem);

            GridDataBind();
        }