public async Task Handle(FoodRegisteredEvent notification, CancellationToken cancellationToken)
        {
            var item = await _tableDataProvider.GetFood(notification.RestaurantId, notification.FoodName);

            if (item.HasValue())
            {
                var food = new FoodDocument(item.RestaurantId,
                                            notification.RestaurantName,
                                            item.Id,
                                            item.ImageUrl,
                                            item.Name,
                                            item.UnitPrice,
                                            item.OldUnitPrice,
                                            item.Type,
                                            item.CategoryId,
                                            item.MenuId,
                                            item.CuisineId,
                                            notification.MenuName,
                                            notification.CategoryName,
                                            notification.CuisineName,
                                            item.Status,
                                            item.IsGlutenFree,
                                            item.IsVeg,
                                            item.IsNonVeg,
                                            item.Description,
                                            item.DescriptionEng,
                                            notification.Ingredients
                                            );

                await _documentCollection.FoodCollection.InsertOneAsync(food, cancellationToken);
            }
        }
Exemplo n.º 2
0
        public async Task <Result <IPagedList <FoodMinimalDto> > > Handle(FilterFoodsQuery request,
                                                                          CancellationToken cancellationToken)
        {
            var foods = await _collection.FoodCollection.Find(FilterBy(request))
                        .SortByDescending(FoodDocument.GetOrderBy(request.OrderBy))
                        .Skip(PaginationHelper.Skip(request.PageNumber, request.PageSize))
                        .Limit(request.PageSize)
                        .Project(Projections.MinimalFoodProjection())
                        .ToListAsync(cancellationToken);

            return(Result.Ok(foods.ToPagedList(request.PageNumber, request.PageSize)));
        }