コード例 #1
0
    //ADD or UPDATE category
    protected void lnkaddTest_Click(object sender, EventArgs e)
    {
        try
        {
            string category = txtCategory.Text.Trim();
            if (lnkaddTest.Text == "Update Category") // Update Category
            {
                if (Checks.Empty(category))
                {
                    lblmsg.Text = "*Category Name is Required!!";
                }
                else
                {
                    CategoryInfoData data = new CategoryInfoData();
                    data.CategoryName = category;
                    data.CategoryId   = int.Parse(hfCategoryId.Value);
                    int result = new CategoryInfoAction().UpdateCategory(data); //method caling to update news
                    if (result > 0)
                    {
                        ViewCategory();
                        txtCategory.Text = "";
                    }
                }
            }
            else
            {
                //Add category
                if (Checks.Empty(category))
                {
                    lblmsg.Text = "*Category Name is Required!!";
                }
                else
                {
                    CategoryInfoData data = new CategoryInfoData();
                    data.CategoryName = category;

                    int ans = new CategoryInfoAction().AddCategory(data); //method calling to submit new News
                    if (ans > 0)
                    {
                        txtCategory.Text = "";
                        ViewCategory();
                        lblmsg.Text = "*Category is successfully Added!";
                    }
                }
            }
        }
        catch (Exception ex)
        {
            if (ex.Message.Contains("UNIQUE"))
            {
                lblmsg.Text = "*This category already exists!";
            }
            else
            {
                lblmsg.Text = ex.Message;
            }
        }
    }
コード例 #2
0
        // Add new Category
        public int AddCategory(CategoryInfoData Nidata)
        {
            crazyTattoosEntities apData = new crazyTattoosEntities();
            categoryInfo         data   = new categoryInfo();

            data.CategoryName = Nidata.CategoryName;

            apData.categoryInfoes.Add(data);
            int ans = apData.SaveChanges();

            return(ans);
        }
コード例 #3
0
        //Update Category info
        public int UpdateCategory(CategoryInfoData data)
        {
            crazyTattoosEntities nidata = new crazyTattoosEntities();
            categoryInfo         ni     = new categoryInfo();

            var nsd = from p in nidata.categoryInfoes where p.CategoryId == data.CategoryId select p;

            foreach (categoryInfo nifo in nsd)
            {
                nifo.CategoryId   = data.CategoryId;
                nifo.CategoryName = data.CategoryName;
            }
            int ans = nidata.SaveChanges();

            return(ans);
        }