public async Task <GetJobValuationResponse> AddJobValuation(Guid serviceRequestId, CreateJobValuationRequest dto) { var serviceRequest = await _unitOfWork.ServiceRequests.Get(serviceRequestId); // validate if (serviceRequest is null) { throw new KeyNotFoundException("Service request does not exist."); } if (serviceRequest.Status != Status.InProgress) { throw new AppException("This service is not in progress."); } var employee = await _unitOfWork.Employees.Get(new Guid(dto.EmployeeId)); if (employee is null) { throw new KeyNotFoundException("Employee does not exist."); } var newJobValuation = _mapper.Map <JobValuation>(dto); newJobValuation.Id = Guid.NewGuid(); var newSRJobValuation = new ServiceRequestJobValuation() { EmployeeId = employee.Id, JobValuationId = newJobValuation.Id, ServiceRequestId = serviceRequest.Id, Date = DateTime.UtcNow }; _unitOfWork.JobValuations.Add(newJobValuation); _unitOfWork.ServiceRequestJobValuations.Add(newSRJobValuation); _unitOfWork.Commit(); return(_mapper.Map <GetJobValuationResponse>(newJobValuation)); }
public async Task <ActionResult <GetJobValuationResponse> > AddJobValuation(Guid serviceRequestId, [FromBody] CreateJobValuationRequest dto) { return(Ok(await _serviceRequestService.AddJobValuation(serviceRequestId, dto))); }