Ejemplo n.º 1
0
        /// <inheritdoc/>
        public async override Task <IEnumerable <Models.Examination> > Handle(ExaminationsRetrievalQuery param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }

            var predicate = _examinationQueryBuilder.GetPredicate(param, false);

            switch (param.FilterOrderBy)
            {
            case ExaminationsOrderBy.Urgency:
                var key = DateTime.Now.Date.UrgencyKey();
                return(_store
                       .Query()
                       .WithPagination(param.FilterPageNumber, param.FilterPageSize)
                       .Where(predicate)
                       .OrderByDescending(x => x.UrgencySort[key])
                       .ToListAsync()
                       .Result);

            case ExaminationsOrderBy.CaseCreated:
                return(_store.Query().WithPagination(param.FilterPageNumber, param.FilterPageSize).Where(predicate).OrderBy(x => x.CreatedAt).ToListAsync().Result);

            case null:
                return(_store.Query().WithPagination(param.FilterPageNumber, param.FilterPageSize).Where(predicate).ToListAsync().Result);

            default:
                throw new ArgumentOutOfRangeException(nameof(param.FilterOrderBy));
            }
        }
Ejemplo n.º 2
0
        public async Task <List <FlatForRentAnnouncement> > GetAllAsync()
        {
            var flatForRentAnnouncementEntities = await _cosmosStore.Query().ToListAsync();

            return(_mapper.Map <List <FlatForRentAnnouncementEntity>, List <FlatForRentAnnouncement> >(
                       flatForRentAnnouncementEntities));
        }
Ejemplo n.º 3
0
        public async Task <List <T> > List(string resourceID)
        {
            // list product history given product ID. TODO: get the most RECENT record.
            var feedOptions = new FeedOptions()
            {
                PartitionKey = new PartitionKey(resourceID)
            };

            return(await _productStore.Query(feedOptions).ToListAsync());
        }
Ejemplo n.º 4
0
        public async Task <IEnumerable <MeUserItem> > GetUsers()
        {
            var users = await _userStore.Query().ToListAsync();

            return(users.Select(u => new MeUserItem
            {
                Id = u.UserId,
                FullName = u.FullName(),
            }));
        }
        public async Task <List <CreateProjectViewModel> > GetAllProjects()
        {
            var projects = await _NoDb.Query()
                           .Select(x => new CreateProjectViewModel {
                Name = x.ProjectName
            })
                           .ToListAsync();

            return(projects);
        }
Ejemplo n.º 6
0
        public async Task <Post> GetPostById(Guid postId)
        {
            var post = await cosmosStore.Query().FirstOrDefaultAsync(p => p.Id == postId.ToString());

            if (post == null)
            {
                return(null);
            }
            return(new Post {
                Id = Guid.Parse(post.Id), Name = post.Name
            });
        }
Ejemplo n.º 7
0
        public async Task <NumSizePagedData <Student> > GetStudentsNumSize([FromQuery] int page = 1, [FromQuery] int pageSize = 10)
        {
            var students = await _studentsStore.Query().WithPagination(page, pageSize).ToListAsync();

            var totalCount = await _studentsStore.Query().CountAsync();

            var pager = new NumSizePager(totalCount, page, pageSize);

            return(new NumSizePagedData <Student>
            {
                Items = students,
                NumSizePager = pager
            });
        }
Ejemplo n.º 8
0
        private static async Task <string> PrepareExpectedResponseAsync(ICosmosStore <RoomForRentAnnouncementEntity> cosmosStore, string title)
        {
            var roomForRentAnnouncementEntity = await cosmosStore.Query().SingleOrDefaultAsync(x => x.Title.Equals(title));

            var roomForRentAnnouncementResponse = new RoomForRentAnnouncementResponse(
                roomForRentAnnouncementEntity.Id,
                roomForRentAnnouncementEntity.Title,
                roomForRentAnnouncementEntity.SourceUrl,
                roomForRentAnnouncementEntity.CityId,
                roomForRentAnnouncementEntity.Created,
                roomForRentAnnouncementEntity.Description,
                roomForRentAnnouncementEntity.Price,
                roomForRentAnnouncementEntity.RoomTypes.Select(x => RoomForRentAnnouncementProfile.ConvertToRoomTypeEnum(x.ConvertToEnumeration())),
                roomForRentAnnouncementEntity.CityDistricts);
            var settings = new JsonSerializerSettings
            {
                Formatting       = Formatting.Indented,
                ContractResolver = new DefaultTestPlatformContractResolver
                {
                    NamingStrategy = new CamelCaseNamingStrategy()
                },
                Converters = new List <JsonConverter> {
                    new IsoDateTimeConverter(), new StringEnumConverter()
                }
            };

            return(JsonConvert.SerializeObject(roomForRentAnnouncementResponse, settings));
        }
