Ejemplo n.º 1
0
 /// <summary>
 /// This method edits data of product and saves changes to database.
 /// </summary>
 /// <param name="product">The product to be edited.</param>
 /// <returns>Edited product.</returns>
 public vwProduct EditProduct(vwProduct product)
 {
     try
     {
         using (WarehouseEntities context = new WarehouseEntities())
         {
             tblProduct productToEdit = context.tblProducts.Where(x => x.ProductID == product.ProductID).FirstOrDefault();
             productToEdit.ProductName = product.ProductName;
             productToEdit.ProductKey  = product.ProductKey;
             productToEdit.Quantity    = product.Quantity;
             productToEdit.Price       = product.Price;
             context.SaveChanges();
             LogAction("Product with ID " + productToEdit.ProductID + " is updated. Key: " + productToEdit.ProductKey +
                       " Name: " + productToEdit.ProductName + " Price: " + productToEdit.Price + " Quantity: " + productToEdit.Quantity);
             return(product);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }