public ServerDataModule(IServerDataRepository serverDataRepository)
            : base("/serverdata")
        {
            _serverDataRepository = serverDataRepository;

            Get["/"] = _ => Response.AsJson <object>(serverDataRepository.GetAll());

            //Get["/{id:int}"] = _ => FormatterExtensions.AsJson<object>(Response, serverDataRepository.Get(_.id));

            Get["/{id:int}"] = _ => NegotiatorExtensions
                               .WithModel(Negotiate.WithStatusCode(HttpStatusCode.OK), serverDataRepository.Get(_.id));

            Post["/"] = _ =>
            {
                var data = serverDataRepository.Add(this.Bind <ServerData>());

                return(HttpStatusCode.OK);
            };

            Put["/{id:int}"] = _ =>
            {
                var data = this.Bind <ServerData>();
                data.Id = _.id;

                serverDataRepository.Update(data);

                return(HttpStatusCode.OK);
            };

            Delete["/{id:int}"] = _ =>
            {
                serverDataRepository.Delete(_.id);
                return(HttpStatusCode.OK);
            };
        }
Esempio n. 2
0
        public RestauranteModulo(IRestauranteRepository restauranteRepository) : base("/restaurante")
        {
            _restauranteRepository = restauranteRepository;
            Get["/"]         = _ => Response.AsJson <object>(restauranteRepository.PegaTodosRegistro());
            Get["/{id:int}"] =
                _ =>
                NegotiatorExtensions.WithModel(Negotiate.WithStatusCode(HttpStatusCode.OK),
                                               restauranteRepository.Get(_.id));

            Post["/"] = _ =>
            {
                var nancyrestaurante = restauranteRepository.Adiciona(this.Bind <Restaurante>());
                return(HttpStatusCode.OK);
            };

            Put["/{id:int}"] = _ =>
            {
                var nancyrestaurante = this.Bind <Restaurante>();
                nancyrestaurante.Id = _.id;
                restauranteRepository.Atualiza(nancyrestaurante);
                return(HttpStatusCode.OK);
            };

            Delete["/{id:int}"] = _ =>
            {
                restauranteRepository.Delete(_.id);
                return(HttpStatusCode.OK);
            };
        }