public async Task <CharacterView> GetCharacterViewAsync(int projectId, int characterId)
        {
            Expression <Func <CharacterGroup, GroupHeader> > groupHeaderSelector = group =>
                                                                                   new GroupHeader()
            {
                IsActive           = group.IsActive,
                CharacterGroupId   = group.CharacterGroupId,
                CharacterGroupName = group.CharacterGroupName,
                IsSpecial          = group.IsSpecial,
                ParentGroupIds     = group.ParentGroupsImpl,
            };

            var character = await Ctx.Set <Character>().AsNoTracking()
                            .Where(e => e.CharacterId == characterId && e.ProjectId == projectId)
                            .SingleOrDefaultAsync();

            var allGroups = await Ctx.Set <CharacterGroup>().AsNoTracking()
                            .Where(cg => cg.ProjectId == projectId && cg.IsActive)
                            .Select(groupHeaderSelector)
                            .ToDictionaryAsync(d => d.CharacterGroupId);

            var activeClaimPredicate = ClaimPredicates.GetClaimStatusPredicate(ClaimStatusSpec.Active);

            var view =
                new CharacterView()
            {
                CharacterId       = character.CharacterId,
                Name              = character.CharacterName,
                Description       = character.Description.Contents,
                UpdatedAt         = character.UpdatedAt,
                IsActive          = character.IsActive,
                InGame            = character.InGame,
                IsAcceptingClaims = character.IsAcceptingClaims,
                JsonData          = character.JsonData,
                ApprovedClaim     = await Ctx.Set <Claim>()
                                    .Where(claim => claim.CharacterId == characterId &&
                                           claim.ClaimStatus == Claim.Status.Approved).Select(
                    claim => new ClaimView()
                {
                    PlayerUserId = claim.PlayerUserId,
                    JsonData     = claim.JsonData,
                }).SingleOrDefaultAsync(),
                Claims = await Ctx.Set <Claim>().AsExpandable()
                         .Where(claim => claim.CharacterId == characterId &&
                                claim.ClaimStatus == Claim.Status.Approved).Select(
                    claim => new ClaimHeader()
                {
                    IsActive = activeClaimPredicate.Invoke(claim),
                }).ToListAsync(),
                DirectGroups = await Ctx.Set <CharacterGroup>()
                               .Where(group => character.ParentCharacterGroupIds.Contains(group.CharacterGroupId))
                               .Select(groupHeaderSelector).ToListAsync(),
            };

            view.AllGroups = view.DirectGroups
                             .SelectMany(g => g.FlatTree(group => group.ParentGroupIds._parentCharacterGroupIds.Select(id => allGroups[id])))
                             .Distinct()
                             .ToList();
            return(view);
        }
예제 #2
0
 public async Task <IReadOnlyCollection <ClaimCountByMaster> > GetClaimsCountByMasters(int projectId, ClaimStatusSpec claimStatusSpec)
 {
     return(await Ctx.Set <Claim>().Where(claim => claim.ProjectId == projectId)
            .Where(ClaimPredicates.GetClaimStatusPredicate(claimStatusSpec)).GroupBy(claim => claim.ResponsibleMasterUserId)
            .Select(grouping => new ClaimCountByMaster()
     {
         ClaimCount = grouping.Count(), MasterId = grouping.Key
     })
            .ToListAsync());
 }
예제 #3
0
 public async Task <IReadOnlyCollection <Claim> > GetClaimsForMoneyTransfersListAsync(int projectId, ClaimStatusSpec claimStatusSpec)
 {
     return(await Ctx
            .ClaimSet
            .AsNoTracking()
            .Include(c => c.Player)
            .Where(ClaimPredicates.GetClaimStatusPredicate(claimStatusSpec))
            .Where(c => c.ProjectId == projectId)
            .ToArrayAsync());
 }
예제 #4
0
 public async Task <IReadOnlyCollection <ClaimWithPlayer> > GetClaimHeadersWithPlayer(int projectId, ClaimStatusSpec claimStatusSpec)
 {
     return(await Ctx.Set <Claim>().Where(claim => claim.ProjectId == projectId)
            .Where(ClaimPredicates.GetClaimStatusPredicate(claimStatusSpec))
            .Include(c => c.Player.Extra)
            .Select(
                claim => new ClaimWithPlayer()
     {
         Player = claim.Player,
         ClaimId = claim.ClaimId,
         CharacterName = claim.Character.CharacterName,
         Extra = claim.Player.Extra,
     })
            .ToListAsync());
 }