Ejemplo n.º 9
0
 public async Task <IEnumerable <Process> > ExecuteAsync(GetProcessQuery command, IEnumerable <Process> previousResult)
 {
     return(await _cosmosStore
            .Query()
            .Where(p => p.Status == command.Status)
            .ToListAsync());
 }
Ejemplo n.º 10
0
        public async Task GetAllAsync_Should_Return_RoomForRentAnnouncements()
        {
            var roomForRentAnnouncementEntities = await _cosmosStore.Query().ToListAsync();

            var roomForRentAnnouncements = roomForRentAnnouncementEntities
                                           .Select(x => RoomForRentAnnouncement.Builder()
                                                   .SetId(x.Id)
                                                   .SetTitle(x.Title)
                                                   .SetSourceUrl(x.SourceUrl)
                                                   .SetCityId(x.CityId)
                                                   .SetCreated(x.Created)
                                                   .SetDescription(x.Description)
                                                   .SetPrice(x.Price)
                                                   .SetCityDistricts(x.CityDistricts)
                                                   .SetRoomTypes(x.RoomTypes.Select(r => r.ConvertToEnumeration()))
                                                   .Build()
                                                   )
                                           .ToList();

            _mapperMock
            .Setup(x => x.Map <List <RoomForRentAnnouncementEntity>, List <RoomForRentAnnouncement> >(It.IsAny <List <RoomForRentAnnouncementEntity> >()))
            .Returns(roomForRentAnnouncements);
            var result = await _repository.GetAllAsync();

            result.Should().BeEquivalentTo(roomForRentAnnouncements);
        }
Ejemplo n.º 11
0
        private static async Task <string> PrepareExpectedResponseAsync(ICosmosStore <FlatForRentAnnouncementEntity> cosmosStore)
        {
            var flatForRentAnnouncementEntities = await cosmosStore.Query().ToListAsync();

            var getFlatForRentAnnouncementsCollectionItemResponses = flatForRentAnnouncementEntities.Select(
                flatForRentAnnouncementEntity => new FlatForRentAnnouncementResponse(
                    flatForRentAnnouncementEntity.Id,
                    flatForRentAnnouncementEntity.Title,
                    flatForRentAnnouncementEntity.SourceUrl,
                    flatForRentAnnouncementEntity.CityId,
                    flatForRentAnnouncementEntity.Created,
                    flatForRentAnnouncementEntity.Description,
                    flatForRentAnnouncementEntity.Price,
                    FlatForRentAnnouncementProfile.ConvertToNumberOfRoomsEnum(flatForRentAnnouncementEntity
                                                                              .NumberOfRooms.ConvertToEnumeration()),
                    flatForRentAnnouncementEntity.CityDistricts));
            var collectionResponse =
                new CollectionResponse <FlatForRentAnnouncementResponse>(flatForRentAnnouncementEntities.Count, getFlatForRentAnnouncementsCollectionItemResponses);
            var settings = new JsonSerializerSettings
            {
                Formatting       = Formatting.Indented,
                ContractResolver = new DefaultTestPlatformContractResolver
                {
                    NamingStrategy = new CamelCaseNamingStrategy()
                },
                Converters = new List <JsonConverter> {
                    new IsoDateTimeConverter(), new StringEnumConverter()
                }
            };

            return(JsonConvert.SerializeObject(collectionResponse, settings));
        }
Ejemplo n.º 12
0
        public async Task <List <Message> > GetMessagesAsync()
        {
            var messages = await _cosmosStore.Query().ToListAsync();

            return(messages.Select(m => new Message {
                Id = Guid.Parse(m.Id), Text = m.Text
            }).ToList());
        }
Ejemplo n.º 13
0
        public async Task <List <Post> > GetAll_Async(PaginationFilter paginationFilter)
        {
            var posts = await _cosmosStore.Query().ToListAsync();

            return(posts.Select(x => new Post {
                Id = Guid.Parse(x.Id), Name = x.Name
            }).ToList());
        }
Ejemplo n.º 14
0
        public async Task <List <Post> > GetAllAsync()
        {
            var posts = await _cosmosStore.Query().ToListAsync();

            return(posts.Select(p => new Post {
                Id = Guid.Parse(p.Id), Name = p.Name
            }).ToList());
        }
Ejemplo n.º 15
0
        public async Task <List <Post> > GetPostsAsync()
        {
            var posts = await _cosmosStore.Query().ToListAsync(); // this is cosmos extension, not EF one

            return(posts.Select(p => new Domain.Post {
                Id = Guid.Parse(p.Id.ToString()), Name = p.Name
            }).ToList());
        }
