コード例 #1
0
        public CreateAllocationResponse CreateAllocation(CreateAllocationRequest request)
        {
            var(worker, team, person, allocatedBy) = GetCreateAllocationRequirements(request);

            var allocation = new AllocationSet
            {
                PersonId            = person.Id,
                WorkerId            = worker.Id,
                TeamId              = team.Id,
                AllocationStartDate = request.AllocationStartDate,
                CaseStatus          = "Open",
                CreatedBy           = allocatedBy.Email
            };

            _databaseContext.Allocations.Add(allocation);
            _databaseContext.SaveChanges();


            var response = new CreateAllocationResponse();

            //Add note
            try
            {
                var dt = DateTime.Now;

                var note = new AllocationCaseNote
                {
                    FirstName   = person.FirstName,
                    LastName    = person.LastName,
                    MosaicId    = person.Id.ToString(),
                    Timestamp   = dt.ToString("dd/MM/yyyy H:mm:ss"), //in line with imported form data
                    WorkerEmail = allocatedBy.Email,
                    Note        =
                        $"{dt.ToShortDateString()} | Allocation | {worker.FirstName} {worker.LastName} in {team.Name} was allocated to this person (by {allocatedBy.FirstName} {allocatedBy.LastName})",
                    FormNameOverall = "API_Allocation",
                    FormName        = "Worker allocated",
                    AllocationId    = allocation.Id.ToString(),
                    CreatedBy       = request.CreatedBy
                };

                var caseNotesDocument = new CaseNotesDocument()
                {
                    CaseFormData = JsonConvert.SerializeObject(note)
                };

                response.CaseNoteId   = _processDataGateway.InsertCaseNoteDocument(caseNotesDocument).Result;
                response.AllocationId = allocation.Id;
            }
            catch (Exception ex)
            {
                //roll back allocation record
                _databaseContext.Allocations.Remove(allocation);
                _databaseContext.SaveChanges();

                throw new UpdateAllocationException(
                          $"Unable to create a case note. Allocation not created: {ex.Message}");
            }

            return(response);
        }
コード例 #2
0
        public void CreateAllocationReturns201WhenSuccessful()
        {
            var request        = TestHelpers.CreateAllocationRequest().Item1;
            var responseObject = new CreateAllocationResponse();

            _mockAllocationsUseCase.Setup(x => x.ExecutePost(request))
            .Returns(responseObject);

            var response = _classUnderTest.CreateAllocation(request) as CreatedAtActionResult;

            response?.StatusCode.Should().Be(201);
            response?.Value.Should().BeEquivalentTo(responseObject);
        }
コード例 #3
0
        public void ExecuteReturnsTheResponse()
        {
            var responseObject = new CreateAllocationResponse()
            {
                CaseNoteId = _fixture.Create <string>()
            };

            _mockDatabaseGateway.Setup(x => x.CreateAllocation(It.IsAny <CreateAllocationRequest>()))
            .Returns(responseObject);

            var response = _allocationsUseCase.ExecutePost(new CreateAllocationRequest());

            response.Should().BeEquivalentTo(responseObject);
        }
コード例 #4
0
        public async Task <CreateAllocationResponse> MapPopupInfo(CreateAllocationRequest req)
        {
            //  var userId = (string)HttpContext.Items["User"];

            //UserDetailsRequest userDetailsRequest = new UserDetailsRequest();
            //userDetailsRequest.id = userId;

            //var userDetails = await _kistService.UsersDetails(userDetailsRequest);
            // loop through assets to be allocated

            var res = new CreateAllocationResponse();

            foreach (long id in req.AssetID)
            {
                await _kistService.CreateAllocation(req.ParentId, id, req.siteId, req.status);
            }


            return(res);
        }