Exemple #1
0
        public async Task <Result> DeleteDeveloperAsync(Guid id)
        {
            var existDeveloper = await _developerRepository.ExistAsync(id);

            if (!existDeveloper)
            {
                return(new Result(Status.NotFund, $"Developer with {nameof(id)} does not exist"));
            }

            var developer = await _developerRepository.GetByIdAsync(id);

            await _developerRepository.DeleteAsync(developer);

            return(new Result());
        }
        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());
        }