예제 #5
0
        private Expression <Func <Project, ProjectWithClaimCount> > GetProjectWithClaimCountBuilder(
            int?userId)
        {
            var activeClaimPredicate = ClaimPredicates.GetClaimStatusPredicate(ClaimStatusSpec.Active);
            var myClaim = userId == null ? claim => false : ClaimPredicates.GetMyClaim(userId.Value);

            return(project => new ProjectWithClaimCount()
            {
                ProjectId = project.ProjectId,
                Active = project.Active,
                PublishPlot = project.Details.PublishPlot,
                ProjectName = project.ProjectName,
                IsAcceptingClaims = project.IsAcceptingClaims,
                ActiveClaimsCount = project.Claims.Count(claim => activeClaimPredicate.Invoke(claim)),
                HasMyClaims = project.Claims.Any(claim => myClaim.Invoke(claim)),
                HasMasterAccess = project.ProjectAcls.Any(acl => acl.UserId == userId),
            });
        }
예제 #6
0
        public async Task <CharacterView> GetCharacterViewAsync(int projectId, int characterId)
        {
            var character = await Ctx.Set <Character>().AsNoTracking()
                            .Where(e => e.CharacterId == characterId && e.ProjectId == projectId)
                            .SingleOrDefaultAsync();

            var activeClaimPredicate = ClaimPredicates.GetClaimStatusPredicate(ClaimStatusSpec.Active);

            return
                (new CharacterView()
            {
                CharacterId = character.CharacterId,
                UpdatedAt = character.UpdatedAt,
                IsActive = character.IsActive,
                InGame = character.InGame,
                IsAcceptingClaims = character.IsAcceptingClaims,
                JsonData = character.JsonData,
                ApprovedClaim = await Ctx.Set <Claim>()
                                .Where(claim => claim.CharacterId == characterId &&
                                       claim.ClaimStatus == Claim.Status.Approved).Select(
                    claim => new ClaimView()
                {
                    PlayerUserId = claim.PlayerUserId,
                    JsonData = claim.JsonData,
                }).SingleOrDefaultAsync(),
                Claims = await Ctx.Set <Claim>().AsExpandable()
                         .Where(claim => claim.CharacterId == characterId &&
                                claim.ClaimStatus == Claim.Status.Approved).Select(
                    claim => new ClaimHeader()
                {
                    IsActive = activeClaimPredicate.Invoke(claim)
                }).ToListAsync(),
                Groups = await Ctx.Set <CharacterGroup>()
                         .Where(group => character.ParentCharacterGroupIds.Contains(group.CharacterGroupId))
                         .Select(group => new GroupHeader()
                {
                    IsActive = group.IsActive,
                    CharacterGroupId = group.CharacterGroupId,
                    CharacterGroupName = group.CharacterGroupName,
                    IsSpecial = group.IsSpecial
                }).ToListAsync(),
            });
        }
예제 #7
0
        private async Task <IReadOnlyCollection <Claim> > GetClaimsImpl(int projectId, ClaimStatusSpec status, Expression <Func <Claim, bool> > predicate)
        {
            await LoadProjectFields(projectId);
            await LoadProjectCharactersAndGroups(projectId);
            await LoadMasters(projectId);

            Debug.WriteLine($"{nameof(LoadProjectClaimsAndComments)} started");
            return(await Ctx
                   .ClaimSet
                   .Include(c => c.CommentDiscussion.Comments.Select(cm => cm.Finance))
                   .Include(c => c.CommentDiscussion.Watermarks)
                   .Include(c => c.Player)
                   .Include(c => c.FinanceOperations)
                   .Where(ClaimPredicates.GetClaimStatusPredicate(status))
                   .Where(predicate)
                   .Where(
                       c =>
                       c.ProjectId == projectId
                       ).ToListAsync());
        }
 GetClaimAccommodationReport(int project)
 {
     return(await Ctx.Set <Claim>().AsExpandable().Include(claim => claim.Player.Extra)
            .Where(ClaimPredicates.GetClaimStatusPredicate(ClaimStatusSpec.Active))
            .Where(claim => claim.ProjectId == project)
            .Select(
                claim => new ClaimAccommodationInfoRow()
     {
         ClaimId = claim.ClaimId,
         AccomodationType = claim.AccommodationRequest != null
                     ? claim.AccommodationRequest.AccommodationType.Name
                     : null,
         RoomName =
             claim.AccommodationRequest != null &&
             claim.AccommodationRequest.Accommodation != null
                         ? claim.AccommodationRequest.Accommodation.Name
                         : null,
         User = claim.Player,
     }).ToListAsync());
 }