Beispiel #1
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);
        }
Beispiel #2
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));
        }