Esempio n. 1
0
        public bool Execute(IUseCaseOutput <AddUseCaseResponse> output, AddUseCaseInitialRequest request)
        {
            try
            {
                if (!request.Validate(out var errors))
                {
                    return(output.Accept(new ValidationErrorResponse(errors, "Invalid request.")));
                }

                var rights = _securityGateway.GetProjectRights(request.ProjectId, request.RequestedBy);
                if (rights == null || !rights.CanChangeUseCases)
                {
                    return(output.Accept(new FailureResponse("User can't change use cases of this. project")));
                }

                var user    = _userRepository.ReadUserInfo(request.RequestedBy);
                var project = _projectRepository.ReadProject(request.ProjectId, false, false);

                return(output.Accept(new AddUseCaseResponse
                {
                    ProjectId = project.Id,
                    ProjectName = project.Name,
                }));
            }
            catch (EntityNotFoundException e)
            {
                return(output.Accept(new FailureResponse($"Entity not found. {e.Message}")));
            }
            catch (Exception e)
            {
                return(output.Accept(new FailureResponse($"Tehnical error happend. {e.Message}")));
            }
        }
Esempio n. 2
0
        public bool Execute(IUseCaseOutput <ChangeInformationResponse> output, ChangeInformationInitialRequest request)
        {
            try
            {
                if (!request.Validate(out var errors))
                {
                    return(output.Accept(new ValidationErrorResponse(errors, "Invalid request.")));
                }

                var rights = _securityGateway.GetProjectRights(request.ProjectId, request.RequestedBy);
                if (!rights.IsAdministrator)
                {
                    return(output.Accept(new FailureResponse("User can't change information of the project.")));
                }

                var project = _projectRepository.ReadProject(request.ProjectId, false, false);

                return(output.Accept(new ChangeInformationResponse
                {
                    ProjectId = project.Id,
                    Name = project.Name,
                    Description = project.Description,
                }));
            }
            catch (EntityNotFoundException e)
            {
                return(output.Accept(new FailureResponse($"Entity not found. {e.Message}")));
            }
            catch (Exception e)
            {
                return(output.Accept(new FailureResponse($"Tehnical error happend. {e.Message}")));
            }
        }
Esempio n. 3
0
        public bool Execute(IUseCaseOutput <DeleteUseCaseResponse> output, DeleteUseCaseRequest request)
        {
            try
            {
                if (!request.Validate(out var errors))
                {
                    return(output.Accept(new ValidationErrorResponse(errors, "Invalid request.")));
                }

                var rights = _securityGateway.GetProjectRights(request.ProjectId, request.RequestedBy);

                if (rights == null || !rights.CanChangeUseCases)
                {
                    return(output.Accept(new FailureResponse("User can't change use cases of this project.")));
                }

                if (!_useCaseRepository.DeleteUseCase(request.UseCaseId))
                {
                    return(output.Accept(new FailureResponse("Use case couldn't be deleted.")));
                }

                return(output.Accept(new DeleteUseCaseResponse
                {
                    Message = "Use case deleted successfully",
                }));
            }
            catch (EntityNotFoundException e)
            {
                return(output.Accept(new FailureResponse($"Entity not found. {e.Message}")));
            }
            catch (Exception e)
            {
                return(output.Accept(new FailureResponse($"Tehnical error happend. {e.Message}")));
            }
        }
