예제 #1
0
        public async Task <EbatchSheetVm> Handle(GetEbatchSheetQuery request, CancellationToken cancellationToken)
        {
            var ebatchSheet = await _cosmosStore.FindAsync(request.Id, Constants.EBATCH_SHEET_PARTITON_KEY);

            if (ebatchSheet != null)
            {
                var userRoles = _httpContext.HttpContext?.User?.FindAll("roles").Select(r => r.Value);
                if (userRoles.Contains(UserRole.AdminTeam))
                {
                    return(ebatchSheet.ToViewEntity());
                }
                else
                {
                    var states = userRoles.Select(x => MappingExtention.GetReviewStateByRole(x).Value);
                    if (states.Contains(ebatchSheet.CurrentState.Value))
                    {
                        return(ebatchSheet.ToViewEntity());
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            else
            {
                return(null);
            }

            //return ebatchSheet.ToViewEntity();
        }
예제 #2
0
        public async Task <IEnumerable <EbatchSheetVm> > Handle(GetEbatchSheetsQuery request, CancellationToken cancellationToken)
        {
            var userRoles = _httpContext.HttpContext?.User?.FindAll("roles").Select(r => r.Value);

            if (userRoles.Contains(UserRole.AdminTeam))
            {
                var allEbatchs = await _cosmosStore.Query(new FeedOptions()
                {
                    PartitionKey = new PartitionKey(Constants.EBATCH_SHEET_PARTITON_KEY)
                })
                                 .ToListAsync();

                if (allEbatchs.Count > 0)
                {
                    _logger.LogInformation("GET_EBATCHSHEET_BY_ADMIN: {@result}", allEbatchs);
                    return(allEbatchs.Select(x => x.ToViewEntity()));
                }
            }
            else
            {
                var states = userRoles.Select(x => MappingExtention.GetReviewStateByRole(x).Value);

                var ebatchSheets = await _cosmosStore.Query(new FeedOptions()
                {
                    PartitionKey = new PartitionKey(Constants.EBATCH_SHEET_PARTITON_KEY)
                })
                                   .Where(x => states.Contains(x.CurrentState.Value))
                                   .ToListAsync();

                if (ebatchSheets.Count > 0)
                {
                    _logger.LogInformation("GET_EBATCHSHEET_BY {@role} {@result}", userRoles, ebatchSheets);
                    return(ebatchSheets.Select(x => x.ToViewEntity()));
                }
            }
            return(new List <EbatchSheetVm>());
        }