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 void Handle(UpdateUserCommand command) { var user = _currentUserRetriever.Get(); var contact = _contactByUserIdQueryHandler.Handle(user.Id); contact.Email = command.Email; contact.MobilePhone = command.MobilePhone?.Replace(" ", "").Replace("+", ""); contact.Name = command.Name; contact.Phone = command.Phone?.Replace(" ", "").Replace("+", ""); }
public void Handle(CreateRequirementVersionCommand command) { var queryResult = _specificationItemWithRequirementsQueryHandler.Handle(command.Id); var latestVersion = queryResult.Requirements.FirstOrDefault(s => s.IsLastVersion); foreach (var oldRequirementVersion in queryResult.Requirements) { oldRequirementVersion.IsLastVersion = false; } var package = _packageRepository.Get(command.PackageId.Value); if (!package.Active) { throw new Exception(Sentences.thisPackageWasRemoved); } queryResult.SpecificationItem.Package = package; var currentUser = _currentUserRetriever.Get(); var requirement = new Requirement(); requirement.Id = command.Id.Value; requirement.CreatorId = currentUser.Id; requirement.Difficulty = command.Difficulty.Value; requirement.Identifier = latestVersion.Identifier; requirement.IsLastVersion = true;; requirement.ProjectId = latestVersion.ProjectId; requirement.Rank = command.Rank.Value; requirement.SpecificationItem = queryResult.SpecificationItem; requirement.CreatorId = latestVersion.CreatorId; requirement.Version = latestVersion.Version + 1; requirement.Type = latestVersion.Type; 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 = requirement.Version; content.Requirement = requirement; _requirementContentRepository.Add(content); } _requirementRepository.Add(requirement); }
public void Handle(CreateProjectCommand command) { var project = new Project(); project.Id = Guid.NewGuid(); project.Active = true; foreach (var item in command.Items) { var content = new ProjectContent(); content.Description = item.Description; content.Name = item.Name; content.Locale = item.Locale; content.Project = project; content.IsUpdated = true; content.Id = project.Id; _projectContentRepository.Add(content); } project.CreatedAt = DateTime.Now; var currentUser = _currentUserRetriever.Get(); if (currentUser == null) { throw new Exception(Sentences.youMustBeLoggedIn); } var identifier = _projectNextIdQuery.Handle(currentUser.Id); project.Owner = currentUser; project.CreatorId = currentUser.Id; project.Identifier = identifier; var permission = new Permission(); permission.Id = Guid.NewGuid(); permission.Profile = Profile.ProjectOwner; permission.Project = project; permission.User = currentUser; _permissionRepository.Add(permission); _projectRepository.Add(project); }
public ProjectsPaginatedQueryResult Handle(ProjectsPaginatedQuery query) { var skip = (query.Page - 1) * query.PageSize; var currentUser = _currentUserRetriever.Get(); var dbQuery = _context.Projects .Where(p => p.OwnerId == currentUser.Id && p.Active); var maxPages = (int)Math.Ceiling(dbQuery.Count() / (double)query.PageSize); var projects = dbQuery.OrderBy(p => p.CreatorId) .ThenBy(p => p.Identifier) .Include(p => p.ProjectContents) .Skip(skip) .Take(query.PageSize) .ToList() .Select(ProjectViewModel.FromModel) .ToList(); return(new ProjectsPaginatedQueryResult(projects, maxPages)); }
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); }
public IEnumerable <AuditingViewModel> Handle(AuditingsByPeriodQuery query) { var currentUser = _currentUserRetriever.Get(); var projectsIds = _context.Permissions .Where(p => p.UserId == currentUser.Id) .Select(p => p.ProjectId) .Distinct() .ToList(); var dateTimeFilter = GetDateTimeFilterFromPeriod(query.Period); var auditings = _context.Auditings .Include(a => a.Project.ProjectContents) .Include(a => a.User.Contact) .Where(a => a.Project.Active && projectsIds.Contains(a.ProjectId) && (!dateTimeFilter.HasValue || a.ExecutedAt >= dateTimeFilter.Value)) .OrderByDescending(a => a.ExecutedAt) .Select(AuditingViewModel.FromModel) .ToList(); return(auditings); }
public CurrentUserProjectsQueryResult Handle(CurrentUserProjectsQuery query) { var currentUser = _currentUserRetriever.Get(); if (currentUser == null) { throw new Exception(Sentences.youMustBeLoggedIn); } var projects = _context.Projects .Include(p => p.ProjectContents) .Where(p => p.Permissions.Any(perm => perm.UserId == currentUser.Id) && p.Active) .ToList() .Select(ProjectOption.FromModel) .OrderBy(p => p.Name) .ToList(); var result = new CurrentUserProjectsQueryResult(); result.Projects = projects; return(result); }
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(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); }
public IEnumerable <AuditingViewModel> Handle(AuditingsByProjectQuery query) { var currentUser = _currentUserRetriever.Get(); var hasPermission = _context.Permissions .Include(p => p.Project) .Any(p => p.UserId == currentUser.Id && p.ProjectId == query.ProjectId || p.Project.OwnerId == currentUser.Id); if (!hasPermission) { throw new Exception(Sentences.youDontHavePermissionToAccessThisProject); } var auditingsQuery = _context.Auditings .Include(a => a.Project.ProjectContents) .Include(a => a.User.Contact) .Where(a => a.ProjectId == query.ProjectId) .OrderByDescending(a => a.ExecutedAt) .Select(AuditingViewModel.FromModel); var auditings = auditingsQuery.ToList(); return(auditings); }
public void Handle(ChangeUserPasswordCommand command) { var user = _currentUserRetriever.Get(); user.Password = _cryptographer.Encrypt(command.Password); }
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); }