Esempio n. 4
0
        public bool Execute(IUseCaseOutput <ViewProjectResponse> output, ViewProjectRequest request)
        {
            try
            {
                if (!request.Validate(out var errors))
                {
                    return(output.Accept(new ValidationErrorResponse(errors, "Invalid request.")));
                }

                var rights = _securityGateway.GetProjectRights(request.ProjectId, request.RequestedBy);
                if (rights == null || !rights.CanViewProject)
                {
                    return(output.Accept(new FailureResponse("User can't view this project.")));
                }

                var project = _projectRepository.ReadProject(request.ProjectId, request.ShowRequirements, request.ShowUseCases);

                return(output.Accept(new ViewProjectResponse
                {
                    Name = project.Name,
                    Description = project.Description,
                    ProjectId = request.ProjectId,
                    Author = new User
                    {
                        Id = project.Author.Id,
                        Name = project.Author.DisplayName,
                    },
                    Rights = new ProjectRights
                    {
                        UserName = request.RequestedBy,
                        CanViewProject = rights.CanViewProject,
                        CanChangeRequirements = rights.CanChangeRequirements,
                        CanChangeUseCases = rights.CanChangeUseCases,
                        CanChangeProjectRights = rights.CanChangeProjectRights,
                        IsAdministrator = rights.IsAdministrator,
                    },
                    Requirements = project.Requirements?.Select(r => new Requirement
                    {
                        Id = r.Id,
                        Type = r.Type.ToString(),
                        Title = r.Title,
                    }) ?? new List <Requirement>(),
                    UseCases = project.UseCases?.Select(r => new UseCase
                    {
                        Id = r.Id,
                        Title = r.Title,
                    }) ?? new List <UseCase>(),
                    ShowRequirements = request.ShowRequirements,
                    ShowUseCases = request.ShowUseCases,
                }));
            }
            catch (EntityNotFoundException e)
            {
                return(output.Accept(new FailureResponse($"Entity not found. {e.Message}")));
            }
            catch (Exception e)
            {
                return(output.Accept(new FailureResponse($"Tehnical error happend. {e.Message}")));
            }
        }
        public bool Execute(IUseCaseOutput <ChangeRightsResponse> output, ChangeRightsInitialRequest request)
        {
            try
            {
                if (!request.Validate(out var errors))
                {
                    return(output.Accept(new ValidationErrorResponse(errors, "Invalid request.")));
                }

                var userRights = _securityGateway.GetProjectRights(request.ProjectId, request.RequestedBy);
                if (userRights == null || !userRights.CanChangeProjectRights)
                {
                    return(output.Accept(new FailureResponse("User can't change information of this project.")));
                }

                var rights = _securityGateway.GetProjectRights(request.ProjectId);

                var project = _projectRepository.ReadProject(request.ProjectId, false, false);

                return(output.Accept(new ChangeRightsResponse
                {
                    ProjectId = request.ProjectId,
                    Name = project.Name,
                    Rights = rights.Select(r => new ProjectRights
                    {
                        UserName = r.UserName,
                        CanViewProject = r.CanViewProject,
                        CanChangeRequirements = r.CanChangeRequirements,
                        CanChangeUseCases = r.CanChangeUseCases,
                        CanChangeProjectRights = r.CanChangeProjectRights,
                        IsAdministrator = r.IsAdministrator,
                    }),
                }));
            }
            catch (EntityNotFoundException e)
            {
                return(output.Accept(new FailureResponse($"Entity not found. {e.Message}")));
            }
            catch (Exception e)
            {
                return(output.Accept(new FailureResponse($"Tehnical error happend. {e.Message}")));
            }
        }
Esempio n. 6
0
        public bool Execute(IUseCaseOutput <ChangeRequirementOrderResponse> output, ChangeRequirementOrderInitialRequest request)
        {
            try
            {
                if (!request.Validate(out var errors))
                {
                    return(output.Accept(new ValidationErrorResponse(errors, "Invalid request.")));
                }

                var rights = _securityGateway.GetProjectRights(request.ProjectId, request.RequestedBy);
                if (rights == null || !rights.CanChangeRequirements)
                {
                    return(output.Accept(new FailureResponse("User can't change requirements of this project.")));
                }

                var project = _projectRepository.ReadProjectRequirements(request.ProjectId, Enum.Parse <RequirementType>(request.Type));

                return(output.Accept(new ChangeRequirementOrderResponse
                {
                    Name = project.Name,
                    ProjectId = request.ProjectId,
                    Type = request.Type,
                    Requirements = project.Requirements.Select(r => new Requirement
                    {
                        Id = r.Id,
                        Title = r.Title,
                    }),
                }));
            }
            catch (EntityNotFoundException e)
            {
                return(output.Accept(new FailureResponse($"Entity not found. {e.Message}")));
            }
            catch (Exception e)
            {
                return(output.Accept(new FailureResponse($"Tehnical error happend. {e.Message}")));
            }
        }
Esempio n. 7
0
        public bool Execute(IUseCaseOutput <AddRequirementResponse> output, AddRequirementInitialRequest request)
        {
            if (!request.Validate(out var errors))
            {
                return(output.Accept(new ValidationErrorResponse(errors, "Invalid request.")));
            }

            var rights = _securityGateway.GetProjectRights(request.ProjectId, request.RequestedBy);

            if (rights == null || !rights.CanChangeRequirements)
            {
                return(output.Accept(new FailureResponse("User can't change requirements of this project.")));
            }

            var project = _projectRepository.ReadProject(request.ProjectId, false, false);

            return(output.Accept(new AddRequirementResponse
            {
                ProjectId = request.ProjectId,
                ProjectName = project.Name,
                Types = new[] { "Bussiness", "User", "Functional", "Nonfunctional" },
            }));
        }
