/// <summary> /// sub menu for creating a new Product and adding it to the database /// </summary> /// <param name="data">the DBcontect for the database</param> public static void AddProduct(IDataBase data) { Console.Write("Enter a name for the product: "); string name = Console.ReadLine(); decimal price = 0; bool isValid = false; while (!isValid) { Console.Write("Enter a Price for the product: "); if (decimal.TryParse(Console.ReadLine(), out price)) { isValid = true; } else { Console.WriteLine("Price was invalid:"); } } List <Product> products = data.GetAllProducts(name: name).ToList(); if (products.Count == 0) { try { Product newProduct = new Product() { Name = name, CostPerUnit = price, }; data.AddProduct(newProduct); } catch (ArgumentException ex) { Log.Warning("Error in database update {Message}", ex.Message); Console.WriteLine($"Error in creating new location: {ex.Message}"); } catch (DbUpdateConcurrencyException ex) { Log.Warning("Error in database update {Message}", ex.Message); Console.WriteLine($"Error in creating new location: {ex.Message}"); } catch (DbUpdateException ex) { Log.Warning("Error in database update {Message}", ex.Message); Console.WriteLine($"Error in creating new location: {ex.Message}"); } } }
public Guid AddProduct(ProductCreateRequestDto request) { return(DbImplementation.AddProduct(request)); }