예제 #1
0
        /// <summary>
        /// Place orders for restaurant
        /// </summary>
        /// <param name="restaurantName">Name of restaurant</param>
        public void PlaceOrdersForRestaurant(string restaurantName)
        {
            switch (restaurantName)
            {
            case "Restoran pod Lipom":
                var lipa = _restaurantQueryRepo.Query(new RestaurantQueryModel {
                    Name = restaurantName
                })
                           .Map(x => x.Items.FirstOrDefault())
                           .Reduce(_ => throw new Exception());
                if (lipa != null)
                {
                    var lipaOrders = _orderQueryRepo.GetAllOrdersForRestaurant(lipa.Id, 1, int.MaxValue)
                                     .Map(x => x.Items.Where(o => o.Date == DateTime.Today.Date).ToList())
                                     .Reduce(_ => throw new Exception());
                    _lipaConector.PlaceOrders(lipaOrders);
                }

                break;

            case "Hedone":
                var hedone = _restaurantQueryRepo.Query(new RestaurantQueryModel {
                    Name = restaurantName
                })
                             .Map(x => x.Items.FirstOrDefault())
                             .Reduce(_ => throw new Exception());
                if (hedone != null)
                {
                    var hedoneOrders = _orderQueryRepo.GetAllOrdersForRestaurant(hedone.Id, 1, int.MaxValue)
                                       .Map(x => x.Items.Where(o => o.Date == DateTime.Today.Date).ToList())
                                       .Reduce(_ => throw new Exception());
                    _hedoneConector.PlaceOrders(hedoneOrders);
                }

                break;

            case "Teglas":
                var teglas = _restaurantQueryRepo.Query(new RestaurantQueryModel {
                    Name = restaurantName
                })
                             .Map(x => x.Items.FirstOrDefault())
                             .Reduce(_ => throw new Exception());
                if (teglas != null)
                {
                    var teglasOrders = _orderQueryRepo.GetAllOrdersForRestaurant(teglas.Id, 1, int.MaxValue)
                                       .Map(x => x.Items.Where(o => o.Date == DateTime.Today.Date).ToList())
                                       .Reduce(_ => throw new Exception());
                    _teglasConector.PlaceOrders(teglasOrders);
                }

                break;

            default:
                throw new ArgumentException("Invalid restaurant");
            }
        }
예제 #2
0
        /// <summary>
        /// Update daily menu for restaurants
        /// </summary>
        public void UpdateRestorauntsMenu()
        {
            Restaurant lipaRestaurant = _restaurantQueryRepository.Query(new RestaurantQueryModel {
                Name = Constants.POD_LIPOM_NAME
            })
                                        .Map(x => x.Items.First())
                                        .Reduce(_ => throw new System.Exception());
            Restaurant hedoneRestaurant = _restaurantQueryRepository.Query(new RestaurantQueryModel {
                Name = Constants.HEDONE_NAME
            })
                                          .Map(x => x.Items.First())
                                          .Reduce(_ => throw new System.Exception());
            Restaurant teglasRestaurant = _restaurantQueryRepository.Query(new RestaurantQueryModel {
                Name = Constants.TEGLAS_NAME
            })
                                          .Map(x => x.Items.First())
                                          .Reduce(_ => throw new System.Exception());
            Restaurant indexRestaurant = _restaurantQueryRepository.Query(new RestaurantQueryModel {
                Name = Constants.INDEX_NAME
            })
                                         .Map(x => x.Items.First())
                                         .Reduce(_ => throw new System.Exception());

            DailyMenu lipaDailyMenu = _dailyMenuQueryRepository.Query(new DailyMenuQueryModel {
                RestaurantId = lipaRestaurant.Id
            })
                                      .Map(x => x.Items.FirstOrDefault())
                                      .Reduce(_ => throw new System.Exception());
            DailyMenu hedoneDailyMenu = _dailyMenuQueryRepository.Query(new DailyMenuQueryModel {
                RestaurantId = hedoneRestaurant.Id
            })
                                        .Map(x => x.Items.FirstOrDefault())
                                        .Reduce(_ => throw new System.Exception());
            DailyMenu teglasDailyMenu = _dailyMenuQueryRepository.Query(new DailyMenuQueryModel {
                RestaurantId = teglasRestaurant.Id
            })
                                        .Map(x => x.Items.FirstOrDefault())
                                        .Reduce(_ => throw new System.Exception());
            DailyMenu indexDailyMenu = _dailyMenuQueryRepository.Query(new DailyMenuQueryModel {
                RestaurantId = indexRestaurant.Id
            })
                                       .Map(x => x.Items.FirstOrDefault())
                                       .Reduce(_ => throw new System.Exception());

            // Get food from sheet, update database for new and changed and update daily menu
            var restaurantOffers = _sheetsApi.GetOffers(DateTime.Today).ToList();
            var updateDate       = DateTime.Today;

            UpdateRestaurant(restaurantOffers, lipaRestaurant, lipaDailyMenu, updateDate);
            UpdateRestaurant(restaurantOffers, hedoneRestaurant, hedoneDailyMenu, updateDate);
            UpdateRestaurant(restaurantOffers, teglasRestaurant, teglasDailyMenu, updateDate);
            UpdateRestaurant(restaurantOffers, lipaRestaurant, lipaDailyMenu, updateDate);
        }
예제 #3
0
        public void Run(string[] args)
        {
            ResetDatabase();

            // liefs
            SeedRestaurant();
            SeedLocation();
            SeedRole();

            SeedCustomer(); // restaurant related
            SeedPayment();
            SeedFoods();
            SeedMeal();

            SeedDailyMenu();

            var restaurant = _restaurantQueryRepository.Query(new RestaurantQueryModel {
                Id = 1
            })
                             .Map(x => x.Items.First())
                             .Reduce(_ => throw new Exception());

            _restaurantCommandRepository.Update(restaurant.Id, _mapper.Map <RestaurantUpdateModel>(restaurant));

            var order = new OrderInsertModel()
            {
                CustomerId = 1,
                MealId     = 1,
                Note       = "Test insert"
            };

            this._orderCommandRepo.Insert(order);
        }
예제 #4
0
 public Either <Error, PagingResult <Restaurant> > GetRestorantsWithMenus()
 {
     return(_restaurantRepository.Query(new RestaurantQueryModel()));
 }