public Category CreateCategory(Category category)
 {
     try
     {
         if (category != null)
         {
             category.DateCreated = DateTime.Now;
             category.DateModified = DateTime.Now;
             category.IsApproved = false;
             category.ApprovedByUser = null;
             catalogDAO.CreateCategory(category);
         }
     }
     catch (Exception)
     {
         throw new Exceptions.UserException("Catalog category creation failed.");
     }
     return category;
 }
        public Category CreateCategory(Category category)
        {
            try
            {
                Category c = GetAllCategories().Where(x => x.Name.ToLower() == category.Name.ToLower()).FirstOrDefault<Category>();

                using (TransactionScope ts = new TransactionScope())
                {

                        context.AddToCategories(category);
                        context.SaveChanges();
                        ts.Complete();

                    return category;
                }
            }
            catch (Exception)
            {
                throw new CatalogException("Error Occured when creating category");
            }
        }
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            Category category = new Category();
            category.Name = NameTextBox.Text;
            category.CreatedBy = Utilities.Membership.GetCurrentLoggedInUser().UserID;
            category.ModifiedBy = Utilities.Membership.GetCurrentLoggedInUser().UserID;

            CatalogManager categoryManager = new CatalogManager();

            try
            {
                categoryManager.CreateCategory(category);
                CategoryGridView.DataBind();
            }
            catch (Exception)
            {
                ErrorLabel.Text = "Category Creation Failed";
            }
        }
        public Category UpdateCategory(Category category)
        {
            try
            {
                Category tempCategory = (from s in context.Categories
                                         where s.CategoryID == category.CategoryID
                                         select s).First<Category>();

                tempCategory.Name = category.Name;
                tempCategory.DateModified = DateTime.Now;
                tempCategory.ModifiedByUser = category.ModifiedByUser;

                using (TransactionScope ts = new TransactionScope())
                {
                context.SaveChanges();
                ts.Complete();
                return tempCategory;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void DeleteCategory(Category category)
        {
            try
            {
                Category persistedCategory = (from c in context.Categories
                                      where c.CategoryID == category.CategoryID
                                      select c).FirstOrDefault<Category>();

                using (TransactionScope ts = new TransactionScope())
                {
                    context.Categories.DeleteObject(persistedCategory);
                    context.SaveChanges();
                    ts.Complete();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// Get Requistions by category filter
        /// </summary>
        /// <param name="category">category object</param>
        /// <param name="requisitionSearchDTO">requisitionSearchDTO object</param>
        /// <returns>List of Requisitions by category</returns>
        public List<VW_RequisitionsByCategory> GetRequisitionByCategoryID(Category category, RequisitionSearchDTO requisitionSearchDTO)
        {
            try
            {
                return GetAllRequisitionByCategory()
                .Where(ri => ri.CategoryID == (category.CategoryID == 0 ? ri.CategoryID : category.CategoryID))
                 .ToList<VW_RequisitionsByCategory>();
            }
            catch (Exception)
            {

                throw;
            }
        }
 /// <summary>
 /// Get requisition List by category
 /// </summary>
 /// <param name="category">category object</param>
 /// <param name="requisitionSearchDTO">RequisitionSearchDTO object</param>
 /// <returns>List of VW_RequisitionsByCategory</returns>
 public List<VW_RequisitionsByCategory> GetRequisitionByCategory(Category category, RequisitionSearchDTO requisitionSearchDTO)
 {
     List<VW_RequisitionsByCategory> temp = requisitionDAO.GetRequisitionByCategoryID(category, requisitionSearchDTO);
     if (temp != null)
     {
         return temp;
     }
     else
     {
         ErrorMessage("Result Not Found");
         return null;
     }
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Categories EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCategories(Category category)
 {
     base.AddObject("Categories", category);
 }
 /// <summary>
 /// Create a new Category object.
 /// </summary>
 /// <param name="categoryID">Initial value of the CategoryID property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="isApproved">Initial value of the IsApproved 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>
 public static Category CreateCategory(global::System.Int32 categoryID, global::System.String name, global::System.Boolean isApproved, global::System.DateTime dateCreated, global::System.DateTime dateModified, global::System.Int32 createdBy, global::System.Int32 modifiedBy)
 {
     Category category = new Category();
     category.CategoryID = categoryID;
     category.Name = name;
     category.IsApproved = isApproved;
     category.DateCreated = dateCreated;
     category.DateModified = dateModified;
     category.CreatedBy = createdBy;
     category.ModifiedBy = modifiedBy;
     return category;
 }
 public Category UpdateCategory(Category category)
 {
     try
     {
         if (category != null)
         {
             category.DateModified = DateTime.Now;
             catalogDAO.UpdateCategory(category);
         }
     }
     catch (Exception)
     {
         throw new Exceptions.UserException("Catalog updating failed.");
     }
     return category;
 }
 public void DeleteCategory(Category category)
 {
     try
     {
         if (category != null)
         {
             catalogDAO.DeleteCategory(category);
         }
     }
     catch (Exception)
     {
         //throw new Exceptions.UserException("Catalog deletion failed.");
     }
 }