Пример #1
0
 public void Add(Person person)
 {
     if (_personValidator.Validate(person))
     {
         _personRepository.Add(person);
     }
 }
Пример #2
0
        public bool Create(Person item)
        {
            if (item == null)
            {
                throw new InvalidOperationException("The person to create can't be null");
            }

            var created          = false;
            var validationResult = _validator.Validate(item);

            if (validationResult.HasError)
            {
                NotifyError?.Invoke(this, validationResult);
            }
            else
            {
                created = _repository.Create(item);
            }

            return(created);
        }
Пример #3
0
        public override OperationResult <IKeyedDto> Add(IBaseDto dto)
        {
            var b       = (BasePersonDto)dto;
            var results = _validtor.Validate(b);

            IsValid = results.IsValid;
            if (!IsValid)
            {
                var vstatus = OperationStatus.BadRequest;
                vstatus.ReasonForFailure = "Invalid input";
                return(new OperationResult <IKeyedDto>(vstatus));
            }
            var personToAdd = _mapper.MapBack(b);

            var(status, value) = _repository.Add(personToAdd);
            if (status != OperationStatus.OK)
            {
                return(new OperationResult <IKeyedDto>(status));
            }
            var val = RecoverKeyedEntity(value);

            return(new OperationResult <IKeyedDto>(status, val));
        }
Пример #4
0
        /// <summary>
        /// Start processing person object from reading, parsing, validating, sorting, and writing to output file
        /// </summary>
        /// <param name="reader">person data provider</param>
        /// <param name="parser">person data parser</param>
        /// <param name="writer">person data writer</param>
        /// <param name="validator">person data validator</param>
        /// <param name="sorter">person data sorter</param>
        /// <returns>List of persons</returns>
        public IList <PersonDTO> Process()
        {
            Messages = new List <String>();

            var providedData = _reader.Read();

            var parsedData = _parser.Parse(providedData);

            var validatedData = _validator.Validate(parsedData);

            var sortedData = _sorter.Sort(validatedData);

            _writer.Write(sortedData);

            Messages = Messages.Concat(_validator.Messages);

            return(sortedData);
        }
Пример #5
0
        static void Main(string[] args)
        {
            StandardMessages.StartApplication();

            Person person = new Person();

            StandardMessages.DisplayFirstNameRequestMessage();
            person = PersonDataCapture.CapturePersonFirstName(person);

            StandardMessages.DisplayLastNameRequestMessage();
            person = PersonDataCapture.CapturePersonLastName(person);

            bool isValidPerson = PersonValidator.Validate(person);

            if (!isValidPerson)
            {
                ApplicationFinisher.FinishApplication();
                return;
            }

            PersonCreator.Create(person);
            ApplicationFinisher.FinishApplication();
        }