public int Add(CommentsAddRequest model,string userId) { int id = 0; DataProvider.ExecuteNonQuery(GetConnection, "dbo.Comments_Insert" , inputParamMapper: delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@Comment", model.Comment); paramCollection.AddWithValue("@Title", model.Title); paramCollection.AddWithValue("@ParentId", model.ParentId); paramCollection.AddWithValue("@OwnerId", model.OwnerId); paramCollection.AddWithValue("@OwnerType", model.OwnerType); paramCollection.AddWithValue("@UserId", userId); SqlParameter p = new SqlParameter("@Id", System.Data.SqlDbType.Int); p.Direction = System.Data.ParameterDirection.Output; paramCollection.Add(p); }, returnParameters: delegate(SqlParameterCollection param) { int.TryParse(param["@Id"].Value.ToString(), out id); }); return id; }
public HttpResponseMessage AddComments(CommentsAddRequest model) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); }// If model is not valid give an error. string userId = _userService.GetCurrentUserId(); //Get the userID ItemResponse<int> response = new ItemResponse<int>(); // grabs and packages all the data as "Item" sends it as a response response.Item = _commentService.Add(model, userId); switch (model.OwnerType) //One of these switch models will be executed.. { case (int)CommentOwnerType.QuickQuestions: //If the comment type is a Quick question do this QuickQuestion question = _quickQuestionService.GetQuestionForNotification(model.OwnerId, model.OwnerType); //get question by id if (question != null) // If there is a question present : { User parent = _userService.GetByUserId(question.UserId); //Get the question by User Id, that question is the parent, we cant get to parent without getting question. if (parent != null) //If there is a parent { try { bool emailSent = MailService.SendQuickQuestionReplyEmails(parent.Email, question.Id); //send email with q# } catch (Exception) { return Request.CreateResponse(HttpStatusCode.OK, response); // swallow the exception if no email is sent. we still want to send a success message back to the front end // since the original comment was in fact posted successfully. } } } break; case (int)CommentOwnerType.Forum: List<FollowForumThread> padrino = _forumEmailService.SelectUsersFollowingThread(model.OwnerId); //get the list of user Id's and send email! if (padrino != null) { foreach ( var user in padrino) { try { bool emailFollower = MailService.EmailThreadFollower(user.Email,model.OwnerId); } catch (Exception) { return Request.CreateResponse(HttpStatusCode.OK, response); } } } // @Paul: forum notification logic goes here break; default: // default case is here if we need to do anything when NONE of the other cases are satisfied break; } return Request.CreateResponse(response); }
private static CommentsAddRequest CreateComment(ChatCommentAddRequest model) { CommentsAddRequest comment = new CommentsAddRequest(); comment.Comment = model.Content; comment.OwnerId = model.Id; comment.OwnerType = 12; comment.Title = null; comment.ParentId = null; return comment; }