// GET: OrderController public ActionResult Index(DateTime fromDate, DateTime toDate) { string sql; //checking if the fromDate hasn't been initialized if (fromDate == Convert.ToDateTime("January 1, 0001")) { sql = "SELECT * FROM Sales"; } else { //checking if fromDate is not higher than toDate if (fromDate > toDate) { ViewBag.Message = "Invalid Date"; sql = "SELECT * FROM Sales"; } else { sql = $"SELECT * FROM Sales WHERE (Date >= '{fromDate}' AND Date <= '{toDate}')"; } } List <Order> orders = DisplayDbData.DisplayOrders(new List <Order>(), sql); return(View(orders)); }
//to place order directly from a product public ActionResult CreateFromProduct(int Id) { Product product = new Product(); DisplayDbData.GetProductById(product, Id); ViewBag.Product = product; return(View()); }
// GET: ProductController/Create public ActionResult Create() { //passing all the product characteristics to view to create dropdown menus ProductCharacteristics productCharacteristics = new ProductCharacteristics(); DisplayDbData.DisplayProductCharacteristics(productCharacteristics); ViewBag.ProductCharacteristics = productCharacteristics; return(View(new Product())); }
public ActionResult Index() { var Products = DisplayDbData.DisplayInventory(new List <Product>()); if (TempData["rowsAffected"] != null) { ViewBag.Message = TempData["rowsAffected"].ToString(); } return(View(Products)); }
// GET: ProductController/Edit/ public ActionResult Edit(int Id) { try { var product = DisplayDbData.GetProductById(new Product(), Id); ProductCharacteristics productCharacteristics = new ProductCharacteristics(); DisplayDbData.DisplayProductCharacteristics(productCharacteristics); ViewBag.ProductCharacteristics = productCharacteristics; return(View(product)); } catch (Exception) { ViewBag.Message = "Product not found"; return(RedirectToAction(nameof(Index))); throw; } }
public ActionResult Index() { var Products = DisplayDbData.DisplayInventory(new List <Product>()); return(View(Products)); }
static void Main(string[] args) { string input; while (true) { Console.WriteLine("Type Import to upload data or Retrieve to display data from database"); input = Console.ReadLine().Trim(); if (input.ToLower() == "import" || input.ToLower() == "retrieve") { break; } } if (input.ToLower() == "import") { while (true) { Console.WriteLine("Type JSON to save data to a JSON file or SQL to save data to the database"); input = Console.ReadLine().Trim(); if (input.ToLower() == "json" || input.ToLower() == "sql") { break; } } if (input.ToLower() == "json") { Console.WriteLine("json input"); try { //string builder necessary to parse csv to JSON format StringBuilder JInventoryrecords = new StringBuilder(); StringBuilder JSalesrecords = new StringBuilder(); //transforming into json var JInventorySb = new InventoryManagementService(JInventoryrecords); JInventorySb.ProcessProductsFromCsv(Config.PathToInvetoryFile); var JSalesSb = new InventoryManagementService(JSalesrecords); JSalesSb.ProcesOrdersFromCsv(Config.PathToSalesFile); //making file out of json string var JInventoryFile = new CsvToJsonConverter(); JInventoryFile.ProcessCsvFile(JInventoryrecords, Config.PathToData + "JInventoryFile.json"); var JSalesFile = new CsvToJsonConverter(); JSalesFile.ProcessCsvFile(JSalesrecords, Config.PathToData + "JSalesFile.json"); } catch (Exception ex) { var Err = new CreateLogFiles(); Err.ErrorLog(Config.PathToData + "err.log", ex.Message); Console.WriteLine("Fatal error : " + ex.Message + ", please find a complete error at ErrorLog file"); throw; } Console.WriteLine("Updated database succesfully"); } else if (input.ToLower() == "sql") { try { var dropData = new InventoryManagementService(); dropData.DropAllData(); var CsvProductCharRecords = new InventoryManagementService(); CsvProductCharRecords.SaveProductChar(Config.PathToInvetoryFile); var CsvInvetoryRecords = new InventoryManagementService(); CsvInvetoryRecords.SaveCsvInventory(Config.PathToInvetoryFile); var CsvSalesRecords = new InventoryManagementService(); CsvSalesRecords.SaveCsvOrders(Config.PathToSalesFile); } catch (Exception ex) { var Err = new CreateLogFiles(); Err.ErrorLog(Config.PathToData + "err.log", ex.Message); Console.WriteLine("Fatal error : " + ex.Message + ", please find a complete error at ErrorLog file"); throw; } Console.WriteLine("Updated database succesfully"); } } else if (input == "retrieve") { StringBuilder records = new StringBuilder(); Console.WriteLine(DisplayDbData.displayAllData(records).ToString()); } }