/// <newDrug> /// This method takes from the console information for a new drug. /// (name, sell price, acquire price) /// It adds the new drug to the database. /// </newDrug> public void NewDrug() { string name; double sellPrice; double acquirePrice; int quantity = 0; try { Dictionary <string, string> dict = CommandReader.NewDrug(); name = dict["name"]; if (name == "" || dict["sell"] == "" || dict["acquire"] == "") { throw new InvalidOperationException(ConstantStrings.Blank); } OutputPrinter.Connecting(); List <string> names = c.Drugs.Select(e => e.Name).ToList(); if (names.Contains(name)) { throw new InvalidOperationException(ConstantStrings.Drug + $" with name '{name}' " + ConstantStrings.AlreadyExists); } try { sellPrice = double.Parse(dict["sell"]); acquirePrice = double.Parse(dict["acquire"]); } catch (Exception) { throw new InvalidOperationException(ConstantStrings.SellAndAcquire + " " + ConstantStrings.ValidNumber); } if (sellPrice <= 0 || acquirePrice <= 0) { throw new InvalidOperationException(ConstantStrings.SellAndAcquire + " " + ConstantStrings.PositiveNumber); } var drug = new Drug { Name = name, Sell_Price = sellPrice, Acquire_Price = acquirePrice, Quantity = quantity }; New(drug); OutputPrinter.Done(); } catch (Exception e) { Console.WriteLine(e.Message); OutputPrinter.InvalidCommand(); } }