コード例 #1
0
        public void DeveSerInvalidoComNameVazioOuNulo()
        {
            var input = new NewRestaurantInputModel
            {
                Address  = "Av. Araxá",
                Category = "Restaurante",
                Location = "Goiânia"
            };

            Assert.False(input.IsValid);
        }
コード例 #2
0
        public void DeveSerValidoComInformacoesPreenchidas()
        {
            var input = new NewRestaurantInputModel
            {
                Name     = "Restaurante",
                Category = "Restaurante",
                Address  = "Av. Araxá",
                Location = "Goiânia"
            };

            Assert.True(input.IsValid);
        }
コード例 #3
0
        public async Task <Result> Add(NewRestaurantInputModel input)
        {
            if (!input.IsValid)
            {
                return(Result.Error(input.ValidationResult.ToErrorList()));
            }

            var restaurant = _mapper.Map <Restaurant>(input);

            await _repository.Insert(restaurant);

            return(Result.Success());
        }
コード例 #4
0
        public async Task <ActionResult <Result> > Create([FromBody] NewRestaurantInputModel input)
        {
            try
            {
                var result = await _service.Add(input);

                return(ReturnResult(result));
            }
            catch (Exception ex)
            {
                return(ReturnResult(Result.Error(ex)));
            }
        }