public TaxModule() : base("/tax") { Get("/id/{id}", _ => GetTaxById(_)); Get("/{municipality}/{year}/{month}/{day}", _ => GetTax(_)); Post("/add", _ => { try { var model = this.Bind <Tax>(); Taxes.Add(model); var r = Response.AsJson(model).WithHeader("Location", $"/tax/id/{model.Id}"); return(r); } catch (Exception e) { return(Helper.ErrorResponse(e, HttpStatusCode.InternalServerError)); } }); Put("/{id}", _ => { try { var request = this.Bind <RequestObject>(); var model = this.Bind <Tax>(); Taxes.UpdateTax(request.Id, model); return(model); } catch (Exception e) { return(Helper.ErrorResponse(e, HttpStatusCode.InternalServerError)); } }); Delete("/{id}", _ => { try { var request = this.Bind <RequestObject>(); Taxes.Delete(request.Id); return(HttpStatusCode.NoContent); } catch (Exception e) { return(Helper.ErrorResponse(e, HttpStatusCode.InternalServerError)); } }); }
public ApiTransactionOffer Add(ApiTransactionTax tax) { Taxes ??= new List <ApiTransactionTax>(); Taxes.Add(tax); return(this); }