コード例 #1
0
        public Worker CreateWorker(CreateWorkerRequest createWorkerRequest)
        {
            if (GetWorkerByEmail(createWorkerRequest.EmailAddress) != null)
            {
                throw new PostWorkerException($"Worker with Email {createWorkerRequest.EmailAddress} already exists");
            }

            var worker = new Worker
            {
                Role           = createWorkerRequest.Role,
                Email          = createWorkerRequest.EmailAddress,
                FirstName      = createWorkerRequest.FirstName,
                LastName       = createWorkerRequest.LastName,
                IsActive       = true,
                CreatedBy      = createWorkerRequest.CreatedBy,
                ContextFlag    = createWorkerRequest.ContextFlag,
                DateStart      = createWorkerRequest.DateStart,
                DateEnd        = null,
                LastModifiedBy = createWorkerRequest.CreatedBy
            };

            var workerTeams = GetTeams(createWorkerRequest.Teams);

            worker.WorkerTeams = new List <WorkerTeam>();
            foreach (var team in workerTeams)
            {
                worker.WorkerTeams.Add(new WorkerTeam {
                    Team = team, Worker = worker
                });
            }

            _databaseContext.Workers.Add(worker);
            _databaseContext.SaveChanges();
            return(worker);
        }
コード例 #2
0
        public IActionResult CreateWorker([FromBody] CreateWorkerRequest request)
        {
            var validator         = new CreateWorkerRequestValidator();
            var validationResults = validator.Validate(request);

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

            try
            {
                var createdWorker = _workersUseCase.ExecutePost(request);
                return(CreatedAtAction(nameof(CreateWorker), createdWorker));
            }
            catch (PostWorkerException e)
            {
                return(UnprocessableEntity(e.Message));
            }
        }
コード例 #3
0
 public WorkerResponse ExecutePost(CreateWorkerRequest createWorkerRequest)
 {
     return(_databaseGateway.CreateWorker(createWorkerRequest).ToDomain(true).ToResponse());
 }