Exemplo n.º 1
0
        public RequirementsPaginatedQueryResult Handle(RequirementsPaginatedQuery query)
        {
            var skip             = (query.Page - 1) * query.PageSize;
            var currentProjectId = _currentProjectContextId.Get();

            var requirementsQuery = _context.Requirements
                                    .Include(r => r.SpecificationItem.Package)
                                    .Where(r => r.ProjectId == currentProjectId &&
                                           r.IsLastVersion &&
                                           r.SpecificationItem.Active);

            var maxPages = (int)Math.Ceiling(requirementsQuery.Count() / (double)query.PageSize);

            var paginatedQuery = requirementsQuery.OrderBy(r => r.Type)
                                 .ThenBy(r => r.Identifier)
                                 .Include(r => r.RequirementContents)
                                 .Skip(skip)
                                 .Take(query.PageSize);

            var requirements = paginatedQuery.Select(RequirementViewModel.FromModel)
                               .ToList();

            _issueHydration.Hydrate(requirements);

            var result = new RequirementsPaginatedQueryResult(requirements, maxPages);

            return(result);
        }
Exemplo n.º 2
0
        public ClassDiagramsPaginatedQueryResult Handle(ClassDiagramsPaginatedQuery query)
        {
            var skip             = (query.Page - 1) * query.PageSize;
            var currentProjectId = _currentProjectContextId.Get();

            var classDiagramsQuery = _context.ClassDiagrams
                                     .Where(cd => cd.Project.Id == currentProjectId &&
                                            cd.SpecificationItem.Active && cd.IsLastVersion);

            var maxPages = (int)Math.Ceiling(classDiagramsQuery.Count() / (double)query.PageSize);

            var classDiagrams = classDiagramsQuery.OrderBy(cd => cd.Identifier)
                                .Include(cd => cd.Contents)
                                .Include(cd => cd.SpecificationItem.Package)
                                .Where(cd => cd.SpecificationItem.Active)
                                .Skip(skip)
                                .Take(query.PageSize)
                                .Select(ClassDiagramViewModel.FromModel)
                                .ToList();

            _issueHydration.Hydrate(classDiagrams);

            var result = new ClassDiagramsPaginatedQueryResult(classDiagrams, maxPages);

            return(result);
        }
        public void Handle(CreateIssueCommentCommand command)
        {
            var creator = _currentUserRetriever.Get();

            var issueComment = new IssueComment();

            issueComment.Creator = creator;
            issueComment.IssueId = command.IssueId.Value;
            issueComment.Id      = Guid.NewGuid();

            foreach (var item in command.Contents)
            {
                var content = new IssueCommentContent();
                content.Description  = item.Description;
                content.Locale       = item.Locale;
                content.IssueComment = issueComment;
                content.IsUpdated    = true;
                _issueCommentContentRepository.Add(content);
            }

            issueComment.LastModification = DateTime.Now;

            var currentProjectId = _currentProjectContextId.Get();

            if (currentProjectId == null)
            {
                throw new Exception(Sentences.noProjectInContext);
            }

            issueComment.Active    = true;
            issueComment.CreatedAt = DateTime.Now;
            _issueCommentRepository.Add(issueComment);
        }
        public IEnumerable <Permission> Handle(PermissionsByCurrentProjectQuery query)
        {
            var projectId   = _currentProjectContextId.Get();
            var permissions = _context.Permissions
                              .Where(p => p.Project.Id == projectId &&
                                     p.Profile != Profile.ProjectOwner)
                              .ToList();

            return(permissions);
        }
        public ViewResult CurrentProjectDetails()
        {
            var id = _currentProjectContextId.Get();

            if (id == null)
            {
                throw new HttpException(400, Sentences.noProjectInContext);
            }

            return(ProjectDetailsView(id.Value));
        }
Exemplo n.º 6
0
        public IEnumerable <PackageViewModel> Handle(PackagesCurrentProjectQuery query)
        {
            var projectId = _currentProjectContextId.Get();
            var packages  = _context.Packages
                            .Include(p => p.Contents)
                            .Where(p => p.Project.Id == projectId && p.Active)
                            .Select(PackageViewModel.FromModel)
                            .ToList();

            return(packages);
        }
