private void Create() { Console.Write(Configurator.GetConstantString("FirstNameColon")); string firstName = ReadInput <string>(Converter.ConvertStringToString); Console.Write(Configurator.GetConstantString("LastNameColon")); string lastName = ReadInput <string>(Converter.ConvertStringToString); Console.Write(Configurator.GetConstantString("DateOfBirthColon")); DateTime dateOfBirth = ReadInput <DateTime>(Converter.ConvertStringToDateTime); Console.Write(Configurator.GetConstantString("HeightColon")); short height = ReadInput <short>(Converter.ConvertStringToShort); Console.Write(Configurator.GetConstantString("IncomeColon")); decimal income = ReadInput <decimal>(Converter.ConvertStringToDecimal); Console.Write(Configurator.GetConstantString("PatronymicColon")); char patronymicLetter = ReadInput <char>(Converter.ConvertStringToChar); RecordParametersTransfer transfer = new RecordParametersTransfer(firstName, lastName, dateOfBirth, height, income, patronymicLetter); try { int index = this.Service.CreateRecord(transfer); Console.WriteLine($"Record #{index} is created."); } catch (ArgumentException) { Console.WriteLine(Configurator.GetConstantString("InvalidInput")); } }
/// <summary> /// Creates new records with given parameters and measure execution time. /// </summary> /// <param name="transfer">Object to transfer parameters of new record.</param> /// <returns>ID of created record.</returns> /// <exception cref="ArgumentNullException">Throw when transfer object is null.</exception> /// <exception cref="ArgumentException">Thrown when transfer data is invalid.</exception> public int CreateRecord(RecordParametersTransfer transfer) { var stopWatch = Stopwatch.StartNew(); var result = this.service.CreateRecord(transfer); Console.WriteLine($"CreateRecord method execution duration is {stopWatch.ElapsedTicks} ticks."); return(result); }
/// <summary> /// Creates new records with given parameters and writes info to log file. /// </summary> /// <param name="transfer">Object to transfer parameters of new record.</param> /// <returns>ID of created record.</returns> /// <exception cref="ArgumentNullException">Throw when transfer object is null.</exception> /// <exception cref="ArgumentException">Thrown when transfer data is invalid.</exception> public int CreateRecord(RecordParametersTransfer transfer) { if (transfer is null) { throw new ArgumentNullException(nameof(transfer), Configurator.GetConstantString("NullTransfer")); } this.writer.WriteLine($"{DateTime.Now} Calling CreateRecord with FirstName = {transfer.FirstName}, LastName = {transfer.LastName}, DateOfBirth = {transfer.DateOfBirth}, Height = {transfer.Height}, Income = {transfer.Income}, PatrinymicLetter = {transfer.PatronymicLetter}."); var result = this.service.CreateRecord(transfer); this.writer.WriteLine($"{DateTime.Now} CreateRecord returned {result}"); return(result); }