Ejemplo n.º 16
0
        public async Task <List <Order> > GetOrdersAsync()
        {
            var orders = await _cosmosStore.Query().ToListAsync();

            return(orders.Select(x => new Order {
                Id = Guid.Parse(x.Id), Amount = x.Amount
            }).ToList());
        }
Ejemplo n.º 17
0
        public async Task <List <Post> > GetPostsAsync(GetAllPostFilter filter = null, PaginationFilter paginationFilter = null)
        {
            var posts = await _cosmosStore.Query().ToListAsync();

            return(posts.Select(p => new Post {
                Id = Guid.Parse(p.Id), Name = p.Name
            }).ToList());
        }
Ejemplo n.º 18
0
        public async Task <List <Post> > GetPostsAsync()
        {
            var posts = await _CosmosStore.Query().ToListAsync();

            return(posts.Select(x => new Post {
                Id = Guid.Parse(x.Id), Name = x.Name
            }).ToList());
        }
Ejemplo n.º 19
0
        public async Task <List <CustomTask> > GetCustomTasksAsync()
        {
            var customTasks = await _cosmosStore.Query().ToListAsync();

            return(customTasks.Select(x => new CustomTask {
                Title = x.Title, Description = x.Description
            }).ToList());
        }
Ejemplo n.º 20
0
        public async Task <List <ReportTemplate> > List(ReportTypeEnum reportType, VerifiedUserContext verifiedUser)
        {
            var feedOptions = new FeedOptions()
            {
                PartitionKey = new PartitionKey($"{verifiedUser.SellerID}")
            };
            var templates = new List <ReportTemplate>();

            if (verifiedUser.UsrType == "admin")
            {
                templates = await _store.Query(feedOptions).Where(x => x.ReportType == reportType).ToListAsync();
            }
            else if (verifiedUser.UsrType == "supplier")
            {
                templates = await _store.Query(feedOptions).Where(x => x.ReportType == reportType && x.AvailableToSuppliers == true).ToListAsync();
            }
            return(templates);
        }
Ejemplo n.º 21
0
        public async Task UpdateAsync(UserUpdatedIntegrationEvent integrationEvent)
        {
            var flatForRentAnnouncementPreferences =
                await _cosmosStore.Query().Where(x => x.UserId == integrationEvent.UserId).ToListAsync();

            foreach (var flatForRentAnnouncementPreference in flatForRentAnnouncementPreferences)
            {
                flatForRentAnnouncementPreference.ServiceActive = integrationEvent.ServiceActive;
                flatForRentAnnouncementPreference.AnnouncementSendingFrequency = integrationEvent.AnnouncementSendingFrequency;
            }

            var updateResult = await _cosmosStore.UpdateRangeAsync(flatForRentAnnouncementPreferences);

            if (!updateResult.IsSuccess)
            {
                throw new UpdateManyFailureException();
            }
        }
Ejemplo n.º 22
0
        public async Task <List <ReportTemplate> > List(ReportTypeEnum reportType, DecodedToken decodedToken)
        {
            var me = await _oc.Me.GetAsync(accessToken : decodedToken.AccessToken);

            var feedOptions = new FeedOptions()
            {
                PartitionKey = new PartitionKey($"{me?.Seller?.ID}")
            };
            var templates = new List <ReportTemplate>();

            if (decodedToken.CommerceRole == CommerceRole.Seller)
            {
                templates = await _store.Query(feedOptions).Where(x => x.ReportType == reportType).ToListAsync();
            }
            else if (decodedToken.CommerceRole == CommerceRole.Supplier)
            {
                templates = await _store.Query(feedOptions).Where(x => x.ReportType == reportType && x.AvailableToSuppliers == true).ToListAsync();
            }
            return(templates);
        }
Ejemplo n.º 23
0
        public async Task <List <Product> > GetProductsAsync()
        {
            var products = await _cosmosStore.Query().ToListAsync();

            return(products.Select(x => new Product
            {
                ProductID = Guid.Parse(x.ProductID),
                ProductCode = x.ProductCode,
                ProductName = x.ProductName
            }).ToList());
        }
        public async Task <IActionResult> GetAllPaged([FromQuery] string continuationToken,
                                                      CancellationToken cancellationToken, [FromQuery] int pageSize = 10)
        {
            if (pageSize > 50 || pageSize <= 0)
            {
                return(BadRequest("Page Size Invalid! Must be 0 < pageSize < 50"));
            }

            if (continuationToken == null || continuationToken.Trim().Length == 0)
            {
                var initialPage = await _peopleCosmosStore.Query().OrderBy(person => person.Name)
                                  .WithPagination(1, pageSize).ToPagedListAsync(cancellationToken: cancellationToken);

                return(Ok(initialPage));
            }

            var page = await _peopleCosmosStore.Query().OrderBy(person => person.Name)
                       .WithPagination(continuationToken, pageSize).ToPagedListAsync(cancellationToken: cancellationToken);

            return(Ok(page));
        }
