Ejemplo n.º 1
0
        /// <summary>
        /// Posts a new post.
        /// </summary>
        /// <param name="item">New post</param>
        /// <returns>Status message</returns>
        public async Task<Post> Post(Post item)
        {
            if (item == null)
            {
                throw new HttpResponseException(
                    Request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid parameter"));
            }

            var post = await repository.InsertAsync(item);
            return post;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates an existing post.
        /// </summary>
        /// <param name="key">Post ID</param>
        /// <param name="item">Updated post</param>
        /// <returns>Status message</returns>
        public async Task<Post> Put([FromODataUri] Guid key, Post item)
        {
            if (key == Guid.Empty || item == null)
            {
                throw new HttpResponseException(
                    Request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid parameter"));
            }

            item.ID = key;
            var post = await repository.UpdateAsync(item);
            return post;
        }