// Get all categories of products
 public List<Category> GetCategory()
 {
     try
     {
         List<Category> ListOfCategory = new List<Category>();
         connect = new Connection().Connect;
         connect.Open();
         Command = new SqlCommand("sp_getAllCategory", connect);
         Command.CommandType = System.Data.CommandType.StoredProcedure;
         SqlDataReader dr = Command.ExecuteReader();
         while (dr.Read())
         {
             Category objCategory = new Category();
             objCategory.CategoryID = dr.GetInt32(0);
             objCategory.CategoryName = dr.GetString(1);
             ListOfCategory.Add(objCategory);
         }
         connect.Close();
         return ListOfCategory;
     }
     catch (Exception)
     {
         connect.Close();
         return null;
     }
 }
 public bool Exists(Category category)
 {
     using (var db = new DBContext())
     {
         return db.Categories.Where(x => x.Name == category.Name).Count() > 0;
     }
 }
Esempio n. 3
0
 public void CategoryInsert(Category category)
 {
     using (SqlCommand command = new SqlCommand("sp_CategoryInsert", GetConnection()))
     {
         command.CommandType = CommandType.StoredProcedure;
         command.Parameters.Add(new SqlParameter("@Category", category.CategoryName));
         command.ExecuteNonQuery();
     }
 }
Esempio n. 4
0
 public void CategoryUpdate(Category category)
 {
     using (SqlCommand command = new SqlCommand("sp_CategoryUpdate", GetConnection()))
     {
         command.CommandType = CommandType.StoredProcedure;
         command.Parameters.AddWithValue("@CategoryId", category.CategoryID);
         command.Parameters.AddWithValue("@CategoryName", category.CategoryName);
         command.ExecuteNonQuery();
     }
 }
 public void Add(Category category)
 {
     using (var db = new DBContext())
     {
         try
         {
             db.Categories.Add(category);
             db.SaveChanges();
         }
         catch (System.Data.Entity.Infrastructure.DbUpdateException)
         {
             throw new Repositories.Exceptions.CategoryAlreadyExistsException();
         }
     }
 }
Esempio n. 6
0
        protected void btnSaveConfirmed_Click(object sender, EventArgs e)
        {
            try
            {
                Entities.Category Cat = new Entities.Category();
                Cat.ID         = Convert.ToInt32(hdItemId.Value);
                Cat.Name       = txtCategoryName.Text.Trim();
                Cat.Order      = Convert.ToInt32(txtCategoryOrder.Text);
                Cat.Status     = Convert.ToInt32(ddlCategoryStatus.SelectedValue);
                Cat.CompanyId  = CPublic.GetCompanyID();
                Cat.CreatedBy  = CPublic.GetuserID();
                Cat.ModifiedBy = CPublic.GetuserID();


                OutputMessage result = null;

                if (Cat.ID == 0)
                {
                    result = Cat.Save();
                    if (result.Success)
                    {
                        Reset();
                        ClientScript.RegisterStartupScript(this.GetType(), "message", "successAlert('" + result.Message + "');", true);
                    }
                    else
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "message", "$('#add-item-portlet').addClass('in');errorAlert('" + result.Message + "')", true);
                    }
                }
                else
                {
                    result = Cat.Update();
                    if (result.Success)
                    {
                        Reset();
                        ClientScript.RegisterStartupScript(this.GetType(), "message", "successAlert('" + result.Message + "');", true);
                    }
                    else
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "message", "$('#add-item-portlet').addClass('in');errorAlert('" + result.Message + "')", true);
                    }
                }
            }
            catch (FormatException)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "message", "$('#add-item-portlet').addClass('in');errorAlert('Enter a Valid Order')", true);
            }
        }
 public void Remove(Category category)
 {
     throw new NotImplementedException();
 }
Esempio n. 8
0
 protected void lbtn_update_Click(object sender, EventArgs e)
 {
     lbl_catch.Text = "";
     if (txt_CateName.Text.Equals(""))
     {
         lbl_catch.Text += "Enter Category name";
     }
     if (lbl_catch.Text.Equals(""))
     {
         Entities.Category cate = new Entities.Category();
         cate.CategoryID = int.Parse(lbl_CateId.Text.Trim());
         cate.CategoryName = txt_CateName.Text;
         cate_bl.CategoryUpdate(cate);
         if (check_insert)
         {
             cate_bl.CategoryUpdate(cate);
         }
         else
         {
             cate_bl.CategoryInsert(cate);
         }
         pnlShow.Visible = true;
         pnlUpdate.Visible = false;
     }
 }