Exemplo n.º 7
0
        public IEnumerable <PermissionViewModel> Handle(PermissionsByCurrentProjectQuery query)
        {
            var projectId   = _currentProjectContextId.Get();
            var permissions = _context.Permissions
                              .Include(p => p.User.Contact)
                              .Where(p => p.Project.Id == projectId &&
                                     p.Profile != Profile.ProjectOwner)
                              .Select(PermissionViewModel.FromModel)
                              .ToList();

            return(permissions);
        }
Exemplo n.º 8
0
        public void Handle(CreateUseCaseDiagramCommand command)
        {
            var id = Guid.NewGuid();

            var projectId = _currentProjectContextId.Get();

            if (projectId == null)
            {
                throw new Exception(Sentences.noProjectInContext);
            }

            var package = _packageRepository.Get(command.PackageId.Value);

            if (!package.Active)
            {
                throw new Exception(Sentences.thisPackageWasRemoved);
            }

            var nextId = _useCaseDiagramNextIdQueryHandler.Handle(projectId.Value);

            var specificationItem = new SpecificationItem();

            specificationItem.Id        = id;
            specificationItem.Active    = true;
            specificationItem.Type      = SpecificationItemType.UseCaseDiagram;
            specificationItem.PackageId = command.PackageId.Value;
            specificationItem.Label     = $"UCD{nextId}";

            var useCaseDiagram = new UseCaseDiagram();

            useCaseDiagram.Id = id;

            useCaseDiagram.SpecificationItem = specificationItem;
            useCaseDiagram.ProjectId         = projectId.Value;
            useCaseDiagram.Version           = 1;
            useCaseDiagram.IsLastVersion     = true;
            useCaseDiagram.Identifier        = nextId;

            _useCaseDiagramItemsPersister.Persist(useCaseDiagram, command);

            _useCaseDiagramRepository.Add(useCaseDiagram);
            _specifiationItemRepository.Add(specificationItem);
        }
        public PackagesPaginatedQueryResult Handle(PackagesPaginatedQuery query)
        {
            var skip             = (query.Page - 1) * query.PageSize;
            var currentProjectId = _currentProjectContextId.Get();

            var packagesQuery = _context.Packages
                                .Where(p => p.Project.Id == currentProjectId && p.Active);

            var maxPages = (int)Math.Ceiling(packagesQuery.Count() / (double)query.PageSize);

            var packages = packagesQuery.OrderBy(p => p.Identifier)
                           .Include(p => p.Contents)
                           .Skip(skip)
                           .Take(query.PageSize)
                           .Select(PackageViewModel.FromModel)
                           .ToList();

            var result = new PackagesPaginatedQueryResult(packages, maxPages);

            return(result);
        }
Exemplo n.º 10
0
        public void Handle(SavePackageCommand command)
        {
            var package = new Package();

            package.Id = Guid.NewGuid();

            foreach (var item in command.Items)
            {
                var content = new PackageContent();
                content.Id          = package.Id;
                content.Locale      = item.Locale;
                content.Description = item.Description;
                content.Package     = package;
                content.IsUpdated   = true;
                _packageContentRepository.Add(content);
            }

            var currentUser = _currentUserRetriever.Get();

            package.CreatorId = currentUser.Id;


            var currentProjectId = _currentProjectContextId.Get();

            if (currentProjectId == null)
            {
                throw new Exception(Sentences.noProjectInContext);
            }

            var project = _projectRepository.Get(currentProjectId.Value);

            package.Project = project;
            package.Active  = true;

            var nextId = _packageNextIdQueryHandler.Handle(project.Id);

            package.Identifier = nextId;

            _packageRepository.Add(package);
        }
