public string AddInstrumentToDwarf(string dwarfName, int power) { IDwarf dwarf = this.dwarfs.FindByName(dwarfName); if (dwarf == null) { throw new InvalidOperationException("The dwarf you want to add an instrument to doesn't exist!"); } IInstrument instrument = new Instrument(power); dwarf.AddInstrument(instrument); return($"Successfully added instrument with power {instrument.Power} to dwarf {dwarf.Name}!"); }
public string AddInstrumentToDwarf(string dwarfName, int power) { IDwarf wantedDwarf = this.dwarfs.Models.FirstOrDefault(d => d.Name == dwarfName); if (wantedDwarf == null) { throw new InvalidOperationException(ExceptionMessages.InexistentDwarf); } IInstrument instrument = new Instrument(power); wantedDwarf.AddInstrument(instrument); return(String.Format(OutputMessages.InstrumentAdded, power, dwarfName)); }
public string AddInstrumentToDwarf(string dwarfName, int power) { IInstrument instrument = new Instrument(power); IDwarf dwarf = this.dwarfs.FindByName(dwarfName); if (dwarf == null) { throw new InvalidOperationException(ExceptionMessages.InexistentDwarf); } dwarf.AddInstrument(instrument); return($"Successfully added instrument with power {power} to dwarf {dwarfName}!"); }
public string AddInstrumentToDwarf(string dwarfName, int power) { IInstrument instrument = new Instrument(power); if (dwarfs.FindByName(dwarfName) == null) { throw new InvalidOperationException(ExceptionMessages.InexistentDwarf); } IDwarf dwarf = dwarfs.FindByName(dwarfName); dwarf.AddInstrument(instrument); return(string.Format(OutputMessages.InstrumentAdded, power, dwarfName)); }
public string AddInstrumentToDwarf(string dwarfName, int power) { IDwarf dwarf = this.dwarfs.FindByName(dwarfName); // първо проверяваме дали има такъв dwarf if (dwarf == null) { throw new InvalidOperationException(ExceptionMessages.InexistentDwarf); } IInstrument instrument = new Instrument(power); //правим си инструмент dwarf.AddInstrument(instrument); string result = string.Format(OutputMessages.InstrumentAdded, power, dwarfName); return(result); }