コード例 #1
0
        public async Task <IActionResult> PostRootJobs(Guid siteId, [FromBody] RootJobCreateRequestDto model)
        {
            var oid  = _authService.GetRequestOid(Request);
            var site = await _appDbContext.Sites.FirstOrDefaultAsync(s => s.Id == siteId && s.IsActive && s.Oid == oid);

            if (site != null)
            {
                var mappedJob = _mapper.Map <Job>(model);

                var user = await _userManager.GetUserAsync(User);

                await _resourceService.CreateJobAsync(site, mappedJob, oid, user, true);

                await _resourceService.FlushCacheForNewRootJobAsync(Request, Url, oid);

                return(CreatedAtRoute(nameof(JobsController.GetJobsDetail), new { jobId = mappedJob.Id }, _mapper.Map <JobReadResponseDto>(mappedJob)));
            }

            return(NotFound());
        }
コード例 #2
0
        public async Task <IActionResult> PostJobs([FromBody] NonRootJobCreateRequestDto model)
        {
            var oid       = _authService.GetRequestOid(Request);
            var parentJob = await _appDbContext.Jobs.FirstOrDefaultAsync(j => j.Oid == oid && j.IsActive && j.Id == model.ParentJobId);

            if (parentJob != null)
            {
                var mappedJob = _mapper.Map <Job>(model);

                var user = await _userManager.GetUserAsync(User);

                var site = await _appDbContext.Sites.FirstOrDefaultAsync(s => s.Id == parentJob.SiteId);

                await _resourceService.CreateJobAsync(site, mappedJob, oid, user, false); // Not a root job, the parentJobId is already mapped in by the IMapper, so IsRoot = false.

                await _resourceService.FlushCacheForNewNonRootJobAsync(Request, Url, oid, parentJob.Id);

                return(CreatedAtRoute(nameof(GetJobsDetail), new { jobId = mappedJob.Id }, _mapper.Map <JobReadResponseDto>(mappedJob)));
            }
            return(NotFound());
        }