Exemplo n.º 11
0
        public void Handle(T command)
        {
            var commandDescriptionAttribute =
                Attribute.GetCustomAttribute(command.GetType(), typeof(CommandDescriptionAttribute)) as CommandDescriptionAttribute;

            if (commandDescriptionAttribute == null)
            {
                _decorated.Handle(command);
                return;
            }

            var projectId = _currentProjectContextId.Get();

            if (!projectId.HasValue)
            {
                _decorated.Handle(command);
                return;
            }

            var user = _currentUserRetriever.Get();

            if (user == null)
            {
                _decorated.Handle(command);
                return;
            }

            _decorated.Handle(command);

            var auditingCommand = new AddAuditingCommand();

            auditingCommand.ProjectId   = projectId.Value;
            auditingCommand.UserId      = user.Id;
            auditingCommand.Description = commandDescriptionAttribute.Description;

            _addAuditingCommandHandler.Handle(auditingCommand);
        }
        public void Handle(SavePermissionCommand command)
        {
            var currentPermissions = _permissionsByCurrentProjectQueryHandler.Handle(null);

            foreach (var permission in currentPermissions)
            {
                var item = command.Items.FirstOrDefault(i => i.UserId == permission.UserId);
                if (item == null)
                {
                    _permissionRepository.Remove(permission);
                    continue;
                }
                permission.Profile = item.Profile.Value;
            }

            var projectId = _currentProjectContextId.Get();

            if (projectId == null)
            {
                throw new Exception(Sentences.noProjectInContext);
            }

            foreach (var item in command.Items)
            {
                if (currentPermissions.Any(cp => cp.UserId == item.UserId))
                {
                    continue;
                }

                var permission = new Permission();
                permission.Id        = Guid.NewGuid();
                permission.Profile   = item.Profile.Value;
                permission.ProjectId = projectId.Value;
                permission.UserId    = item.UserId.Value;
                _permissionRepository.Add(permission);
            }
        }
Exemplo n.º 13
0
        public void Handle(CreateIssueCommand command)
        {
            var creator = _currentUserRetriever.Get();

            var issue = new Issue();

            issue.Creator             = creator;
            issue.SpecificationItemId = command.SpecificationItemId.Value;
            issue.Id = Guid.NewGuid();

            foreach (var item in command.Contents)
            {
                var content = new IssueContent();
                content.Description = item.Description;
                content.Locale      = item.Locale;
                content.Issue       = issue;
                content.Id          = issue.Id;
                content.IsUpdated   = true;
                _issueContentRepository.Add(content);
            }

            issue.LastModification = DateTime.Now;

            var currentProjectId = _currentProjectContextId.Get();

            if (currentProjectId == null)
            {
                throw new Exception(Sentences.noProjectInContext);
            }

            issue.Identifier = _issueNextIdQueryHandler.Handle(currentProjectId);
            issue.ProjectId  = currentProjectId.Value;
            issue.Concluded  = false;
            issue.CreatedAt  = DateTime.Now;

            _issueRepository.Add(issue);
        }
