protected override async Task <IReadOnlyCollection <GroupSequenceModel> > Process(GroupSequenceQuery request, CancellationToken cancellationToken)
        {
            var tenantId = _userClaimManager.GetRequiredTenantId(request.Principal);

            var groups = await DataContext.Groups
                         .AsNoTracking()
                         .Where(q => q.TenantId == tenantId)
                         .ToListAsync(cancellationToken);

            var grouping = groups.GroupBy(g => g.Sequence);

            var result = new List <GroupSequenceModel>();

            foreach (var group in grouping)
            {
                var sequenceModel = new GroupSequenceModel();
                sequenceModel.TenantId = tenantId;
                sequenceModel.Sequence = group.Key;

                sequenceModel.Name = group
                                     .Select(g => g.Name)
                                     .OrderBy(g => g, StringComparer.OrdinalIgnoreCase.WithNaturalSort())
                                     .ToDelimitedString("; ");

                result.Add(sequenceModel);
            }

            return(result
                   .OrderBy(g => g.Sequence)
                   .ToList());
        }
        protected override async Task <IReadOnlyCollection <LocationDropdownModel> > Process(LocationDropdownQuery request, CancellationToken cancellationToken)
        {
            var tenantId = _userClaimManager.GetRequiredTenantId(request.Principal);

            var result = await DataContext.Locations
                         .AsNoTracking()
                         .Where(q => q.TenantId == tenantId)
                         .OrderBy(q => q.Name)
                         .ProjectTo <LocationDropdownModel>(Mapper.ConfigurationProvider)
                         .ToListAsync(cancellationToken);

            return(result);
        }
Example #3
0
        protected override async Task <CommandCompleteModel> Process(SessionSequenceCreateCommand request, CancellationToken cancellationToken)
        {
            var tenantId     = _userClaimManager.GetRequiredTenantId(request.Principal);
            var identityName = request.Principal?.Identity?.Name;

            // load topic
            var topics = await DataContext.Topics
                         .Where(g => g.TenantId == tenantId)
                         .Where(g => request.TopicIds.Contains(g.Id))
                         .ToListAsync(cancellationToken);

            // load groups by sequence
            var groups = await DataContext.Groups
                         .Where(g => g.TenantId == tenantId)
                         .Where(g => request.Sequences.Contains(g.Sequence))
                         .ToListAsync(cancellationToken);

            var orderedGroups = groups
                                .OrderBy(g => g.Sequence)
                                .ThenBy(g => g.Name, StringComparer.OrdinalIgnoreCase.WithNaturalSort())
                                .ToList();

            // create groups
            foreach (var topic in topics)
            {
                foreach (var group in orderedGroups)
                {
                    var session = new Session
                    {
                        TopicId          = topic.Id,
                        LeadInstructorId = topic.LeadInstructorId,
                        TenantId         = topic.TenantId,
                        GroupId          = group.Id,
                        Created          = DateTimeOffset.UtcNow,
                        CreatedBy        = identityName,
                        Updated          = DateTimeOffset.UtcNow,
                        UpdatedBy        = identityName
                    };

                    DataContext.Sessions.Add(session);
                }
            }

            await DataContext.SaveChangesAsync(cancellationToken);

            return(new CommandCompleteModel());
        }
Example #4
0
        protected override async Task <IReadOnlyCollection <TemplateDropdownModel> > Process(TemplateDropdownQuery request, CancellationToken cancellationToken)
        {
            var tenantId = _userClaimManager.GetRequiredTenantId(request.Principal);

            var query = DataContext.Templates
                        .AsNoTracking()
                        .Where(q => q.TenantId == tenantId);

            if (request.TemplateType.HasValue())
            {
                query = query.Where(q => q.TemplateType == request.TemplateType);
            }

            var result = await query
                         .OrderBy(q => q.Name)
                         .ProjectTo <TemplateDropdownModel>(Mapper.ConfigurationProvider)
                         .ToListAsync(cancellationToken);

            return(result);
        }