private int AddUpdateProduct() { if (product != null && product.Id > 0) { product.Id = productId; product.ProductName = txtName.Text; product.ProductCode = txtCode.Text; product.ProductTitle = txtTitle.Text; product.CategoryId = categoryIds[cmbCategory.SelectedIndex]; product.IsActive = chkActive.Checked; product.UpdatedBy = userId; return(ProductDataAccess.UpdateProduct(product)); } else { var product = new ProductDTO() { ProductName = txtName.Text, ProductCode = txtCode.Text, ProductTitle = txtTitle.Text, CategoryId = categoryIds[cmbCategory.SelectedIndex], CreatedBy = userId }; return(ProductDataAccess.AddProduct(product)); } }
public HttpResponseMessage CreateProduct([FromBody] Product product) { dataAccess.AddProduct(product); return(new HttpResponseMessage(HttpStatusCode.OK)); // Request.CreateResponse(HttpStatusCode.OK,product); }
public ActionResult CreateProduct(ProductPO productToMap) { // call the dropdown method to view the possible suppliers DropDown(); // pass the elements of the product to the map through the method call and then to the DAL _productDataAccess.AddProduct(_mapper.Map(productToMap)); // return the user to the view product page return(RedirectToAction("ViewProducts")); }
private void btnSaveProduct_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtTenHang.Text) || string.IsNullOrWhiteSpace(txtGiaNhap.Text) || string.IsNullOrWhiteSpace(txtGiaXuat.Text) || string.IsNullOrWhiteSpace(txtSoLuong.Text)) { var dialogResult = MessageBox.Show("Nhập dữ liệu là bắt buộc cho các trường: Tên hàng, Giá nhập, Giá xuất, Số lượng", "Error!", MessageBoxButtons.OK); if (dialogResult == DialogResult.OK) { return; } } int giaNhap = 0; int giaXuat = 0; int soLuong = 0; if (!int.TryParse(txtGiaNhap.Text.Trim(), out giaNhap) || !int.TryParse(txtGiaXuat.Text.Trim(), out giaXuat) || !int.TryParse(txtSoLuong.Text.Trim(), out soLuong)) { var dialogResult = MessageBox.Show("Nhập dữ liệu số cho các trường: Giá nhập, Giá xuất, Số lượng", "Error!", MessageBoxButtons.OK); if (dialogResult == DialogResult.OK) { return; } } AddEditProductModel product = new AddEditProductModel() { TenHang = txtTenHang.Text.Trim(), LoaiHangId = (int)cbbLoaiHang.SelectedValue, DonViTinhId = (int)cbbDonViTinh.SelectedValue, NhaSanXuatId = (int)cbbNhaSanXuat.SelectedValue, GiaNhap = giaNhap, GiaXuat = giaXuat, SoLuong = soLuong, KichThuocId = Convert.ToInt32(cbbKichThuoc.SelectedValue) }; try { ProductDataAccess productDataAccess = new ProductDataAccess(); productDataAccess.AddProduct(product); frmProduct.LoadInitData(); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK); } }