public IActionResult Polecany(int i)
        {
            int userid = int.Parse(User.Identity.GetUserId());
            var user   = _context.uzytkownicy.Single(e => e.Id == userid);

            var     recommended_id = PolecanyPosilek(DateTime.Now.Date);
            Posilek recommended    = _context.posilki.First();

            if (recommended_id != -1)
            {
                recommended = _context.posilki.Single(e => e.id_posilku == recommended_id);
            }

            PlanowaniePosilkow plannedMeal = new PlanowaniePosilkow();

            plannedMeal.data           = DateTime.Now;
            plannedMeal.posilek        = recommended;
            plannedMeal.uzytkownik     = user;
            plannedMeal.id_posilku     = recommended.id_posilku;
            plannedMeal.id_uzytkownika = user.Id;

            _context.Add(plannedMeal);
            _context.SaveChanges();

            this.isAdmin();
            return(RedirectToAction(nameof(Index)));
        }
Пример #2
0
        public IActionResult Polecany(int i)
        {
            int userid = int.Parse(User.Identity.GetUserId());
            var user   = _context.uzytkownicy.Single(e => e.Id == userid);

            var     polecay_id = PolecanyPosilek(DateTime.Now.Date);
            Posilek polecany   = _context.posilki.First();

            if (polecay_id != -1)
            {
                polecany = _context.posilki.Single(e => e.id_posilku == polecay_id);
            }

            PlanowaniePosilkow planowany = new PlanowaniePosilkow();

            planowany.data           = DateTime.Now;
            planowany.posilek        = polecany;
            planowany.uzytkownik     = user;
            planowany.id_posilku     = polecany.id_posilku;
            planowany.id_uzytkownika = user.Id;

            _context.Add(planowany);
            _context.SaveChanges();

            return(RedirectToAction(nameof(Index)));

            //return View();
        }
Пример #3
0
        public async Task <IActionResult> Edit(int id, [Bind("id_posilku,nazwa,kalorie,opis,id_uzytkownika")] Posilek posilek)
        {
            if (id != posilek.id_posilku)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(posilek);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PosilekExists(posilek.id_posilku))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["id_uzytkownika"] = new SelectList(_context.uzytkownicy, "Id", "Id", posilek.id_uzytkownika);
            return(View(posilek));
        }
        public IActionResult Polecany()
        {
            var     recommended_id = PolecanyPosilek(DateTime.Now.Date);
            Posilek recommended    = _context.posilki.Include(t => t.obrazy).First();

            if (recommended_id != -1)
            {
                recommended = _context.posilki.Include(t => t.obrazy).Single(e => e.id_posilku == recommended_id);
            }

            ViewBag.mealDetails = _context.posilekSzczegoly.Where(k => k.id_posilku == recommended.id_posilku)
                                  .Include(k => k.skladnik)
                                  .ToList();

            if (recommended.obrazy.Count <= 0)
            {
                ViewBag.image = null;
            }
            else
            {
                ViewBag.image = recommended.obrazy
                                .Last()
                                .GetImageDataUrl();
            }

            ViewBag.polecany = recommended;
            this.isAdmin();
            return(View());
        }
Пример #5
0
        static void main2()
        {
            Creator creator = new ConcreteCreator();
            Posilek produkt = creator.Create("Sniadanie");

            Console.WriteLine(produkt.getName());
        }
Пример #6
0
        public async Task <IActionResult> Create([Bind("id_posilku,nazwa,kalorie,opis,id_uzytkownika")] Posilek posilek)
        {
            if (ModelState.IsValid)
            {
                _context.Add(posilek);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["id_uzytkownika"] = new SelectList(_context.uzytkownicy, "Id", "Id", posilek.id_uzytkownika);
            return(View(posilek));
        }
Пример #7
0
        public async Task <IActionResult> Create([Bind("id_posilku,nazwa,opis")] Posilek posilek)
        {
            posilek.id_uzytkownika = int.Parse(User.Identity.GetUserId());
            if (ModelState.IsValid)
            {
                _context.Add(posilek);
                //podliczanie kalorii
                posilek.kalorie = 0;
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(posilek));
        }
Пример #8
0
        public IActionResult Polecany()
        {
            var     polecay_id = PolecanyPosilek(DateTime.Now.Date);
            Posilek polecany   = _context.posilki.First();

            if (polecay_id != -1)
            {
                polecany = _context.posilki.Single(e => e.id_posilku == polecay_id);
            }

            ViewBag.mealDetails = _context.posilekSzczegoly.Where(k => k.id_posilku == polecay_id)
                                  .Include(k => k.skladnik)
                                  .ToList();

            ViewBag.polecany = polecany;



            return(View());
        }
Пример #9
0
        public async Task <IActionResult> Edit(int id, [Bind("id_posilku,nazwa,opis")] Posilek posilek)
        {
            if (id != posilek.id_posilku)
            {
                return(NotFound());
            }
            Posilek posilekToEdit = await _context.posilki.FindAsync(id);

            if (posilekToEdit.id_uzytkownika != int.Parse(User.Identity.GetUserId()))
            {
                return(RedirectToAction("Details", new { id = posilek.id_posilku }));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    posilekToEdit.nazwa = posilek.nazwa;
                    posilekToEdit.opis  = posilek.opis;
                    _context.Update(posilekToEdit);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PosilekExists(posilek.id_posilku))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewBag.ingredients = await _context.posilekSzczegoly.Where(t => t.id_posilku == posilek.id_posilku)
                                  .Include(t => t.skladnik).ToListAsync();

            this.isDietician();
            return(View(posilek));
        }
Пример #10
0
        public async Task <IActionResult> AddComponent(int id, [Bind("id_skladnika,porcja")] PosilekSzczegoly pszczegoly)
        {
            Posilek posilek = _context.posilki.FirstOrDefault(x => x.id_posilku == id);

            if (posilek == null)
            {
                return(NotFound());
            }

            if (posilek.id_uzytkownika != int.Parse(User.Identity.GetUserId()))
            {
                return(RedirectToAction("Details", new { id = posilek.id_posilku }));
            }

            if (ComponentAlreadyInMeal(posilek.id_posilku, pszczegoly.id_skladnika))
            {
                return(View("AlreadyExists"));
            }

            pszczegoly.id_posilku = id;
            if (pszczegoly.porcja <= 0)
            {
                pszczegoly.porcja = 1;
            }

            if (ModelState.IsValid)
            {
                _context.Add(pszczegoly);

                editCalories(true, pszczegoly);

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(AddComponent), new { id = posilek.id_posilku }));
            }
            ViewBag.posilekId        = id;
            ViewData["id_skladnika"] = new SelectList(_context.skladnik, "id_skladnika", "nazwa", pszczegoly.id_skladnika);
            this.isDietician();
            return(View(pszczegoly));
        }