public async Task <IActionResult> GetAllProducts() { try { List <Product> products = new List <Product>(); var response = await ProductHandler.GetAllProducts(); if (response != null) { //get product photos for (int i = 0; i < response.Count; i++) { Product prod = response[i]; var prodPhotos = await ProductHandler.GetProductPhotosByProductId(prod.ProductId); prod.ProductPhotos = prodPhotos; products.Add(prod); } return(Ok(products)); } return(null); } catch (Exception ex) { Logger.LogError(ex.ToString()); return(StatusCode(505, ex.Message)); } }
private static Transaction AddProducts(Transaction transaction, Staff staff) { bool addingFinished = false; List <Product> products = ProductHandler.GetAllProducts(); Console.WriteLine("** Add products to transaction **\n"); while (!addingFinished) { Console.Clear(); PrintSummary(transaction); Console.WriteLine("\n"); ProductHandler.PrintInfoList(products); Console.WriteLine("Enter the id of the product wanted - enter 0 if you are finished.\n"); Console.Write("Id: "); string idInput = Console.ReadLine(); if (idInput == "0") { break; } try { int productId = int.Parse(idInput); Product wantedProduct = products.Find(p => p.Id == productId); if (wantedProduct != null) { Console.WriteLine("Enter the quantity required. Use , if decimals required"); Console.Write("Quantity: "); double quantity = double.Parse(Console.ReadLine()); TransactionComponent productToAdd = TransactionComponentHandler.Create(transaction, wantedProduct, quantity); transaction.TransactionComponent.Add(productToAdd); Console.WriteLine(String.Format("{0} * {1} à {2} was added to transaction", quantity, productToAdd.ProductName, productToAdd.ProductPrice)); } else { Console.WriteLine(String.Format("No product with id {0} was found", productId)); } } catch (FormatException) { Console.WriteLine("Invalid format of input"); } } return(transaction); }
// GET: Product list public ActionResult Index() { var productList = new List <ProductViewModel>(); var products = productHandler.GetAllProducts(); foreach (var product in products) { productList.Add(new ProductViewModel { ProductId = product.ProductId, BrandCategoryId = product.BrandCategoryId, Name = product.Name, Price = product.Price }); } return(View(productList)); }
//THis function show the product whose quantity is less 15 public ActionResult ProductTable(string search, int?pageNo) { AllProductViewModel model = new AllProductViewModel(); ProductHandler handler = new ProductHandler(); model.SearchItem = search; pageNo = pageNo.HasValue ? pageNo.Value > 0 ? pageNo.Value : 1 : 1; var totalRecord = handler.GetProductCount(search); model.productList = handler.GetAllProducts(search, pageNo.Value); if (model.productList != null) { model.Pager = new Pager(totalRecord, pageNo, 6); return(PartialView("_ProductTable", model)); } return(PartialView("_ProductTable", model)); }
public static void Sell() { bool shouldBeOpen = true; while (shouldBeOpen) { List <Staff> availableStaff = StaffHandler.GetAllStaff(); List <Product> allProducts = ProductHandler.GetAllProducts(); // We must have staff to be able to sell anything: if (availableStaff.Count == 0) { Console.WriteLine("There must be available staff to be able to sell - Please create those first."); Console.ReadKey(); break; // Break the while loop to return to menu } // We also need products to sell: if (allProducts.Count == 0) { Console.WriteLine("There must be products available to be able to sell - Please create those first."); Console.ReadKey(); break; // Break the while loop to return to menu } Staff clerk = Login(availableStaff); Console.Clear(); if (clerk == null) { break; // If we don't have a clerk we abort. } Console.WriteLine("Logged in as " + clerk.FirstName + " " + clerk.LastName); StartSalesMenu(clerk); } }