コード例 #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 CanMapCreateAllocationRequestDomainObjectToDatabaseEntity()
        {
            var personId   = _faker.Random.Long();
            var createdBy  = _faker.Internet.Email();
            var workerId   = _faker.Random.Number();
            var dt         = DateTime.Now;
            var caseStatus = "Open";

            var allocationRequest = new CreateAllocationRequest()
            {
                MosaicId          = personId,
                CreatedBy         = createdBy,
                AllocatedWorkerId = workerId
            };

            var expectedResponse = new AllocationSet()
            {
                PersonId            = personId,
                WorkerId            = workerId,
                AllocationStartDate = dt,
                CaseStatus          = caseStatus,
                CreatedBy           = createdBy
            };

            allocationRequest.ToEntity(workerId, dt, caseStatus).Should().BeEquivalentTo(expectedResponse);
        }
コード例 #3
0
 public static AllocationSet ToEntity(this CreateAllocationRequest request, int workerId, DateTime allocationStartDate, string caseStatus)
 {
     return(new AllocationSet
     {
         PersonId = request.MosaicId,
         WorkerId = workerId,
         AllocationStartDate = allocationStartDate,
         CaseStatus = caseStatus,
         CreatedBy = request.CreatedBy
     });
 }
コード例 #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);
        }
        public IActionResult CreateAllocation([FromBody] CreateAllocationRequest request)
        {
            var validator         = new CreateAllocationRequestValidator();
            var validationResults = validator.Validate(request);

            if (!validationResults.IsValid)
            {
                return(BadRequest(validationResults.ToString()));
            }

            try
            {
                var result = _allocationUseCase.ExecutePost(request);
                return(CreatedAtAction("CreateAllocation", result, result));
            }
            catch (CreateAllocationException ex)
            {
                return(NotFound(ex.Message));
            }
            catch (UpdateAllocationException ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }
コード例 #6
0
 public CreateAllocationResponse ExecutePost(CreateAllocationRequest request)
 {
     return(_databaseGateway.CreateAllocation(request));
 }
コード例 #7
0
        private (Domain.Worker, Team, Person, Worker) GetCreateAllocationRequirements(CreateAllocationRequest request)
        {
            var worker = _workerGateway.GetWorkerByWorkerId(request.AllocatedWorkerId);

            if (string.IsNullOrEmpty(worker?.Email))
            {
                throw new CreateAllocationException("Worker details cannot be found");
            }

            var team = _databaseContext.Teams.FirstOrDefault(x => x.Id == request.AllocatedTeamId);

            if (team == null)
            {
                throw new CreateAllocationException("Team details cannot be found");
            }

            var person = _databaseContext.Persons.Where(x => x.Id == request.MosaicId).FirstOrDefault();

            if (person == null)
            {
                throw new CreateAllocationException($"Person with given id ({request.MosaicId}) not found");
            }

            var allocatedBy = _databaseContext.Workers.Where(x => x.Email.ToUpper().Equals(request.CreatedBy.ToUpper()))
                              .FirstOrDefault();

            if (allocatedBy == null)
            {
                throw new CreateAllocationException(
                          $"Worker with given allocated by email address ({request.CreatedBy}) not found");
            }

            return(worker, team, person, allocatedBy);
        }