Ejemplo n.º 25
0
        public LocationResponse GetTree()
        {
            var sourceUsers = _userStore.Query().ToList();

            var permissedLocations = sourceUsers
                                     .Where(u => u.Permissions != null)
                                     .SelectMany(u => u.Permissions.Select(p => p.LocationId)).Distinct().ToList();

            var offices = _locationStore
                          .Query()
                          .Where(l => l.IsMeOffice || // Is office
                                 permissedLocations.Contains(l.LocationId)) // Or user has it assigned via permission
                          .ToList();

            var allLocations = GetPath(offices);


            var allUsers = sourceUsers.Select(u => new UserItem()
            {
                UserId   = u.UserId,
                FullName = u.FullName()
            }).ToList();

            var result = new LocationResponse();
            var roots  = new List <LocationNode>();

            result.Roots = roots;

            var sourceRoots = allLocations.Where(l => l.ParentId == null).ToList();

            foreach (var sourceRoot in sourceRoots)
            {
                var rootNode = new LocationNode()
                {
                    LocationId = sourceRoot.LocationId,
                    Name       = sourceRoot.Name,
                };

                PopulateTree(rootNode, allLocations, sourceUsers, allUsers);

                roots.Add(rootNode);
            }

            /*result.Locations = allLocations.Select(l => new LocationNode()
             * {
             *  LocationId = l.LocationId,
             *  Name = l.Name
             * }).ToList();*/

            return(result);
        }
Ejemplo n.º 26
0
        private IList <Location> GetPath(IEnumerable <Location> children)
        {
            var todo   = children.ToList();
            var result = new List <Location>();

            while (todo.Any())
            {
                result.AddRange(todo);

                var parents = todo.Select(l => l.ParentId).Distinct().ToList();

                var existingIds = result.Select(r => r.LocationId).ToList();

                var next = _locationStore
                           .Query()
                           .Where(l => parents.Contains(l.LocationId) && !existingIds.Contains(l.LocationId))
                           .ToList();

                todo = next;
            }

            return(result.Distinct().ToList());
        }
Ejemplo n.º 27
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>());
        }
Ejemplo n.º 28
0
        public async Task <ListPage <OrchestrationLog> > List(IListArgs args)
        {
            var query = _store.Query(new FeedOptions()
            {
                EnableCrossPartitionQuery = true
            })
                        .Search(args)
                        .Filter(args)
                        .Sort(args);
            var list = await query.WithPagination(args.Page, args.PageSize).ToPagedListAsync();

            var count = await query.CountAsync();

            return(list.ToListPage(args.Page, args.PageSize, count));
        }
Ejemplo n.º 29
0
        public async Task MatchAnnouncementsToPreferencesAsync(RoomForRentAnnouncementsIntegrationEvent integrationEvent)
        {
            var roomForRentAnnouncementPreferences =
                await _cosmosStore.Query().Where(x => x.CityId == integrationEvent.CityId && x.ServiceActive).ToListAsync();

            var processedAnnouncementPreferenceIds = new HashSet <Guid>();

            Parallel.ForEach(
                roomForRentAnnouncementPreferences,
                _parallelOptions,
                roomForRentAnnouncementPreference => ProcessRoomForRentAnnouncementPreference(roomForRentAnnouncementPreference, integrationEvent, processedAnnouncementPreferenceIds));

            var documents = roomForRentAnnouncementPreferences.Select(JsonConvert.SerializeObject);
            await _bulkExecutor.BulkImportAsync(documents, true, true, _maxDegreeOfParallelism);
        }
Ejemplo n.º 30
0
        public async Task <IEnumerable <Product> > GetRecommendation(string UserID)
        {
            var _recommendations = _cosmosStore.Query().Where(x => x.user_id == UserID).ToArray();

            if (_recommendations.Length > 0)
            {
                using (var httpClient = new HttpClient())
                {
                    swaggerClient swaggerClient = new swaggerClient(productAPIServiceURL, httpClient);
                    return(await swaggerClient.GetProductsAsync(_recommendations[0].product_ids));
                }
            }
            else
            {
                return(new Product[] { });
            }
        }