コード例 #1
0
        public async Task <ActionResult> UpdateJob(int industryId, Guid jobId, [FromBody] JobForUpdateDto request)
        {
            if (!IndustryType.TryFromValue(industryId, out IndustryType industryType))
            {
                return(NotFound());
            }

            var existingJob = await _repository.GetByIdAsync(new GetJobWithTasksSpecification(new JobId(jobId)));

            if (existingJob == null || existingJob.IndustryId != industryType.Value)
            {
                return(NotFound());
            }

            existingJob.UpdateTitleAndDescription(new TitleAndDescription(request.Title, request.Description));

            // PUT is a full update, so we need to clear all job tasks
            existingJob.ClearAllJobTasks();

            if (request.JobTasks.Any())
            {
                foreach (var jobTask in request.JobTasks)
                {
                    existingJob.AddNewJobTask(
                        new TitleAndDescription(jobTask.Title, jobTask.Description)
                        );
                }
            }

            await _repository.UpdateAsync(existingJob);

            return(NoContent());
        }
コード例 #2
0
        public async Task <IActionResult> UpdateJob(int userId, string jobNum, JobForUpdateDto jobForUpdateDto)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var jobFromRepo = await _repo.GetJob(userId, jobNum);

            _mapper.Map(jobForUpdateDto, jobFromRepo);

            if (await _repo.SaveAll())
            {
                return(CreatedAtRoute("GetJob", new { jobNum = jobFromRepo.JobNumber, userId = userId }, jobForUpdateDto));
            }

            var newData = _mapper.Map(jobForUpdateDto, jobFromRepo);

            if (jobFromRepo == newData)
            {
                return(Ok(jobForUpdateDto));
            }

            throw new Exception($"Updating job lot {jobNum} failed on save");
        }
コード例 #3
0
        public async Task <IActionResult> UpdateJob([FromRoute] int id, [FromBody] JobForUpdateDto jobForUpdateDto)
        {
            var jobFromRepo = await _repo.GetJob(id);

            _mapper.Map(jobForUpdateDto, jobFromRepo);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }
            throw new Exception($"حدثت مشكلة في تعديل بيانات المشترك رقم {id}");
        }
コード例 #4
0
        public async Task <IActionResult> UpdateJob([FromBody] JobForUpdateDto jobForUpdateDto, int id)
        {
            // jobForUpdateDto.UnitPrice.Remove(0, 1);
            // decimal.Parse(jobForUpdateDto.UnitPrice);
            // jobForUpdateDto.LineValue.Remove(0, 1);
            // decimal.Parse(jobForUpdateDto.LineValue);

            var job = await _context.Jobs.FindAsync(id);

            _mapper.Map <JobForUpdateDto, Job>(jobForUpdateDto, job);
            job.LastModified = DateTime.Now;

            await _context.SaveChangesAsync();

            return(Ok(_mapper.Map <Job, JobForUpdateDto>(job)));
        }