Esempio n. 1
0
        /// <summary>
        /// Updates products
        /// </summary>
        /// <param name="product"></param>
        public void UpdateProduct(Product product)
        {
            using (SqlConnection conn = CreateConnection())
            {
                try
                {
                    SqlCommand cmd = new SqlCommand("appSchema.uspUpdateProduct", conn);
                    cmd.CommandType = CommandType.StoredProcedure;

                    conn.Open();
                    cmd.Parameters.Add("@ProductID", SqlDbType.Int, 4).Value = product.ProductID;
                    cmd.Parameters.Add("@Name", SqlDbType.NVarChar, 40).Value = product.Name;
                    cmd.Parameters.Add("@Price", SqlDbType.Decimal, 9).Value = product.Price;
                    cmd.Parameters.Add("@Description", SqlDbType.NVarChar, 200).Value = product.Description;
                    cmd.Parameters.Add("@Image", SqlDbType.NVarChar, 50).Value = product.Image;
                    cmd.Parameters.Add("@CategoryID", SqlDbType.Int, 4).Value = product.CategoryID;
                    cmd.ExecuteNonQuery();

                }
                catch
                {
                    throw new ApplicationException("An error occured in the data access layer.");
                }
            }
        }
Esempio n. 2
0
 public void ProductFormView_InsertItem(Product product)
 {
     if (ModelState.IsValid)
     {
         try
         {
             Service service = new Service();
             service.UpdateProduct(product);
             //Session["Success"] = true;
             Response.RedirectToRoute("AProducts");
         }
         catch (Exception)
         {
             ModelState.AddModelError(String.Empty, "Fel inträffade då linje skulle läggas till.");
         }
     }
 } 
Esempio n. 3
0
        public void UpdateProduct(Product product)
        {

            ICollection<ValidationResult> validationResults;
            if (!product.Validate(out validationResults))
            {
                var ex = new ValidationException("Objektet klarade inte valideringen.");
                ex.Data.Add("ValidationResults", validationResults);
                throw ex;
            }
            if (product.ProductID == 0) // New post if ID is 0!
            {
                ProductDAL.InsertProduct(product);
            }
            else
            {
                ProductDAL.UpdateProduct(product);
            }

        }
Esempio n. 4
0
 public Item(Product product, int quantity)
 {
     this.product = product;
     this.quantity = quantity;
 }