public Task <HttpResponseMessage> PostCad([FromBody] dynamic body) // Cadastro dos restaurantes { var response = new HttpResponseMessage(); try { var restauranteExiste = _service.GetOne((string)body.nome); try { if (restauranteExiste.Nome.Equals((string)body.nome)) { response = Request.CreateResponse(HttpStatusCode.OK, "Este restaurante já esta cadastrado!"); } } catch { var command = new RegisterRestauranteCommand( nome: (string)body.nome ); var restaurante = _service.Create(command); return(CreateResponse(HttpStatusCode.Created, restaurante)); } } catch { response = Request.CreateResponse(HttpStatusCode.BadRequest, "Não foi criado o restaurante!"); } var tsc = new TaskCompletionSource <HttpResponseMessage>(); tsc.SetResult(response); return(tsc.Task); }
public Restaurante Create(RegisterRestauranteCommand command) { var restaurante = new Restaurante(command.Nome); restaurante.RegisterRestaurante(); _repository.Create(restaurante); if (Commit()) { return(restaurante); } return(null); }
public Restaurante Create(RegisterRestauranteCommand command) { var restaurante = new Restaurante(command.Nome, command.Bairro, command.Rua, command.Numero, command.UsuarioId); restaurante.RegisterRestaurante(); _repository.Create(restaurante); if (Commit()) { return(restaurante); } return(null); }