public async Task <ActionResult <Pagination <MealToReturnDto> > > GetMeals([FromQuery] MealSpecParams mealParams) { var spec = new MealsWithTypesAndMenusSpecification(mealParams); var countSpec = new MealWithFiltersForCountSpecification(mealParams); var totalItems = await _unitOfWork.Repository <Meal>().CountAsync(countSpec); var meals = await _unitOfWork.Repository <Meal>().ListAsync(spec); var mealsToReturn = new List <Meal>(); foreach (var meal in meals) { if (meal.Stock > 0) { mealsToReturn.Add(meal); } if (meal.Stock < 1) { totalItems--; } } var data = _mapper.Map <IReadOnlyList <Meal>, IReadOnlyList <MealToReturnDto> >(mealsToReturn); return(Ok(new Pagination <MealToReturnDto>(mealParams.PageIndex, mealParams.PageSize, totalItems, data))); }
public async Task <ActionResult <Pagination <MealToReturnDto> > > GetMeals([FromQuery] MealSpecParams mealParams) { var spec = new MealsWithTypesSpecification(mealParams); var countSpec = new MealWithFiltersForCountSpecification(mealParams); var totalItems = await _mealsRepo.CountAsync(countSpec); var meals = await _mealsRepo.ListAsync(spec); var data = _mapper.Map <IReadOnlyList <Meal>, IReadOnlyList <MealToReturnDto> >(meals); return(Ok(new Pagination <MealToReturnDto>(mealParams.PageIndex, mealParams.PageSize, totalItems, data))); }
public async Task <ActionResult <Pagination <MealToReturnDto> > > GetMealsForManager([FromQuery] MealSpecParams mealParams) { var spec = new MealsWithTypesAndMenusSpecification(mealParams); var email = HttpContext.User.RetrieveEmailFromPrincipal(); var user = await _userManager.FindByEmailAsync(email); var restaurants = await _unitOfWork.Repository <Restaurant>().ListAllAsync(); foreach (var restaurant in restaurants) { if (restaurant.Name == user.DisplayName) { mealParams.RestaurantId = restaurant.Id; } } ; var countSpec = new MealWithFiltersForCountSpecification(mealParams); var totalItems = await _unitOfWork.Repository <Meal>().CountAsync(countSpec); var meals = await _unitOfWork.Repository <Meal>().ListAsync(spec); var data = _mapper.Map <IReadOnlyList <Meal>, IReadOnlyList <MealToReturnDto> >(meals); return(Ok(new Pagination <MealToReturnDto>(mealParams.PageIndex, mealParams.PageSize, totalItems, data))); }