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()); }
// 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())); }
public ActionResult Edit(int id, Product product) { try { ProductHandle sdb = new ProductHandle(); sdb.UpdateDetails(product); return(RedirectToAction("Index")); } catch { return(View()); } }
// 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()); } }
// 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))); }
public void Setup() { collectionId = "products"; productHandle = new ProductHandle(); }
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(); }