コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,UpperCategoryId")] AparatKategoria aparatKategoria)
        {
            if (id != aparatKategoria.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(aparatKategoria);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AparatKategoriaExists(aparatKategoria.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UpperCategoryId"] = new SelectList(_context.Kategorie, "Id", "Name", aparatKategoria.UpperCategoryId);
            return(View(aparatKategoria));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Id,Name,UpperCategoryId")] AparatKategoria aparatKategoria)
        {
            if (ModelState.IsValid)
            {
                if (!KategoriaNameExists(aparatKategoria.Name))
                {
                    _context.Add(aparatKategoria);
                    await _context.SaveChangesAsync();

                    ViewBag.DuplicateMessage = "";
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    ViewBag.DuplicateMessage = "This already exists";
                }
            }
            ViewData["UpperCategoryId"] = new SelectList(_context.Kategorie, "Id", "Name", aparatKategoria.UpperCategoryId);
            return(View(aparatKategoria));
        }
コード例 #3
0
        public IActionResult Menu(int?id)
        {
            CookieOptions option = new CookieOptions();

            option.Expires = DateTime.Now.AddMinutes(3);
            AparatKategoria        kategoria = null;
            int?                   katUpper  = 0;
            int?                   x;
            List <AparatViewModel> ListaDisplAP = new List <AparatViewModel>();


            if (id == null)
            {
                id = 1;
            }

            Response.Cookies.Append("currentPageCookie", id.ToString(), option);

            kategoria = _context.Kategorie.Find(id);
            katUpper  = _context.Kategorie.Find(id).UpperCategoryId;

            if (kategoria == null)
            {
                return(NotFound());
            }
            if (Request.Cookies["currentPageCookie"] != null)
            {
                x = (int.Parse(Request.Cookies["currentPageCookie"]));
            }
            else
            {
                x = (int)id;
                Response.Cookies.Append("currentPageCookie", id.ToString(), option);
            }
            if ((Request.Cookies["currentPageCookie"] != null) && ((int.Parse(Request.Cookies["currentPageCookie"])) != (int)id))
            {
                x = (int)id;
            }
            ViewBag.SubCategories = (from category in _context.Kategorie where category.UpperCategoryId == x select category).ToList();
            ViewBag.UpperCategory = _context.Kategorie.FirstOrDefault(x => (x.Id == kategoria.UpperCategoryId));
            List <AparatViewModel> ListaAP = (from aparat in _context.Aparaty select aparat).ToList();

            foreach (AparatViewModel ap in ListaAP)
            {
                int LocalCat = ap.AparatKategoriaId;
                if (LocalCat == x)
                {
                    ListaDisplAP.Add(ap);
                }
                else
                {
                    while (_context.Kategorie.Find(LocalCat).UpperCategoryId.HasValue)
                    {
                        LocalCat = (int)_context.Kategorie.Find(LocalCat).UpperCategoryId;
                        if (LocalCat == x)
                        {
                            ListaDisplAP.Add(ap);
                        }
                    }
                }
            }

            ViewBag.Aparaty = ListaDisplAP;

            return(View(kategoria));
        }