Esempio n. 8
0
        public bool Execute(IUseCaseOutput <ChangeRequirementResponse> output, ChangeRequirementInitialRequest request)
        {
            try
            {
                if (!request.Validate(out var errors))
                {
                    return(output.Accept(new ValidationErrorResponse(errors, "Invalid request.")));
                }

                var rights = _securityGateway.GetProjectRights(request.ProjectId, request.RequestedBy);
                if (rights == null || !rights.CanChangeRequirements)
                {
                    return(output.Accept(new FailureResponse("User can't change requirements of this project.")));
                }

                var requirement = _requirementRepository.ReadRequirement(request.RequirementId);

                return(output.Accept(new ChangeRequirementResponse
                {
                    ProjectId = requirement.Project.Id,
                    ProjectName = requirement.Project.Name,
                    RequirementId = requirement.Id,
                    Type = requirement.Type.ToString(),
                    Title = requirement.Title,
                    Note = requirement.Note,
                    Types = new[] { "Bussiness", "User", "Functional", "Nonfunctional" },
                }));
            }
            catch (EntityNotFoundException e)
            {
                return(output.Accept(new FailureResponse($"Entity not found. {e.Message}")));
            }
            catch (Exception e)
            {
                return(output.Accept(new FailureResponse($"Tehnical error happend. {e.Message}")));
            }
        }
Esempio n. 9
0
        public bool Execute(IUseCaseOutput <ChangeUseCaseResponse> output, ChangeUseCaseInitialRequest request)
        {
            try
            {
                if (!request.Validate(out var errors))
                {
                    return(output.Accept(new ValidationErrorResponse(errors, "Invalid request.")));
                }

                var rights = _securityGateway.GetProjectRights(request.ProjectId, request.RequestedBy);
                if (rights == null || !rights.CanChangeUseCases)
                {
                    return(output.Accept(new FailureResponse("User can't change use cases of this project.")));
                }

                var useCase = _useCaseRepository.ReadUseCase(request.UseCaseId);

                return(output.Accept(new ChangeUseCaseResponse
                {
                    ProjectId = useCase.Project.Id,
                    ProjectName = useCase.Project.Name,
                    UseCaseId = useCase.Id,
                    Title = useCase.Title,
                    Note = useCase.Note,
                    Steps = useCase.Steps.Select(x => x.Content),
                }));
            }
            catch (EntityNotFoundException e)
            {
                return(output.Accept(new FailureResponse($"Entity not found. {e.Message}")));
            }
            catch (Exception e)
            {
                return(output.Accept(new FailureResponse($"Tehnical error happend. {e.Message}")));
            }
        }
Esempio n. 10
0
        public bool Execute(IUseCaseOutput <ViewRequirementResponse> output, ViewRequirementRequest request)
        {
            try
            {
                if (!request.Validate(out var errors))
                {
                    return(output.Accept(new ValidationErrorResponse(errors, "Invalid request.")));
                }

                var rights = _securityGateway.GetProjectRights(request.ProjectId, request.RequestedBy);
                if (rights == null || !rights.CanViewProject)
                {
                    return(output.Accept(new FailureResponse("User can't view this project.")));
                }

                var requirement = _requirementRepository.ReadRequirement(request.RequirementId);

                return(output.Accept(new ViewRequirementResponse
                {
                    Project = new Project {
                        Id = requirement.Project.Id, Name = requirement.Project.Name
                    },
                    Author = new User {
                        Id = requirement.Author.Id, Name = requirement.Author.DisplayName
                    },
                    RequirementId = requirement.Id,
                    Title = requirement.Title,
                    Type = requirement.Type.ToString(),
                    Note = requirement.Note,
                    CanChange = rights.CanChangeRequirements,
                }));
            }
            catch (EntityNotFoundException e)
            {
                return(output.Accept(new FailureResponse($"Entity not found. {e.Message}")));
            }
            catch (Exception e)
            {
                return(output.Accept(new FailureResponse($"Tehnical error happend. {e.Message}")));
            }
        }