public async Task <ResponseDto> CreateAsync(WorkCreateRequestDto request) { const string methodName = ClassName + "." + nameof(CreateAsync); var response = new ResponseDto(); var mappingResponse = _workMappingHelper.MapCreateToEntity(request); if (mappingResponse.Success) { var createResponse = await _workRepository.CreateAsync(mappingResponse.Result); if (createResponse.Success) { response.SetSuccess(); } else { response.SetError(createResponse.ErrorId, createResponse.Message, methodName, createResponse.ResponseType); } } else { response.SetError(mappingResponse.ErrorId, mappingResponse.Message, methodName, mappingResponse.ResponseType); } return(response); }
public async Task <Result> CreateWorkAsync(WorkCreateDto workDto) { var resultValidation = ValidateRanteDateTime(workDto.StartTime, workDto.EndTime); if (!resultValidation.Success) { return(resultValidation); } var existProject = await _projectRepository.ExistAsync(workDto.ProjectId); if (!existProject) { return(new Result(Status.NotFund, $"Project with {nameof(workDto.ProjectId)} does not exist")); } var existDeveloper = await _developerRepository.ExistAsync(workDto.DeveloperId); if (!existDeveloper) { return(new Result(Status.NotFund, $"Developer with {nameof(workDto.DeveloperId)} does not exist")); } var developerVinculatedProject = await _projectRepository.ExistDeveloperVinculatedAsync(workDto.ProjectId, workDto.DeveloperId); if (!developerVinculatedProject) { return(new Result(Status.NotAllowed, $"Developer is not vinculated in Project")); } var developerProjectId = await _projectRepository.GetDeveloperProjectIdAsync(workDto.ProjectId, workDto.DeveloperId); var work = new Work( id: workDto.Id, developerProjectId: developerProjectId, startTime: workDto.StartTime, endTime: workDto.EndTime, comment: workDto.Comment, hours: workDto.Hours ); await _workRepository.CreateAsync(work); var result = await _mockyService.SendNotificationAsync("Lançamento de horas", "Um novo lançamento de horas foi realizado"); if (!result.Success || !result.Data) { return(new Result(Status.Error, result.ErrorMessages)); } return(new Result()); }