Beispiel #1
0
        private void btnAddData_Click(object sender, EventArgs e)
        {
            loaiSanPham.TenLoaiSP = txtProductName.Text;
            string err = "";

            if (isAdd == true)
            {
                bool result = categoryBusiness.AddCategory(loaiSanPham, ref err);
                if (result)
                {
                    MessageBox.Show("Added successfully!", "Add a new category");
                }
                else
                {
                    MessageBox.Show("Failed to add a new category! Error" + err, "Add a new category");
                }
            }
            else
            {
                bool result = categoryBusiness.EditCategory(loaiSanPham, ref err);
                if (result)
                {
                    MessageBox.Show("Edited successfully!", "Edit a category");
                }
                else
                {
                    MessageBox.Show("Failed to edit a category!Error:" + err, "Edit a category");
                }
            }
            loadData();
        }
        public ActionResult SaveCategory(Category viewmodel)
        {
            if (ModelState.IsValid)
            {
                if (viewmodel.Id == 0)
                {
                    result       = CategoryBusiness.AddCategory(viewmodel, out categoryId);
                    viewmodel.Id = categoryId;
                    if (result)
                    {
                        return(Json(new { data = viewmodel, success = result + "Add", JsonRequestBehavior.AllowGet }));
                    }
                }
                else if (viewmodel.Id != 0)
                {
                    result = CategoryBusiness.EditCategory(viewmodel);
                    if (result)
                    {
                        return(Json(new { data = viewmodel, success = result + "Edit", JsonRequestBehavior.AllowGet }));
                    }
                }
            }

            return(Json(new { success = result }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult AddCategory(CategoryViewModel model)
        {
            // if (ModelState.IsValid)
            {
                _Category.AddCategory(model);
                return(RedirectToAction("Index"));
            }

            //  return View();
        }
Beispiel #4
0
        private void buttoncatadd_Click(object sender, EventArgs e)
        {
            Category category = new Category();

            category.Name = textBoxcatname.Text;
            CategoryBusiness.AddCategory(category);

            ShowCategories();
            ShowCategoriesComboBox();
        }
 protected void Button1_Click(object sender, EventArgs e)
 {
     if (!String.IsNullOrEmpty(editID))
     {
         categoryBusiness.UpdateCategory(long.Parse(editID), txtTitle.Text);
     }
     else
     {
         categoryBusiness.AddCategory(txtTitle.Text);
     }
     Response.Redirect("Categorys.aspx");
 }
Beispiel #6
0
        // Create Category
        public async Task <ActionResult> CreateCategory(Category category)
        {
            ModelState.Remove("CreatedBy");
            ModelState.Remove("ModifiedBy");
            ModelState.Remove("CreatedDate");
            ModelState.Remove("ModifiedDate");

            var viewmodel = new CategoryViewModel();

            if (ModelState.IsValid)
            {
                if (category.Id <= 0)
                {
                    viewmodel = await CategoryBusiness.AddCategory(category);

                    if (viewmodel.CategoryId != 0)
                    {
                        success = true;
                    }
                    else
                    {
                        success = false;
                    }
                    return(Json(new { success = success, data = viewmodel, IsEdit = false, JsonRequestBehavior.AllowGet }));
                }
                else
                {
                    viewmodel = await CategoryBusiness.EditCategory(category);

                    if (viewmodel.CategoryId != 0)
                    {
                        success = true;
                    }
                    else
                    {
                        success = false;
                    }
                    return(Json(new { success = success, data = viewmodel, IsEdit = true, JsonRequestBehavior.AllowGet }));
                }
            }

            return(RedirectToAction("AddCategory"));
        }
Beispiel #7
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            var  index = dgvListCategory.CurrentCell.RowIndex;
            bool trung = false;

            if (txtName.Text == "")
            {
                MessageBox.Show("Tên Danh Mục Không Được Trống!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            #region Lưu khi Thêm
            else if (g == 1)
            {
                CategoryDTO category = new CategoryDTO();
                category.Name = txtName.Text.ToString().Trim();
                trung         = _CategoryBusiness.ExisCattName(txtName.Text.ToString(), -1);
                if (trung == false)
                {
                    MessageBox.Show("Trùng Tên Danh Mục! Vui Lòng Chọn Tên Khác", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    if (_CategoryBusiness.AddCategory(category))
                    {
                        MessageBox.Show("Thêm mới thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        LoadData();
                    }
                    else
                    {
                        MessageBox.Show("Thêm mới không thành công!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
            }
            #endregion

            #region Lưu khi sửa
            else if (g == 2)
            {
                CategoryDTO category = ListCategory.ElementAtOrDefault(index);
                category.Name = txtName.Text.ToString().Trim();
                //category.Id = int.Parse(dgvListCategory.Rows[index].Cells[0].Value.ToString());
                trung = _CategoryBusiness.ExisCattName(txtName.Text.ToString(), int.Parse(dgvListCategory.Rows[index].Cells[0].Value.ToString()));
                if (trung == false)
                {
                    MessageBox.Show("Trùng Tên Danh Mục! Vui Lòng Chọn Tên Khác", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    if (_CategoryBusiness.EditCategory(category))
                    {
                        MessageBox.Show("Sửa thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        LoadData();
                    }
                    else
                    {
                        MessageBox.Show("Sửa không thành công!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
            }
            #endregion

            DieuKhien((int)DIEUKHIEN.MO);
            g = 0;
        }
Beispiel #8
0
 /// <summary>
 /// Método que agrega en registro de la entidad
 /// </summary>
 public async Task AddCategory(Category category)
 {
     categoryBusiness.AddCategory(category);
 }