protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                using(CatalogManager cm = new CatalogManager())
                {
                    this.StationeriesGridView.DataSource = cm.GetAllStationeries();
                    this.StationeriesGridView.DataBind();
                }

                Stationery stationery = new Stationery();
                StationeryPrice stationeryPrice = new StationeryPrice();
            }
        }
 public Stationery CreateStationery(Stationery stationery)
 {
     try
     {
         using (TransactionScope ts = new TransactionScope())
         {
             context.Stationeries.AddObject(stationery);
             context.SaveChanges();
             ts.Complete();
             return stationery;
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            CatalogManager Manager = new CatalogManager();

            Stationery stationery = new Stationery();
            StationeryPrice[] stationeryPrice = new StationeryPrice[3];

            stationery.ItemCode = NameTextBox.Text;
            stationery.Description = DescriptionTextBox.Text;
            stationery.UnitOfMeasure = UOMTextBox.Text;
            stationery.CategoryID = Convert.ToInt32(CategoryDDL.SelectedValue);
            stationery.LocationID = Convert.ToInt32(LocationDDL.SelectedValue);
            stationery.ReorderLevel = Convert.ToInt32(ReorderLevelTextBox.Text);
            stationery.ReorderQuantity = Convert.ToInt32(ReorderQtyTextBox.Text);
            stationery.CreatedBy = Utilities.Membership.GetCurrentLoggedInUser().UserID;
            stationery.ModifiedBy = Utilities.Membership.GetCurrentLoggedInUser().UserID;
            stationery.DateCreated = DateTime.Now;
            stationery.DateModified = DateTime.Now;
            stationery.IsApproved = false;

            stationeryPrice[0] = new StationeryPrice();
            stationeryPrice[0].SupplierID = Convert.ToInt32(Supplier1DDL.SelectedValue);
            stationeryPrice[0].Price = Convert.ToInt32(Price1TextBox.Text);
            stationeryPrice[1] = new StationeryPrice();
            stationeryPrice[1].SupplierID = Convert.ToInt32(Supplier2DDL.SelectedValue);
            stationeryPrice[1].Price = Convert.ToInt32(Price2TextBox.Text);
            stationeryPrice[2] = new StationeryPrice();
            stationeryPrice[2].SupplierID = Convert.ToInt32(Supplier3DDL.SelectedValue);
            stationeryPrice[2].Price = Convert.ToInt32(Price3TextBox.Text);

            try
            {
                Stationery temp = Manager.CreateStationery(stationery);

                foreach (StationeryPrice st in stationeryPrice)
                {
                    st.StationeryID = temp.StationeryID;
                    Manager.CreateStationeryPrice(st);
                }
            }
            catch (Exception)
            {
                ErrorLabel.Text = "Create Stationery Failed";
            }
        }
        public Stationery UpdateStationery(Stationery stationery)
        {
            try
            {
                Stationery tempStationery = (from s in context.Stationeries
                                             where s.StationeryID == stationery.StationeryID
                                             select s).FirstOrDefault<Stationery>();

                tempStationery.CategoryID = stationery.CategoryID;
                tempStationery.LocationID = stationery.LocationID;
                tempStationery.ItemCode = stationery.ItemCode;
                tempStationery.Description = stationery.Description;
                tempStationery.ReorderLevel = stationery.ReorderLevel;
                tempStationery.ReorderQuantity = stationery.ReorderQuantity;
                tempStationery.DateModified = stationery.DateModified;
                tempStationery.ModifiedByUser = stationery.ModifiedByUser;
                tempStationery.UnitOfMeasure = stationery.UnitOfMeasure;
                tempStationery.IsApproved = stationery.IsApproved;
                tempStationery.QuantityInHand = stationery.QuantityInHand;

                using (TransactionScope ts = new TransactionScope())
                {
                    context.SaveChanges();
                    ts.Complete();
                    return tempStationery;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void DeleteStationery(Stationery stationery)
        {
            try
            {
                Stationery persistedStationery = (from s in context.Stationeries
                                                  where s.StationeryID == stationery.StationeryID
                                                  select s).First<Stationery>();

                List<StationeryPrice> spList = GetAllStationeryPrices().Where(x => x.StationeryID == persistedStationery.StationeryID).ToList<StationeryPrice>();
                using (TransactionScope ts = new TransactionScope())
                {
                    foreach (StationeryPrice temp in spList)
                    {
                        context.StationeryPrices.DeleteObject(temp);
                    }
                    context.Stationeries.DeleteObject(persistedStationery);
                    context.SaveChanges();
                    ts.Complete();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Stationeries EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToStationeries(Stationery stationery)
 {
     base.AddObject("Stationeries", stationery);
 }
 /// <summary>
 /// Create a new Stationery object.
 /// </summary>
 /// <param name="stationeryID">Initial value of the StationeryID property.</param>
 /// <param name="categoryID">Initial value of the CategoryID property.</param>
 /// <param name="locationID">Initial value of the LocationID property.</param>
 /// <param name="itemCode">Initial value of the ItemCode property.</param>
 /// <param name="description">Initial value of the Description property.</param>
 /// <param name="reorderLevel">Initial value of the ReorderLevel property.</param>
 /// <param name="reorderQuantity">Initial value of the ReorderQuantity property.</param>
 /// <param name="quantityInHand">Initial value of the QuantityInHand property.</param>
 /// <param name="dateCreated">Initial value of the DateCreated property.</param>
 /// <param name="dateModified">Initial value of the DateModified property.</param>
 /// <param name="createdBy">Initial value of the CreatedBy property.</param>
 /// <param name="modifiedBy">Initial value of the ModifiedBy property.</param>
 /// <param name="isApproved">Initial value of the IsApproved property.</param>
 /// <param name="unitOfMeasure">Initial value of the UnitOfMeasure property.</param>
 public static Stationery CreateStationery(global::System.Int32 stationeryID, global::System.Int32 categoryID, global::System.Int32 locationID, global::System.String itemCode, global::System.String description, global::System.Int32 reorderLevel, global::System.Int32 reorderQuantity, global::System.Int32 quantityInHand, global::System.DateTime dateCreated, global::System.DateTime dateModified, global::System.Int32 createdBy, global::System.Int32 modifiedBy, global::System.Boolean isApproved, global::System.String unitOfMeasure)
 {
     Stationery stationery = new Stationery();
     stationery.StationeryID = stationeryID;
     stationery.CategoryID = categoryID;
     stationery.LocationID = locationID;
     stationery.ItemCode = itemCode;
     stationery.Description = description;
     stationery.ReorderLevel = reorderLevel;
     stationery.ReorderQuantity = reorderQuantity;
     stationery.QuantityInHand = quantityInHand;
     stationery.DateCreated = dateCreated;
     stationery.DateModified = dateModified;
     stationery.CreatedBy = createdBy;
     stationery.ModifiedBy = modifiedBy;
     stationery.IsApproved = isApproved;
     stationery.UnitOfMeasure = unitOfMeasure;
     return stationery;
 }
 public Stationery UpdateStationery(Stationery stationery)
 {
     try
     {
         if (stationery != null)
         {
             stationery.DateModified = DateTime.Now;
             catalogDAO.UpdateStationery(stationery);
         }
     }
     catch (Exception)
     {
         throw new Exceptions.UserException("Catalog stationery updating failed.");
     }
     return stationery;
 }
 public void DeleteStationery(Stationery stationery)
 {
     try
     {
         if (stationery != null)
         {
             catalogDAO.DeleteStationery(stationery);
         }
     }
     catch (Exception)
     {
         //throw new Exceptions.UserException("Catalog stationery deletion failed.");
     }
 }
 public Stationery CreateStationery(Stationery stationery)
 {
     try
     {
         if (stationery != null)
         {
             stationery.DateCreated = DateTime.Now;
             catalogDAO.CreateStationery(stationery);
         }
     }
     catch (Exception)
     {
         throw new Exceptions.UserException("Catalog stationery creation failed.");
     }
     return stationery;
 }