public async Task <ActionResult <JobDetailedDTO> > UpdateJob(int id, JobDTO jobDTO)
        {
            var job = _mapper.Map <Job>(jobDTO);

            if (job.JobId != id)
            {
                return(BadRequest());
            }
            if (!_context.Jobs.Where(x => x.JobId == job.JobId).Any())
            {
                await _jobService.Create(job);

                return(_mapper.Map <JobDetailedDTO>(job));
            }
            try
            {
                job = await _jobService.Update(job);

                foreach (JobStage stage in job.JobStages)
                {
                    await _jobStageService.Update(stage);
                }
            }
            catch
            {
                return(BadRequest());
            }
            if (job == null)
            {
                return(NotFound());
            }
            return(_mapper.Map <JobDetailedDTO>(job));
        }
Esempio n. 2
0
        public async Task <ActionResult <JobStageDetailedDTO> > UpdateJobStage(int id, JobStageDTO jobStageDTO)
        {
            var jobStage = _mapper.Map <JobStage>(jobStageDTO);

            if (jobStage.JobStageId != id)
            {
                return(BadRequest());
            }
            if (!_context.JobStages.Where(x => x.JobStageId == jobStage.JobStageId).Any())
            {
                await _jobStageService.Create(jobStage);

                return(_mapper.Map <JobStageDetailedDTO>(jobStage));
            }
            jobStage = await _jobStageService.Update(jobStage);

            if (jobStage == null)
            {
                return(NotFound());
            }
            return(_mapper.Map <JobStageDetailedDTO>(jobStage));
        }