Пример #1
0
        public HttpResponseMessage PostComment(Comment item)
        {
            if (item == null)
            {
                var errorResponse = this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Object is null");
                return errorResponse;
            }
            var entity = this.commentRepository.Add(item);
            var response = Request.CreateResponse(HttpStatusCode.Created, entity);
            response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = entity.Id }));

            return response;
        }
Пример #2
0
        public HttpResponseMessage PutComment(int id, Comment item)
        {
            if (id <= 0)
            {
                var errorResponse = this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "ID must be positive");
                return errorResponse;
            }
            if (item == null)
            {
                var errorResponse = this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Object is null");
                return errorResponse;
            }
            var entity = this.commentRepository.Update(id, item);
            var response = Request.CreateResponse(HttpStatusCode.OK, entity);
            response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = entity.Id }));

            return response;
        }