示例#1
0
        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()));
        }
示例#2
0
        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()));
        }
示例#3
0
        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()));
        }
示例#4
0
        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));
        }
示例#5
0
        public HttpResponseMessage Widgets()
        {
            var values = DicWidgets.Values.ToList();

            return(HttpResponseHelper.CreateMessage(HttpStatusCode.OK, values.ToHttpContent()));
        }