示例#1
0
        private void Create(string parameters)
        {
            Console.Write("First name: ");
            var firstName = this.ReadInput(this.stringConverter, this.firstNameValidator);

            Console.Write("Last name: ");
            var lastName = this.ReadInput(this.stringConverter, this.lastNameValidator);

            Console.Write("Date of birth: ");
            var dateOfBirth = this.ReadInput(this.dateConverter, this.dateOfBirthValidator);

            Console.Write("Sex: ");
            var sex = this.ReadInput(this.charConverter, this.sexValidator);

            Console.Write("Number of reviews: ");
            var numberOfReviews = this.ReadInput(this.numberOfReviewsConverter, this.numberOfReviewsValidator);

            Console.Write("Salary: ");
            var salary = this.ReadInput(this.salaryConverter, this.salaryValidator);

            var userInputData = new UnverifiedData(firstName, lastName, dateOfBirth, sex, numberOfReviews, salary);
            int id            = this.fileCabinetService.CreateRecord(userInputData);

            Console.WriteLine($"Record #{id} is created.");
        }
示例#2
0
        /// <summary>Validates user input data.</summary>
        /// <param name="data">Data to validate.</param>
        /// <exception cref="ArgumentNullException">Thrown when data is null.</exception>
        /// <exception cref="ArgumentException">Last name is empty
        /// or
        /// Last name's length is out of range or has invalid characters.</exception>
        public void ValidateParameters(UnverifiedData data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            if (string.IsNullOrWhiteSpace(data.LastName))
            {
                throw new ArgumentException("Last name is empty.");
            }

            if (data.LastName.Length < this.minLength || data.LastName.Length > this.maxLength)
            {
                throw new ArgumentException("Last name's length is out of range.");
            }

            if (this.isCustomValidationRules)
            {
                if (!Regex.IsMatch(data.LastName, AllowedCharacters))
                {
                    throw new ArgumentException("Last name has invalid characters.");
                }
            }
        }
示例#3
0
 /// <summary>Validates user input data.</summary>
 /// <param name="data">Data to validate.</param>
 public void ValidateParameters(UnverifiedData data)
 {
     foreach (var validator in this.validators)
     {
         validator.ValidateParameters(data);
     }
 }
示例#4
0
        /// <summary>Validates user input data.</summary>
        /// <param name="data">Data to validate.</param>
        /// <exception cref="ArgumentNullException">Thrown when data is null.</exception>
        /// <exception cref="ArgumentException">Wrong sex.</exception>
        public void ValidateParameters(UnverifiedData data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            if (data.Sex != MaleSex && data.Sex != FemaleSex)
            {
                throw new ArgumentException("Wrong sex.");
            }
        }
示例#5
0
        /// <summary>Validates user input data.</summary>
        /// <param name="data">Data to validate.</param>
        /// <exception cref="ArgumentNullException">Thrown when data is null.</exception>
        /// <exception cref="ArgumentException">Salary is less than specified value.</exception>
        public void ValidateParameters(UnverifiedData data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            if (data.Salary < this.minSalary)
            {
                throw new ArgumentException("Salary is too small.");
            }
        }
示例#6
0
        /// <summary>Validates user input data.</summary>
        /// <param name="data">Data to validate.</param>
        /// <exception cref="ArgumentNullException">Thrown when data is null.</exception>
        /// <exception cref="ArgumentException">Invalid date of birth.</exception>
        public void ValidateParameters(UnverifiedData data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            if (data.DateOfBirth < this.from || data.DateOfBirth >= this.to)
            {
                throw new ArgumentException("Invalid date of birth.");
            }
        }
示例#7
0
        /// <summary>Validates user input data.</summary>
        /// <param name="data">Data to validate.</param>
        /// <exception cref="ArgumentNullException">Thrown when data is null.</exception>
        /// <exception cref="ArgumentException">Number of reviews is less than specified number.</exception>
        public void ValidateParameters(UnverifiedData data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            if (data.NumberOfReviews < this.minNumber)
            {
                throw new ArgumentException("Number of reviews is too small.");
            }
        }
示例#8
0
        private void Edit(string parameters)
        {
            if (!int.TryParse(parameters, out int id))
            {
                Console.WriteLine("Invalid characters.");
                Console.WriteLine();
                return;
            }

            if (!this.fileCabinetService.StoredIdentifiers.Contains(id))
            {
                Console.WriteLine($"#{id} record is not found.");
                Console.WriteLine();
                return;
            }

            Console.Write("First name: ");
            var firstName = this.ReadInput(this.stringConverter, this.firstNameValidator);

            Console.Write("Last name: ");
            var lastName = this.ReadInput(this.stringConverter, this.lastNameValidator);

            Console.Write("Date of birth: ");
            var dateOfBirth = this.ReadInput(this.dateConverter, this.dateOfBirthValidator);

            Console.Write("Sex: ");
            var sex = this.ReadInput(this.charConverter, this.sexValidator);

            Console.Write("Number of reviews: ");
            var numberOfReviews = this.ReadInput(this.numberOfReviewsConverter, this.numberOfReviewsValidator);

            Console.Write("Salary: ");
            var salary = this.ReadInput(this.salaryConverter, this.salaryValidator);

            var userInputData = new UnverifiedData(firstName, lastName, dateOfBirth, sex, numberOfReviews, salary);

            this.fileCabinetService.EditRecord(id, userInputData);
            Console.WriteLine($"Record #{id} is updated.");
        }