示例#1
0
        public ActionResult Create(Product product)
        {
            StringBuilder errorMessages = new StringBuilder();

            if (ModelState.IsValid)
            {
                try {
                    ProductHandle sdb = new ProductHandle();
                    if (sdb.AddProduct(product))
                    {
                        ViewBag.Message = "Product Details Added Successfully";
                        ModelState.Clear();
                    }
                }
                catch (SqlException ex)
                {
                    for (int i = 0; i < ex.Errors.Count; i++)
                    {
                        errorMessages.Append("Index #" + i + "\n" +
                                             "Message: " + ex.Errors[i].Message + "\n" +
                                             "LineNumber: " + ex.Errors[i].LineNumber + "\n" +
                                             "Source: " + ex.Errors[i].Source + "\n" +
                                             "Procedure: " + ex.Errors[i].Procedure + "\n");
                    }
                    Console.WriteLine(errorMessages.ToString());
                }
            }
            return(View());
        }
示例#2
0
        // 1. *************RETRIEVE ALL PRODUCT DETAILS ******************
        // GET: Admin/Select
        public ActionResult Select()
        {
            ProductHandle dbhandle = new ProductHandle();

            ModelState.Clear();
            if (TempData["shortMessage"] != null)
            {
                ViewBag.AlertMsg = TempData["shortMessage"].ToString();
            }

            return(View(dbhandle.GetProducts()));
        }
示例#3
0
 public ActionResult Edit(int id, Product product)
 {
     try
     {
         ProductHandle sdb = new ProductHandle();
         sdb.UpdateDetails(product);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
示例#4
0
        // 4. ************* DELETE Product DETAILS ******************
        // GET: Admin/Delete/5
        public ActionResult Delete(int id)
        {
            try
            {
                ProductHandle sdb = new ProductHandle();
                if (sdb.DeleteProduct(id))
                {
                    TempData["shortMessage"] = "The product has been deleted!";
                }

                return(RedirectToAction("Select"));
            }
            catch
            {
                return(View());
            }
        }
示例#5
0
        // 3. ************* EDIT PRODUCT DETAILS ******************
        // GET: Admin/Edit/5
        public ActionResult Edit(int id)
        {
            ProductHandle sdb = new ProductHandle();

            return(View(sdb.GetProducts().Find(product => product.Id == id)));
        }
示例#6
0
 public void Setup()
 {
     collectionId  = "products";
     productHandle = new ProductHandle();
 }
示例#7
0
        static void Main(string[] args)
        {
            /*try
             * {
             *  Program p = new Program();
             *  p.AsycnGetProducts().Wait();
             * }
             * catch (DocumentClientException de)
             * {
             *  Exception baseException = de.GetBaseException();
             *  Console.WriteLine("{0} error occurred: {1}, Message: {2}", de.StatusCode, de.Message, baseException.Message);
             * }
             * catch (Exception e)
             * {
             *  Exception baseException = e.GetBaseException();
             *  Console.WriteLine("Error: {0}, Message: {1}", e.Message, baseException.Message);
             * }
             * finally
             * {
             *  Console.WriteLine("End of demo, press any key to exit.");
             *  Console.ReadKey();
             * }*/

            //ListDBs();
            client = DocumentDBClientConfig.GetClientInstance;
            ProductHandle productHandle = new ProductHandle();

            /*Console.WriteLine("Show list of products!!!");
             * Console.WriteLine("==============================================================\n\n");
             * foreach (var item in productHandle.GetProducts())
             * {
             *  Console.WriteLine($"product {item.name}  price:{item.price}");
             * }
             *
             *
             * Console.WriteLine("[Async Fashion] Show list of products!!!");
             * Console.WriteLine("==============================================================\n\n");
             * var data = productHandle.GetProductsAsync();
             * foreach (var item in data.Result)
             * {
             *  Console.WriteLine($"product {item.name}  price:{item.price}");
             * }
             */
            /* var productName = "iPad";
             * Console.WriteLine($"[Async Fashion] Get products that match with {productName}!!!");
             * Console.WriteLine("==============================================================\n\n");
             * var data = productHandle.GetProductsByNameAsync(productName);
             * foreach (var item in data.Result)
             * {
             *   Console.WriteLine($"product {item.name}  price:{item.price}");
             * }
             * Console.WriteLine("List products is done!!!!");*/

            Console.WriteLine($"[Async Fashion] Add Product !!!");
            Console.WriteLine("==============================================================\n\n");
            Product p = new Product
            {
                Id    = "1013",
                Name  = "iPhone x",
                Price = 300
            };

            productHandle.AddProductAsync(p);

            /*
             * Task t = Task.Run(() =>
             * {
             *  var data = productHandle.GetProductsByNameAsync(productName);
             *  foreach (var item in data.Result)
             *  {
             *      Console.WriteLine($"product {item.name}  price:{item.price}");
             *  }
             * });
             *
             * t.Wait();*/


            // Accessing documents

            /*var dbName = "InventoryDB";
             * var collectionId = "products";
             * ListProducts(client,dbName, collectionId);
             *
             * GetProductByName(client, dbName, collectionId, "iPad");
             * GetProductWhichLowerThan(client, dbName, collectionId, 500);*/

            Console.ReadKey();
        }