public async Task <MealDto> UpdateMeal(int mealId, MealDto meal)
        {
            var myMeal = await _mealRepository.GetMeal(mealId);

            if (myMeal == null)
            {
                _logger.LogInformation("Error while changing a meal");
                throw new MealNotFoundException();
            }
            var result = await _mealRepository.UpdateMeal(meal);

            return(result);
        }
Example #2
0
        public Meal GetMeal(string userId, int mealId)
        {
            DataTable mealTable        = _mealRepository.GetMeal(mealId);
            DataTable ingredientsTable = _ingredientRepository.GetIngredients(userId, mealId);

            return(_mealMapper.HydrateMeal(mealTable, ingredientsTable).FirstOrDefault());
        }
Example #3
0
        public void CopyRecipe(int id)
        {
            var model = _mealRepository.GetMeal(id);

            var newMeal = new Meal()
            {
                Name     = model.Name,
                MealType = model.MealType,
                Who      = model.Who == Who.Cathal ? Who.Yasmin : Who.Cathal
            };
            int newid = _mealRepository.Add(newMeal);

            foreach (var item in model.MealIngredients)
            {
                //copy ingredient with meaure = null
                int newIngredientId = CopyIngredient(item.IngredientId);

                var newIngredient = new MealIngredient()
                {
                    IngredientId = newIngredientId,
                    MealId       = newid
                };
                _mealIngredientRepository.Add(newIngredient);
            }
        }
Example #4
0
        public ViewModels.MealForListVm GetMeal(int mealId)
        {
            var meal   = _mealRepo.GetMeal(mealId);
            var mealVm = _mapper.Map <ViewModels.MealForListVm>(meal);

            mealVm.Items = new List <ItemInMealDetailVm>();
            var itemsInMeal = _itemInMealService.GetAllItemsInMeal(mealVm.Id);

            foreach (var e in itemsInMeal)
            {
                var item = _itemService.GetItemById(e.ItemId);
                var itemInMealDetailVm = CreateItemInMealDetailVm(item, itemsInMeal);
                mealVm.Items.Add(itemInMealDetailVm);
            }
            return(mealVm);
        }
Example #5
0
        public MealModel GetMeal(LoginModel loggedInUser, int userId, int mealId)
        {
            CheckPermission(loggedInUser, userId, "You can't get other's meal.");
            var meal = _mealRepository.GetMeal(userId, mealId);

            if (meal == null)
            {
                throw new NoContentException("Meal does not exists.");
            }
            return(meal);
        }
        public IActionResult Index(int id)
        {
            var model    = _mealingredientRepository.GetIngredientsForMeal(id);
            var newModel = new List <MealIngredientViewModel>();

            foreach (var item in model)
            {
                var temp = new MealIngredientViewModel();
                temp.Id       = item.Ingredient.Id;
                temp.ItemName = item.Ingredient.Item.Name;
                temp.Measure  = item.Ingredient.Measure;
                temp.Unit     = item.Ingredient.Item.Unit;
                temp.MealId   = id;
                newModel.Add(temp);
            }
            var meal = _mealRepository.GetMeal(id);

            ViewBag.MealName = meal.Name;
            ViewBag.MealId   = meal.Id;
            return(View(newModel));
        }
Example #7
0
        public IActionResult Show(int mealId)
        {
            // Get student from logged in user
            Student student = studentRepository.GetStudent(GetUserId());

            ViewBag.UserIsLoggedIn = student != null;
            // Render view with meal transformed into meal date
            return(View(MealTransformer.TransformIntoMealDate(mealRepository.GetMeal(mealId), student)));
        }
Example #8
0
        public async Task <ScheduledMealDto> ScheduleMeal(int userId, int mealId, DateTime date)
        {
            var user = await _userRepository.GetUser(userId);

            if (user == null)
            {
                _logger.LogInformation("Error while scheduling a meal");
                throw new UserNotFoundException();
            }

            var meal = await _mealRepository.GetMeal(mealId);

            if (meal == null)
            {
                _logger.LogInformation("Error while scheduling a meal");
                throw new MealNotFoundException();
            }
            var result = await _scheduledMealRepository.CreateScheduledMeal(userId, mealId, date);

            return(result);
        }
Example #9
0
 public Meal GetMealById(int id)
 {
     return(_repository.GetMeal(id));
 }
Example #10
0
        public IActionResult Edit(int id)
        {
            var model = _mealRepository.GetMeal(id);

            return(View(model));
        }
        public InfoScreenQuery(
            ILunchplanRepository lunchplans,
            IMealRepository meals,
            IMessageRepository messages,
            IAdminRepository admins
            )
        {
            Name = "Query";

            FieldAsync <AdminType>(
                "admin",
                arguments: new QueryArguments(
                    new QueryArgument <IntGraphType> {
                Name = "id"
            },
                    new QueryArgument <StringGraphType> {
                Name = "username"
            }
                    ),
                resolve: async ctx =>
            {
                if (ctx.HasArgument("id"))
                {
                    return(await admins.GetAdmin(ctx.GetArgument <int>("id")));
                }
                if (ctx.HasArgument("username"))
                {
                    return(await admins.FindByUsername(ctx.GetArgument <string>("username")));
                }
                return(null);
            }
                );

            FieldAsync <LunchplanType>(
                "lunchplan",
                arguments: new QueryArguments(
                    new QueryArgument <IntGraphType> {
                Name = "week"
            }
                    ),
                resolve: async ctx =>
            {
                if (ctx.HasArgument("week"))
                {
                    return(await lunchplans.GetLunchplan(ctx.GetArgument <int>("week")));
                }
                return(null);
            }
                );

            FieldAsync <MealType>(
                "meal",
                arguments: new QueryArguments(
                    new QueryArgument <IntGraphType> {
                Name = "id"
            }
                    ),
                resolve: async ctx =>
            {
                if (ctx.HasArgument("id"))
                {
                    return(await meals.GetMeal(ctx.GetArgument <int>("id")));
                }
                return(null);
            }
                );

            FieldAsync <ListGraphType <MealType> >(
                "meals",
                resolve: async ctx => await meals.ListMeals()
                );

            FieldAsync <MessageType>(
                "message",
                arguments: new QueryArguments(
                    new QueryArgument <IntGraphType> {
                Name = "id"
            }
                    ),
                resolve: async ctx =>
            {
                if (ctx.HasArgument("id"))
                {
                    return(await messages.GetMessage(ctx.GetArgument <int>("id")));
                }
                return(null);
            }
                );

            FieldAsync <ListGraphType <MessageType> >(
                "messages",
                resolve: async ctx => await messages.ListMessages()
                );

            FieldAsync <MessageType>(
                "newestMessage",
                resolve: async ctx => await messages.GetNewestMessage()
                );
        }
Example #12
0
        public ActionResult Details(int id)
        {
            MealDetailView view = new MealDetailView(repository.GetMeal(id), repository.GetStudentsMeal(id));

            return(View(view));
        }