public bool AddProduct(string productName, string description, string imagePath, string unitPrice, int labelID, string status, string unitInStock, string categoryID, string userID) { var newProduct = new Product(); newProduct.ProductName = productName; newProduct.Description = description; newProduct.ImagePath = imagePath; newProduct.UnitPrice = Convert.ToDouble(unitPrice); newProduct.LabelID = labelID; newProduct.Status = Convert.ToBoolean(status); newProduct.UnitInStock = Convert.ToInt16(unitInStock); newProduct.CategoryID = Convert.ToInt16(categoryID); newProduct.CreatedDate = DateTime.Now.Date; newProduct.CreatedBy = userID; newProduct.UnitsAvailable = Convert.ToInt16(unitInStock); newProduct.UnitsLock = 0; newProduct.Discount = 0; using (ProductContext _db = new ProductContext()) { // Add product to DB. _db.Products.Add(newProduct); _db.SaveChanges(); } return true; }
protected void gvProducts_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName != "Page" && e.CommandName != "Sort") { GridViewRow gvr = (GridViewRow)((Control)e.CommandSource).NamingContainer; int rowIndex = gvr.RowIndex; Product p = new Product(); p = productAction.GetProduct(int.Parse(gvProducts.Rows[rowIndex].Cells[0].Text)); if (e.CommandName == "edt") { txtEditProDescription.Text = WebUtility.HtmlDecode(p.Description); txtEditProName.Text = WebUtility.HtmlDecode(p.ProductName); txtEditProPrice.Text = ((double)p.UnitPrice).ToString("0.00"); txtEditProUnitsInStock.Text = p.UnitInStock.ToString(); lblEditProIDDisplay.Text = p.ProductID.ToString(); cbEditProStatus.Checked = p.Status; imgEditPro.Src = "~/Catalog/Images/" + p.ImagePath; lblEditProLabelDisplay.Text = p.Label.LabelName; ddEditProCategoryName.SelectedValue = p.CategoryID.ToString(); if (p.Discount == 1.0) { txtEditProDiscount.Text = "0"; } else { txtEditProDiscount.Text = (p.Discount * 100).ToString(); } ManageEditProValidation(true); ModalEditProduct.Show(); } else if (e.CommandName == "dlt") { lblDeleteProID.Text = p.ProductID.ToString(); lblDeleteProName.Text = p.ProductName; ModalDeleteProduct.Show(); } } }