public async Task <Result <ICollection <RestaurantViewModel> > > HandleAsync(GetAllRestaurantsQuery query, User currentUser, CancellationToken cancellationToken = default) { if (query == null) { throw new ArgumentNullException(nameof(query)); } if (currentUser == null) { return(FailureResult <ICollection <RestaurantViewModel> > .Unauthorized()); } if (currentUser.Role < Role.SystemAdmin) { return(FailureResult <ICollection <RestaurantViewModel> > .Forbidden()); } var paymentMethods = (await paymentMethodRepository.FindAllAsync(cancellationToken)) .ToDictionary(en => en.Id.Value, PaymentMethodViewModel.FromPaymentMethod); var restaurants = await restaurantRepository.FindAllAsync(cancellationToken); return(SuccessResult <ICollection <RestaurantViewModel> > .Create(restaurants .Select(en => RestaurantViewModel.FromRestaurant(en, paymentMethods, userRepository)).ToList())); }
public Task <IEnumerable <Restaurant> > Handle(GetAllRestaurantsQuery request, CancellationToken cancellationToken) { return(Task.FromResult(_repo.GetAll())); }
public Task <IEnumerable <RestaurantViewModel> > Handle(GetAllRestaurantsQuery request, CancellationToken cancellationToken) { var restaurants = _restaurantsService.GetAllResturants().Select(r => new RestaurantViewModel(r)); return(Task.FromResult(restaurants)); }