public ActionResult IncluirRestaurante([FromBody] RestauranteInclusao restauranteInclusao) { var cozinha = ECozinhaHelper.ConverterDeInteiro(restauranteInclusao.Cozinha); var restaurante = new Restaurante(restauranteInclusao.Nome, cozinha); var endereco = new Endereco( restauranteInclusao.Logradouro, restauranteInclusao.Numero, restauranteInclusao.Cidade, restauranteInclusao.UF, restauranteInclusao.Cep); restaurante.AtribuirEndereco(endereco); if (!restaurante.Validar()) { return(BadRequest( new { errors = restaurante.ValidationResult.Errors.Select(_ => _.ErrorMessage) })); } _restauranteRepository.Inserir(restaurante); return(Ok( new { data = "Restaurante inserido com sucesso" } )); }
public ActionResult Create([Bind(Include = "RestauranteId,Nome")] RestauranteViewModel restaurante) { if (ModelState.IsValid) { Restaurante rest = new Restaurante() { Nome = restaurante.Nome }; repRestaurante.Inserir(rest); repRestaurante.SalvarTodos(); ViewBag.Mensagem = "Restaurante Cadastrado com Sucesso!"; return(RedirectToAction("Index")); } return(View(restaurante)); }