Exemplo n.º 1
0
        /// <summary>
        /// Delete Post
        /// </summary>
        /// <param name="postId">Id of Post</param>
        /// <param name="userId">Id of User</param>
        /// <returns></returns>
        public HttpResponseMessage DeletePost(string postId, string userId)
        {
            if (ModelState.IsValid)
            {
                string userName = User.Identity.Name;

                var user = userBLL.GetUserByUserName(userName);

                if (user.Id == userId)
                {
                    postBLL.DeletePost(postId);

                    var    response = Request.CreateResponse(HttpStatusCode.OK);
                    string uri      = Url.Link("DefaultApi", new { id = postId });
                    response.Headers.Location = new Uri(uri);

                    return(response);
                }
                else
                {
                    var    response = Request.CreateResponse(HttpStatusCode.Unauthorized);
                    string uri      = Url.Link("DefaultApi", new { id = postId });
                    response.Headers.Location = new Uri(uri);

                    return(response);
                }
            }

            throw new HttpResponseException(HttpStatusCode.BadRequest);
        }