예제 #1
0
        /// <summary>
        /// Create New Post
        /// </summary>
        /// <param name="postVM">PostViewModel</param>
        /// <returns></returns>
        public HttpResponseMessage PostPost(PostViewModel postVM)
        {
            if (ModelState.IsValid)
            {
                string userName = User.Identity.Name;

                var user = userBLL.GetUserByUserName(userName);

                postVM.UserId = user.Id;

                string postId = postBLL.CreatePost(postVM);

                postVM = postBLL.GetPostByID(postId);

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

                // Send Notification using SignalR
                friendHub.Value.Clients.All.showUpdatedPost();

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

                return(response);
            }
        }