Exemplo n.º 1
0
        public Person(string firstName, string lastName, string email)
        {
            FirstName = firstName;
            LastName  = lastName;
            Email     = email;

            this.Errors = new ReadOnlyCollection <DomainNotification>(PersonValidation.Validate(this).ToDomainNotification());
        }
Exemplo n.º 2
0
        public async Task WillAddPersonUsingHandler()
        {
            var handler = new PersonHandler(_context, _logger);

            var person = new PersonDTO()
            {
                City        = "Zagreb",
                Name        = "Joža",
                PhoneNumber = "+385910397123",
                Surname     = "Jožić",
                ZipCode     = 10000.ToString()
            };

            var validationData = _validator.Validate(person);

            var result = await handler.AddAsync(person);

            Assert.True(validationData.IsValid);
            Assert.Equal(1, result);
        }
Exemplo n.º 3
0
        public void PersonInstanceIsValid()
        {
            PersonDTO person = new PersonDTO()
            {
                Name        = "Antonio",
                Surname     = "Halužan",
                PhoneNumber = "+385959180338",
                ZipCode     = 10000.ToString(),
                City        = "Zagreb"
            };

            var result = _validator.Validate(person);

            Assert.True(result.IsValid);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Post([FromBody] JArray json)
        {
            var data = json.ToObject <ICollection <PersonDTO> >();

            var returnData = new List <PersonDTO>();

            foreach (var item in data)
            {
                if (_validator.Validate(item).IsValid &&
                    int.TryParse(item.ZipCode, out int n))
                {
                    var result = await _handler.AddAsync(item);

                    if (result == 1)
                    {
                        returnData.Add(item);
                    }
                }
            }

            return(Ok(returnData));
        }