Exemplo n.º 14
0
        public void Persist(UseCaseDiagram useCaseDiagram, CreateUseCaseDiagramCommand command, IEnumerable <UseCase> oldVersionUseCases = null)
        {
            foreach (var contentItem in command.Contents)
            {
                var useCaseDiagramContent = new UseCaseDiagramContent();
                useCaseDiagramContent.Id     = Guid.NewGuid();
                useCaseDiagramContent.Locale = contentItem.Locale;
                useCaseDiagramContent.Name   = contentItem.Name;
                useCaseDiagram.Contents.Add(useCaseDiagramContent);
                _useCaseDiagramContentRepository.Add(useCaseDiagramContent);
            }

            var projectId = _currentProjectContextId.Get();
            var useCaseId = _useCaseNextIdQueryHandler.Handle(projectId);

            foreach (var useCaseData in command.UseCases)
            {
                var currentUseCaseId = useCaseData.Identifier == null ?
                                       useCaseId++ :
                                       useCaseData.Identifier.Value;
                PersistUseCase(useCaseDiagram, useCaseData, currentUseCaseId, oldVersionUseCases);
            }

            foreach (var actorData in command.Actors)
            {
                PersistActor(useCaseDiagram, actorData);
            }

            foreach (var relationData in command.EntitiesRelations)
            {
                var entitiesRelation = new UseCaseEntityRelation();
                entitiesRelation.Id = Guid.NewGuid();

                var source = useCaseDiagram.Entities
                             .FirstOrDefault(e => e.Id == relationData.SourceId.Value);
                var target = useCaseDiagram.Entities
                             .FirstOrDefault(e => e.Id == relationData.TargetId.Value);

                entitiesRelation.Source = source;
                entitiesRelation.Target = target;

                if (relationData.Contents != null)
                {
                    foreach (var content in relationData.Contents)
                    {
                        var relationContent = new UseCaseEntityRelationContent();
                        relationContent.Description = content.Description;
                        relationContent.Locale      = content.Locale;
                        relationContent.Id          = entitiesRelation.Id;
                        _useCaseEntityRelationContentRepository.Add(relationContent);
                    }
                }

                useCaseDiagram.EntitiesRelations.Add(entitiesRelation);
                _useCaseEntityRelationRepository.Add(entitiesRelation);
            }

            foreach (var relationData in command.UseCasesRelations)
            {
                var useCasesRelation = new UseCasesRelation();

                useCasesRelation.Version        = useCaseDiagram.Version;
                useCasesRelation.SourceId       = relationData.SourceId.Value;
                useCasesRelation.TargetId       = relationData.TargetId.Value;
                useCasesRelation.Type           = relationData.Type.Value;
                useCasesRelation.UseCaseDiagram = useCaseDiagram;

                useCaseDiagram.UseCasesRelations.Add(useCasesRelation);
                _useCasesRelationRepository.Add(useCasesRelation);
                useCasesRelation.Id = Guid.NewGuid();
            }
        }
Exemplo n.º 15
0
        public IEnumerable <SpecificationItemViewModel> SpecificationItems()
        {
            var projectId = _projectContextId.Get();

            return(_itemsByProjectQueryHandler.Handle(projectId));
        }
        public void Handle(SaveRequirementCommand command)
        {
            var requirement = new Requirement();
            var currentUser = _currentUserRetriever.Get();

            requirement.CreatorId     = currentUser.Id;
            requirement.Difficulty    = command.Difficulty.Value;
            requirement.Id            = Guid.NewGuid();
            requirement.IsLastVersion = true;
            requirement.Rank          = command.Rank.Value;

            foreach (var item in command.Items)
            {
                var content = new RequirementContent();
                content.Action      = item.Action;
                content.Subject     = item.Subject;
                content.Condition   = item.Condition;
                content.Id          = requirement.Id;
                content.Locale      = item.Locale;
                content.Version     = 1;
                content.Requirement = requirement;
                _requirementContentRepository.Add(content);
            }

            var currentProjectId = _currentProjectContextId.Get();

            if (currentProjectId == null)
            {
                throw new Exception(Sentences.noProjectInContext);
            }

            var project = _projectRepository.Get(currentProjectId.Value);

            var nextIdQuery = new RequirementNextIdQuery
            {
                ProjectId       = project.Id,
                RequirementType = command.RequirementType
            };

            var identifier = _requirementNextIdQueryHandler.Handle(nextIdQuery);

            var specificationItem = new SpecificationItem();

            specificationItem.Active = true;
            specificationItem.Id     = requirement.Id;
            specificationItem.Type   = SpecificationItemType.Requirement;
            var prefix = RequirementViewModel.GetPrefixFromType(command.RequirementType.Value);

            specificationItem.Label = $"{prefix}{identifier}";

            var package = _packageRepository.Get(command.PackageId.Value);

            if (!package.Active)
            {
                throw new Exception(Sentences.thisPackageWasRemoved);
            }
            specificationItem.Package = package;

            requirement.SpecificationItem = specificationItem;
            requirement.Type    = command.RequirementType.Value;
            requirement.Creator = currentUser;
            requirement.Version = 1;
            requirement.Project = project;

            requirement.Identifier = identifier;

            _specificationItemRepository.Add(specificationItem);
            _requirementRepository.Add(requirement);
        }