public async Task InsertTestCommentAsync() { // arrange CommentModel retrieved; CommentInsertModel inserted; using (var contextScope = ContextFactory.Create()) { var activity = await GetTestActivityAsync(); var person = await GetTestPersonAsync(activityId : activity.ActivityId); inserted = new CommentInsertModel() { CommentActivityId = activity.ActivityId, CommentPersonId = person.PersonId, CommentContent = "Here's a comment from the test method." }; // act var newId = await _repository.InsertCommentAsync(inserted); retrieved = await DbContext.QuerySingleOrDefaultAsync <CommentModel>($"Select * from Comment where CommentId = {newId}", commandType : CommandType.Text); } // assert Assert.IsTrue(inserted.CommentContent == retrieved.CommentContent, "Comment Content is not equal"); Assert.IsTrue(inserted.CommentPersonId == retrieved.CommentPersonId, "Comment PersonId is not equal"); Assert.IsTrue(inserted.CommentActivityId == retrieved.CommentActivityId, "Comment ActivityId is not equal"); }
/// <summary> /// this method inserts a new comment record into the Comment db Table /// </summary> /// <param name="model">the comment model containing the details of the new comment</param> /// <returns>the Id value of the new comment</returns> public async Task <ServiceResult <int> > InsertCommentAsync(CommentInsertModel model) { try { // validate var validationResult = _validators.ValidateInsertModel(model); using (var dbScope = ContextFactory.Create()) { var commentId = await _repository.InsertCommentAsync(model); dbScope.Transaction.Commit(); return(validationResult.IsValid ? new ServiceResult <int>(commentId) : new ServiceResult <int>(validationResult.ValidationErrors)); } } catch (Exception x) { return(new ServiceResult <int>(new ValidationError() { FieldName = "InsertCommentAsync", ErrorDetail = x.Message })); } }
public async Task <IActionResult> InsertNote(CommentInsertModel commentModel) { var insertValue = mapper.Map <Comment>(commentModel); await commentManager.Insert(insertValue); return(StatusCode(201)); }
/// <summary> /// this method inserts a new record into the comments table /// </summary> /// <param name="model">this is the data model containing the field values</param> /// <returns>the Id of the new record</returns> public async Task <int> InsertCommentAsync(CommentInsertModel model) { var parameters = new DynamicParameters(model); parameters.Add("NewId", DbType.Int32, direction: ParameterDirection.Output); await DbContext.ExecuteAsync(StoredProcedures.CommentInsert, parameters, commandType : CommandType.StoredProcedure); return(parameters.Get <int>("NewId")); }
/// <summary> /// this method validates the comment model on insert /// </summary> /// <param name="model">the model containing the details of the comment</param> /// <returns>a ValidationResults model</returns> public ValidationResults ValidateInsertModel(CommentInsertModel model) { var returnValue = new ValidationResults(); if (model.CommentContent.Length > 250) { returnValue.ValidationErrors.Add(new ValidationError() { FieldName = "CommentContent", ErrorDetail = "The content is too long." }); } return(returnValue); }
public async Task <ActionResult> InsertCommentAsync(CommentInsertModel comment) { try { _logger.LogInformation("InsertCommentAsync executing..."); var srvResult = await _service.InsertCommentAsync(comment); if (srvResult.IsSuccessful) { return(new OkObjectResult(srvResult.Payload)); } if (srvResult.IsException) { return(Problem(detail: srvResult.Exception.Exception, title: srvResult.Exception.Location)); } return(new BadRequestObjectResult(srvResult.Errors)); } catch (Exception x) { _logger.LogError(x, "InsertCommentAsync"); return(Problem(detail: x.StackTrace, title: x.Message)); } }
public IActionResult Insert(CommentInsertModel category) { category.UserId = User.GetUserId(); return(Ok(_commentService.Insert(category))); }