public Product GetProductById(int id)
 {
     Product oneProduct = new Product();
     using(ISession session = OpenSession())
     {
         oneProduct = session.Get<Product>(id);
     }
     return oneProduct;
 }
        public ActionResult Create(Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(product);
        }
 public ActionResult Create(Product newProduct)
 {
     try
     {
         objProduct.CreateProduct(newProduct);
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
 public ActionResult Delete(Product productToDelete)
 {
     try
     {
         _repository.Delete(productToDelete);
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
        public ActionResult Create(Product productToCreate)
        {
            try
            {
                _entities.AddToProductSet(productToCreate);
                _entities.SaveChanges();

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        public ActionResult Delete(Product productToDelete)
        {
            try
            {
                var originalProduct = (from p in _entities.ProductSet
                                       where p.Id == productToDelete.Id
                                       select p).FirstOrDefault();

                _entities.DeleteObject(originalProduct);
                _entities.SaveChanges();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
 public String DeleteProduct(Product product)
 {
     String result;
     using (ISession session = OpenSession())
     {
         using (ITransaction transaction = session.BeginTransaction())
         {
             try
             {
                 session.Delete(product);
                 transaction.Commit();
                 result = "Product successfully deleted!";
             }
             catch (HibernateException e)
             {
                 transaction.Rollback();
                 result = e.Message;
                 throw;
             }
         }
         return result;
     }
 }
 public ActionResult Edit(Product productToEdit)
 {
     try
     {
         var originalProduct = (from p in _entities.ProductSet
                              where p.Id == productToEdit.Id
                              select p).FirstOrDefault();
         _entities.ApplyPropertyChanges(originalProduct.EntityKey.EntitySetName, productToEdit);
         _entities.SaveChanges();
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
 public ActionResult ProductArray(Product[] products)
 {
     return RedirectToAction("Index");
 }
 public void Delete(Product productToDelete)
 {
     var originalProduct = Get(productToDelete.Id);
     _entities.DeleteObject(originalProduct);
     _entities.SaveChanges();
 }
Example #11
0
 /// <summary>
 /// Create a new Product object.
 /// </summary>
 /// <param name="productID">Initial value of the ProductID property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="productNumber">Initial value of the ProductNumber property.</param>
 /// <param name="standardCost">Initial value of the StandardCost property.</param>
 /// <param name="listPrice">Initial value of the ListPrice property.</param>
 /// <param name="sellStartDate">Initial value of the SellStartDate property.</param>
 /// <param name="rowguid">Initial value of the rowguid property.</param>
 /// <param name="modifiedDate">Initial value of the ModifiedDate property.</param>
 public static Product CreateProduct(global::System.Int32 productID, global::System.String name, global::System.String productNumber, global::System.Decimal standardCost, global::System.Decimal listPrice, global::System.DateTime sellStartDate, global::System.Guid rowguid, global::System.DateTime modifiedDate)
 {
     Product product = new Product();
     product.ProductID = productID;
     product.Name = name;
     product.ProductNumber = productNumber;
     product.StandardCost = standardCost;
     product.ListPrice = listPrice;
     product.SellStartDate = sellStartDate;
     product.rowguid = rowguid;
     product.ModifiedDate = modifiedDate;
     return product;
 }
Example #12
0
 public static Product CreateProduct(Product product)
 {
     SQLQueryCommand(String.Format("insert into [ShopDb].[dbo].[Product](Name,Price) values ('{0}','{1}')", product.Name, product.Price));
     return product;
 }
Example #13
0
 public static List<Product> SelectAllProducts(List<Product> products)
 {
     SqlDataReader reader = SQLSelectQueryCommand("Select * from [ShopDb].[dbo].[Product]");
     products = new List<Product>();
     Product product;
     while (reader.Read())
     {
         product = new Product();
         product.ProductId = (int)reader[0];
         product.Name = (string)reader[1];
         product.Price = (decimal)reader[2];
         products.Add(product);
     }
     reader.Close();
     connection.Close();
     return products;
 }
 public void Edit(Product productToEdit)
 {
     var originalProduct = Get(productToEdit.Id);
     _entities.ApplyPropertyChanges(originalProduct.EntityKey.EntitySetName, productToEdit);
     _entities.SaveChanges();
 }
 public ActionResult Create()
 {
     var product = new Product();
     return View(product);
 }
Example #16
0
 public ActionResult CreateProduct(Product incomingProduct)
 {
     return View("SuccessProductCreation",DataBase.CreateProduct(incomingProduct));
 }
 public ActionResult Create(Product productToCreate)
 {
     Debugger.Break();
     return View();
 }
 public ActionResult Edit(Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(product);
 }
 public ActionResult Create(Product productToCreate)
 {
     // Add product to database
     return RedirectToAction("Index");
 }
Example #20
0
 public static Product SelectProductForEdit(int ProductId)
 {
     SqlDataReader reader = SQLSelectQueryCommand(String.Format("Select * from [ShopDb].[dbo].[Product] where ProductId = {0}", ProductId));
     Product product = new Product();
     while (reader.Read())
     {
         product.ProductId = (int)reader[0];
         product.Name = (string)reader[1];
         product.Price = (decimal)reader[2];
     }
     connection.Close();
     return product;
 }
 public ActionResult Create(Product productToCreate)
 {
     return View();
 }
Example #22
0
 public static void EditProduct(Product product)
 {
     SQLQueryCommand(String.Format("update Product set Name = '{0}',Price = '{1}' where ProductId = {2}", product.Name, product.Price, product.ProductId));
 }
 public ActionResult Edit(Product productToEdit)
 {
     try
     {
         _repository.Edit(productToEdit);
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
Example #24
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Products EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToProducts(Product product)
 {
     base.AddObject("Products", product);
 }
 public void Create(Product productToCreate)
 {
     _entities.AddToProductSet(productToCreate);
     _entities.SaveChanges();
 }