public HttpResponseMessage Widgets(string id) { int idParsed; WidgetModel widget; return(!int.TryParse(id, out idParsed) || !DicWidgets.TryGetValue(idParsed, out widget) ? HttpResponseHelper.CreateMessage(HttpStatusCode.NotFound, "false".ToHttpContent()) : HttpResponseHelper.CreateMessage(HttpStatusCode.OK, widget.ToHttpContent())); }
public HttpResponseMessage Users(string id) { int idParsed; UserModel user; return(!int.TryParse(id, out idParsed) || !DicUsers.TryGetValue(idParsed, out user) ? HttpResponseHelper.CreateMessage(HttpStatusCode.NotFound, "Not Found".ToHttpContent()) : HttpResponseHelper.CreateMessage(HttpStatusCode.OK, user.ToHttpContent())); }
public HttpResponseMessage Widgets([FromBody] WidgetModel widget) { if (widget == null) { return(HttpResponseHelper.CreateMessage(HttpStatusCode.BadRequest, "Bad Request".ToHttpContent())); } _lastId++; widget.Id = _lastId; DicWidgets.Add(widget.Id, widget); return(HttpResponseHelper.CreateMessage(HttpStatusCode.Created, "added!".ToHttpContent())); }
public HttpResponseMessage Widgets(string id, [FromBody] WidgetModel widget) { if (widget == null) { return(HttpResponseHelper.CreateMessage(HttpStatusCode.BadRequest, "Bad Request".ToHttpContent())); } int idParsed; if (!int.TryParse(id, out idParsed) || !DicWidgets.ContainsKey(idParsed)) { return(HttpResponseHelper.CreateMessage(HttpStatusCode.NotFound, "widget not found".ToHttpContent())); } widget.Id = idParsed; DicWidgets[idParsed] = widget; return(HttpResponseHelper.CreateMessage(HttpStatusCode.NoContent)); }
public HttpResponseMessage Widgets() { var values = DicWidgets.Values.ToList(); return(HttpResponseHelper.CreateMessage(HttpStatusCode.OK, values.ToHttpContent())); }