private static void Edit(string parameters) { int indexOfRecord; if (string.IsNullOrWhiteSpace(parameters)) { Console.WriteLine("You didn't write which record you want to edit."); return; } if (!int.TryParse(parameters, out indexOfRecord) || indexOfRecord <= 0) { Console.WriteLine("Number of record is not correct."); return; } if (indexOfRecord > fileCabinetService.GetStat()) { Console.WriteLine($"#{indexOfRecord} record is not found."); return; } object[] newRecordData = UserQuestioning(); fileCabinetService.EditRecord(indexOfRecord, new ObjectParametrsForCreateAndEditRecord( newRecordData[0].ToString(), newRecordData[1].ToString(), (DateTime)newRecordData[2], (short)newRecordData[3], (decimal)newRecordData[4], (char)newRecordData[5])); Console.WriteLine($"Record #{indexOfRecord} is updated."); }
private static void Edit(string parameters) { if (!string.IsNullOrEmpty(parameters) && int.TryParse(parameters, out int id)) { if (id > 0 && id <= fileCabinetService.GetStat()) { var typesConverter = new RecordTypesConverter(); Console.Write("First name: "); string firstName = ReadInput(typesConverter.StringConverter, recordValidator.FirstNameValidator); Console.Write("Last name: "); string lastName = ReadInput(typesConverter.StringConverter, recordValidator.LastNameValidator); Console.Write("Date of birth: "); DateTime dateOfBirth = ReadInput(typesConverter.DateTimeConverter, recordValidator.DateOfBirthValidator); Console.Write("Age: "); short age = ReadInput(typesConverter.ShortConverter, recordValidator.AgeValidator); Console.Write("Money: "); decimal money = ReadInput(typesConverter.DecimalConverter, recordValidator.MoneyValidator); Console.Write("Any letter: "); char letter = ReadInput(typesConverter.CharConverter, recordValidator.LetterValidator); var newRecord = new FileCabinetRecord() { FirstName = firstName, LastName = lastName, DateOfBirth = dateOfBirth, Age = age, Money = money, Letter = letter, }; fileCabinetService.EditRecord(id, newRecord); Console.WriteLine($"Record #{id} is edited."); } else { Console.WriteLine($"#{id} not found."); } } else { Console.WriteLine($"There is no explanation for '{parameters}' command."); } }
private static void Edit(string parameters) { try { int id; if (!int.TryParse(parameters, out id)) { Console.WriteLine("invalid id"); return; } Console.Write("first name: "); string firstName = ReadInput(StringConverter, FirstNameValidator); Console.Write("last name: "); string lastName = ReadInput(StringConverter, LastNameValidator); Console.Write("sex: "); char sex = ReadInput(CharConverter, SexValidator); Console.Write("weight: "); short weight = ReadInput(ShortConverter, WeightValidator); Console.Write("date: "); DateTime dateOfBirth = ReadInput(DateConverter, DateOfBirthValidator); Console.Write("balance: "); decimal balance = ReadInput(DecimalConverter, BalanceValidator); var changedRecord = new FileCabinetRecordWithoutID { FirstName = firstName, LastName = lastName, Sex = sex, Weight = weight, DateOfBirth = dateOfBirth, Balance = balance, }; fileCabinetService.EditRecord(id, changedRecord); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } }