public int Post(CommentAddRequest model) { int Id = 0; DataProvider.ExecuteNonQuery("dbo.Comments_Comment_Insert", inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@commentText", model.CommentText); paramCollection.AddWithValue("@tableKeyId", model.TableKeyId); paramCollection.AddWithValue("@tableName", model.TableName); paramCollection.AddWithValue("@createdById", model.CreatedById); paramCollection.AddWithValue("@modifiedById", model.ModifiedById); paramCollection.AddWithValue("@parentCommentId", model.ParentCommentId); SqlParameter paramId = new SqlParameter("@id", SqlDbType.Int); paramId.Direction = ParameterDirection.Output; paramId.Value = Id; paramCollection.Add(paramId); }, returnParameters : delegate(SqlParameterCollection paramCollection) { int.TryParse(paramCollection["@id"].Value.ToString(), out Id); } ); return(Id); }
public ActionResult <ItemResponse <int> > Add(CommentAddRequest model) { ObjectResult result = null; int userId = _authService.GetCurrentUserId(); try { int id = _service.Add(model, userId); ItemResponse <int> response = new ItemResponse <int>() { Item = id }; result = Created201(response); } catch (Exception ex) { Logger.LogError(ex.ToString()); ErrorResponse response = new ErrorResponse(ex.Message); result = StatusCode(500, response); } return(result); }
public IHttpActionResult Post(CommentAddRequest model) { try { model.CreatedById = _authenticationService.GetCurrentUserId(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ItemResponse <int> response = new ItemResponse <int> { Item = _commentService.Post(model) }; return(Ok(response)); } catch (Exception ex) { _errorLogService.Post(new Models.Requests.Logs.ErrorLogAddRequest { ErrorSourceTypeId = 1, Message = ex.Message, StackTrace = ex.StackTrace, Title = "Error in " + GetType().Name + " " + System.Reflection.MethodBase.GetCurrentMethod().Name }); return(BadRequest(ex.Message)); } }
public int Add(CommentAddRequest request, int userId) { int commentId = 0; _dataProvider.ExecuteNonQuery("dbo.Comments_Insert" , inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@Title", request.Title); paramCollection.AddWithValue("@Comment", request.Comment); paramCollection.AddWithValue("@ParentId", request.ParentId); paramCollection.AddWithValue("@OwnerId", request.OwnerId); paramCollection.AddWithValue("@OwnerTypeId", request.OwnerTypeId); paramCollection.AddWithValue("@UserId", userId); SqlParameter idParameter = new SqlParameter("@Id", SqlDbType.Int); idParameter.Direction = ParameterDirection.Output; paramCollection.Add(idParameter); }, returnParameters : delegate(SqlParameterCollection param) { Int32.TryParse(param["@Id"].Value.ToString(), out commentId); } ); return(commentId); }
public int Add(CommentAddRequest model, int userId) { int id = 0; string procName = "[dbo].[Comments_Insert]"; _data.ExecuteNonQuery(procName, inputParamMapper : delegate(SqlParameterCollection col) { MapAddWithValue(model, col); col.AddWithValue("@CreatedBy", userId); SqlParameter idOut = new SqlParameter("@Id", SqlDbType.Int); idOut.Direction = ParameterDirection.Output; col.Add(idOut); }, returnParameters : delegate(SqlParameterCollection returnCollection) { object oId = returnCollection["@Id"].Value; int.TryParse(oId.ToString(), out id); }); return(id); }
private SetCommentToneMessage CreateCommentMessage(CommentAddRequest request) { return(new SetCommentToneMessage { Id = request.Id, Comment = request.comment }); }
public static void MapAddWithValue(CommentAddRequest model, SqlParameterCollection col) { col.AddWithValue("@Subject", model.Subject); col.AddWithValue("@Text", model.Text); col.AddWithValue("@ParentId", model.ParentId); col.AddWithValue("@EntityTypeId", model.EntityTypeId); col.AddWithValue("@EntityId", model.EntityId); }
private static void SqlCollection(CommentAddRequest model, SqlParameterCollection col, int UserId) { col.AddWithValue("@Subject", model.Subject); col.AddWithValue("@Text", model.Text); col.AddWithValue("@ParentId", model.ParentId); col.AddWithValue("@EntityTypeId", model.EntityTypeId); col.AddWithValue("@EntityId", model.EntityId); col.AddWithValue("@CreatedBy", UserId); col.AddWithValue("@isDeleted", model.IsDeleted); }
public async Task <IActionResult> Post(CommentAddRequest request) { Outcome <int> outcome = await _commentService.AddCommentAsync(request); if (!outcome.Successful) { return(RequestError(outcome)); } return(CreatedAtAction(nameof(Get), new { commentId = outcome.Result }, null)); }
public HttpResponseMessage Add(CommentAddRequest request) { if (!ModelState.IsValid || request == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } int commentId = _commentsService.Add(request, _currentUser.Id); ItemResponse <int> response = new ItemResponse <int>(); response.Item = commentId; return(Request.CreateResponse(HttpStatusCode.OK, response)); }
public HttpResponseMessage Add(CommentAddRequest model) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } ItemResponse<int> response = new ItemResponse<int>(); string userId = UserService.GetCurrentUserId(); response.Item = _commentsService.Insert(model, userId); return Request.CreateResponse(response); }
public HttpResponseMessage Add(CommentAddRequest model) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } ItemResponse <int> response = new ItemResponse <int>(); string userId = UserService.GetCurrentUserId(); response.Item = _commentsService.Insert(model, userId); return(Request.CreateResponse(response)); }
public int Create(CommentAddRequest model) { int id = 0; Adapter.ExecuteQuery( "Comments_Comment_Insert", new[] { SqlDbParameter.Instance.BuildParameter("@commentText", model.CommentText, SqlDbType.NVarChar), SqlDbParameter.Instance.BuildParameter("@username", model.Username, SqlDbType.NVarChar), SqlDbParameter.Instance.BuildParameter("@id", id, System.Data.SqlDbType.Int, 0, ParameterDirection.Output), }, (parameters => { id = parameters.GetParamValue <int>("@id"); })); return(id); }
[HttpPost] // <== type of http methods supported public HttpResponseMessage CreateComment([FromBody] CommentAddRequest payload) { if (string.IsNullOrWhiteSpace(payload.Title) || string.IsNullOrWhiteSpace(payload.Content) || string.IsNullOrWhiteSpace(payload.UserName) || payload.BlogPostId <= 0) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } // create our response model ItemResponse <int> response = new ItemResponse <int>(); response.Item = CommentService.CommentInsert(payload.BlogPostId, payload.ParentCommentId, payload.UserName, payload.Title, payload.Content); return(Request.CreateResponse(response)); } //CreateComment
public IHttpActionResult Post(CommentAddRequest model) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ItemResponse <int> response = new ItemResponse <int> { Item = _commentService.Create(model) }; return(Ok(response)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <Outcome <int> > AddCommentAsync(CommentAddRequest request) { var comment = await _repository.GetAsync(request.Id); if (comment != null) { return(Outcome.Fail <int>(Status409Conflict, DuplicateCommentId)); } comment = CommentMappingHelper.MapToComment(request); await _repository.AddAsync(comment); await _repository.SaveAsync(); // Publish message to ServiceBus to trigger function to // get comment tone await _queueClient.SendAsync(CreateCommentMessage(request)); return(Outcome.Success(comment.Id)); }
public ActionResult <ItemResponse <int> > Create(CommentAddRequest req, int userId) { ActionResult result = null; ItemResponse <int> response = null; try { userId = _authService.GetCurrentUserId(); int newId = _commentService.Insert(req, userId); response = new ItemResponse <int>(); response.Item = newId; result = Created201(response); } catch (Exception ex) { Logger.LogError(ex.ToString()); result = StatusCode(500, new ErrorResponse(ex.ToString())); } return(result); }
public int Insert(CommentAddRequest model, string userId) { var id = 0; DataProvider.ExecuteNonQuery(GetConnection, "dbo.Comments_Insert" , inputParamMapper : delegate(SqlParameterCollection commentsCollection) { commentsCollection.AddWithValue("@UserId", userId); commentsCollection.AddWithValue("@OwnerId", model.OwnerId); commentsCollection.AddWithValue("@OwnerTypeId", model.OwnerTypeId); commentsCollection.AddWithValue("@Title", model.Title); commentsCollection.AddWithValue("@Body", model.Body); commentsCollection.AddWithValue("@ParentId", model.ParentId); SqlParameter p = new SqlParameter("@Id", System.Data.SqlDbType.Int); p.Direction = System.Data.ParameterDirection.Output; commentsCollection.Add(p); }, returnParameters : delegate(SqlParameterCollection param) { int.TryParse(param["@Id"].Value.ToString(), out id); }); return(id); }