public WeightsModule(IWeightsService weightsService) : base("/weights/") { Get["/"] = _ => "Hello!"; Post["/"] = _ => { var newId = weightsService.Create(); var locationUri = ModulePath + newId; return(Negotiate .WithModel(new { id = newId }) .WithHeader("Location", locationUri) .WithStatusCode(HttpStatusCode.Created)); }; }
public WeightsModule(IWeightsService weightsService) : base(RootUriStrings.Weights) { Post("/", async _ => { //TODO: bind to CreateWeightRequestDto //TODO: validate DTO //TODO: map DTO -> BO var newWeightRequest = this.Bind <CreateWeightRequest>(); var newId = await weightsService.AddWeightAsync(newWeightRequest); return(Negotiate .WithModel(new { id = newId }) .WithHeader("Location", RootUriStrings.Weights + newId) .WithStatusCode(HttpStatusCode.Created)); }); }
public WeightsController(IWeightsService weightsService) { WeightsService = weightsService; }