Example #1
0
        public IActionResult CreateWorkItemComment(int workItemId, [FromBody] WorkItemCommentCreateModel workItemComment)
        {
            if (workItemComment == null)
            {
                return(BadRequest("Not a valid request."));
            }

            var workItemUserDetails = new WorkItemUserDetails
            {
                Id    = User.FindFirst("userid")?.Value.NullSafeTrim(),
                Name  = $"{User.FindFirst("firstname")?.Value} {User.FindFirst("lastname")?.Value}".NullSafeTrim(),
                Phone = User.FindFirst("dayphone")?.Value.NullSafeTrim(),
                Email = User.FindFirst("emailaddress")?.Value.NullSafeTrim(),
                Fax   = User.FindFirst("faxnumber")?.Value.NullSafeTrim()
            };

            var addWorkItemCommunicationResponse = _workItemTrackerServiceRepository.CreateWorkItemCommunication(workItemId, workItemUserDetails, workItemComment);

            if (addWorkItemCommunicationResponse.Success == false)
            {
                return(BadRequest(addWorkItemCommunicationResponse.ErrorMessage));
            }

            return(CreatedAtRoute("GetAllWorkItemComments", new { CommunicationId = addWorkItemCommunicationResponse.CommunicationId }));
        }
        private IActionResult AddWorkItemCommunication(int workItemId, WorkItemCommentCreateModel commentModel)
        {
            var workItemCommentsController = new WorkItemCommentsController(
                _workItemTrackerServiceRepositoryMock.Object,
                new Mock <IUrlHelper>().Object);

            workItemCommentsController.ControllerContext.HttpContext = new DefaultHttpContext
            {
                User = Mock.Of <ClaimsPrincipal>(c => c.FindFirst(It.IsAny <string>()) == Any.Claim())
            };

            return(workItemCommentsController.CreateWorkItemComment(workItemId, commentModel));
        }
        public void return_400_when_comment_is_null()
        {
            var workItemId = Any.Int();

            var workItemUserDetails = Any.WorkItemUserDetails();

            WorkItemCommentCreateModel workItemComment = null;

            _workItemTrackerServiceRepositoryMock.Setup(repository => repository
                                                        .CreateWorkItemCommunication(workItemId, workItemUserDetails, null))
            .Returns(new AddWorkItemCommunicationResponse {
                Success = false, CommunicationId = Any.Int()
            });

            var response = AddWorkItemCommunication(workItemId, workItemComment) as BadRequestObjectResult;

            Assert.Equal(400, response.StatusCode);
        }
        public AddWorkItemCommunicationResponse CreateWorkItemCommunication(int workItemId, WorkItemUserDetails workItemUserDetails, WorkItemCommentCreateModel commentModel)
        {
            #region Create 'AddWorkItemCommunicationRequest' request
            var request = CreateBasicRequest <AddWorkItemCommunicationRequest>();

            const int commentMethodIsEBSCONET = 6;

            const int commentFromContactTypeIsCustomer = 1;

            const int commentToContactTypeIsInternal = 3;

            const string commentOrganization = "EBSCO, Inc.";

            request.Communication = new Communication
            {
                WorkItemId                     = workItemId,
                CommunicationMethodId          = commentModel.CommentMethodId ?? commentMethodIsEBSCONET,
                CommunicationFromContactTypeId = commentModel.CommentFromContactTypeId ?? commentFromContactTypeIsCustomer,
                CommunicationToContactTypeId   = commentModel.CommentToContactTypeId ?? commentToContactTypeIsInternal,
                Organization                   = commentModel.Organization ?? commentOrganization,
                ContactName                    = workItemUserDetails.Name,
                ContactPhone                   = workItemUserDetails.Phone,
                ContactEmail                   = workItemUserDetails.Email,
                ContactFax                     = workItemUserDetails.Fax,
                Details           = commentModel.Details,
                IsInCommunication = commentModel.IsInComment,
                CreatedBy         = workItemUserDetails.Id
            };

            request.CorrelationId = Guid.NewGuid().ToString();
            #endregion

            return(ServiceHelper.ExecuteServiceCall(
                       _serviceFactory.Invoke(),
                       x => x.AddWorkItemCommunicationAsync(request)
                       ));
        }
Example #5
0
 private AddWorkItemCommunicationResponse AddWorkItemComment(Func <IWorkItemService> service, WorkItemCommentCreateModel communicationRequest)
 {
     return(new WorkItemTrackerServiceRepository(service).CreateWorkItemCommunication(_workItemId, _workItemUserDetails, communicationRequest));
 }