Ejemplo n.º 1
0
        public async Task <RoleDetailModel> Handle(GetRoleDetailQuery request, CancellationToken cancellationToken)
        {
            var role = await _context.RolesToPermissions.FirstAsync(x => x.RoleName == request.RoleName, cancellationToken);

            if (role == null)
            {
                return(null);
            }

            var usersInRole = _userManager.GetUsersInRoleAsync(role.RoleName);

            return(new RoleDetailModel
            {
                Name = role.RoleName,
                Description = role.Description,
                Platform = role.PlatformName,
                Active = role.Active,
                Permissions = role.GetPermissionsInRole,
                UserList = usersInRole.Result.Select(x => ApplicationUserLookupModel.Create(x)).ToList()
            });
        }
Ejemplo n.º 2
0
        public async Task <ActivityDetailModel> Handle(GetActivityDetailQuery request, CancellationToken cancellationToken)
        {
            var entity = await _context.Activities
                         .Include(a => a.Assignees).ThenInclude(aa => aa.User).ThenInclude(u => u.JobPosition)
                         .Include(a => a.Project).ThenInclude(x => x.ProjectSettings)
                         .Include(a => a.ActivityType)
                         .Include(a => a.Sprint)
                         .Include(a => a.ActivityList)
                         .Include(a => a.LoggedTimes)
                         .FirstAsync(a => a.Id == request.Id, cancellationToken);

            if (entity == null)
            {
                throw new NotFoundException(nameof(Activity), request.Id);
            }

            var result = ActivityDetailModel.Create(entity);

            result.Author = ApplicationUserLookupModel.Create(_context.ApplicationUsers.Find(entity.CreatedBy));

            if (request.DisplayAuditInfo != true)
            {
                return(result);
            }

            result.AuditChanges = await _context.AuditLogs
                                  .Where(x => Guid.Parse(x.EntityPk) == request.Id &&
                                         x.TableName == "Activities").Select(log => new ActivityAuditModel
            {
                EmployeeId       = log.AuditUserId,
                EmployeeName     = log.AuditUserName,
                ModificationTime = log.AuditDate,
                Data             = JsonConvert.DeserializeObject <EntityDto>(log.AuditData)
            }).ToListAsync(cancellationToken);

            return(result);
        }
Ejemplo n.º 3
0
        public async Task <ActivityListViewModel> Handle(GetActivityListFromParentEntityQuery request, CancellationToken cancellationToken)
        {
            switch (request.ParentType)
            {
            case ActivityParentType.ActivityList:
                return(new ActivityListViewModel
                {
                    Activities = await _context.Activities
                                 .Include(a => a.ActivityType)
                                 .Include(a => a.Assignees)
                                 .Include(a => a.LoggedTimes)
                                 .Include(a => a.Sprint).ThenInclude(s => s.Activities)
                                 .Where(a => a.ActivityListId == request.ParentEntityId &&
                                        request.Filter.Contains(a.ActivityStatus))
                                 .Skip(request.Skip)
                                 .Take(request.Size)
                                 .Select(activity => new ActivityLookupModel
                    {
                        Id = activity.Id,
                        Name = activity.Name,
                        Priority = activity.ActivityPriority,
                        ActivityType = activity.ActivityType.Abbreviation,
                        ActivityTypeColor = activity.ActivityType.ColorBadge,
                        EstimatedTime = activity.EstimatedHours ?? 0,
                        LoggedTime = activity.LoggedTimes.Sum(lt => lt.Time),
                        Progress = activity.Progress,
                        Assignees = activity.Assignees.Select(aa => ApplicationUserLookupModel.Create(aa.User)).ToList(),
                        SprintId = activity.SprintId,
                        Sprint = activity.Sprint != null ? activity.Sprint.Name : string.Empty,
                        SprintDueDate = activity.Sprint != null ? activity.Sprint.EndDate : DateTime.MinValue,
                        SprintIsCompleted = activity.Sprint != null && activity.Sprint.Activities.All(a => a.ActivityStatus == ActivityStatus.Completed),
                        DueDate = activity.DueDate,
                        ProjectId = activity.ProjectId,
                        ProjectName = activity.Project != null ? activity.Project.Name : string.Empty,
                        Status = activity.ActivityStatus,
                        ActivityListId = activity.ActivityListId,
                        Number = activity.Number
                    }).ToListAsync(cancellationToken: cancellationToken)
                });

            case ActivityParentType.UserActivities:
                return(new ActivityListViewModel
                {
                    Activities = (await _context.Activities
                                  .Where(a => a.Assignees.Any(aa => aa.UserId == request.ParentEntityId && request.Filter.Contains(a.ActivityStatus)))
                                  .Include(a => a.Project)
                                  .Include(a => a.ActivityType)
                                  .Include(a => a.Assignees)
                                  .Include(a => a.LoggedTimes)
                                  .Include(a => a.Sprint)
                                  .Skip(request.Skip)
                                  .Take(request.Size)
                                  .ToListAsync(cancellationToken))
                                 .Select(ActivityLookupModel.Create).ToList()
                });

            case ActivityParentType.Sprint:
                return(new ActivityListViewModel
                {
                    Activities = (await _context.Activities
                                  .Include(a => a.ActivityType)
                                  .Include(a => a.Assignees)
                                  .Include(a => a.LoggedTimes)
                                  .Include(a => a.Sprint).ThenInclude(s => s.Activities)
                                  .Where(a => a.SprintId == request.ParentEntityId && request.Filter.Contains(a.ActivityStatus))
                                  .Skip(request.Skip)
                                  .Take(request.Size)
                                  .ToListAsync(cancellationToken))
                                 .Select(ActivityLookupModel.Create).ToList()
                });

            case ActivityParentType.Employee:
                return(new ActivityListViewModel
                {
                    Activities = (await _context.Activities
                                  .Include(a => a.ActivityType)
                                  .Include(a => a.Assignees)
                                  .Include(a => a.LoggedTimes)
                                  .Include(a => a.Sprint).ThenInclude(s => s.Activities)
                                  .Where(a => a.Assignees.Any(assignee => assignee.UserId == request.ParentEntityId) &&
                                         request.Filter.Contains(a.ActivityStatus) &&
                                         a.ProjectId == request.ProjectId)
                                  .Skip(request.Skip)
                                  .Take(request.Size)
                                  .ToListAsync(cancellationToken))
                                 .Select(ActivityLookupModel.Create).ToList()
                });

            default:
                return(null);
            }
        }