Ejemplo n.º 1
0
        public ActionResult New()
        {
            if (User.IsInRole(RoleName.CanManagePredmiot))
            {
                var kategoria = _context.Kategorias.ToList();
                var producent = _context.Producents.ToList();

                var viewModel = new NewPrzedmiotViewModel
                {
                    Przedmiot = new Przedmiot(),
                    Kategoria = kategoria,
                    Producent = producent
                };
                return(View(viewModel));
            }

            return(View("ReadOnlyList"));
        }
Ejemplo n.º 2
0
        public ActionResult Edit(int id)
        {
            if (User.IsInRole(RoleName.CanManagePredmiot))
            {
                var przedmiot = _context.Przedmiots.SingleOrDefault(c => c.ID == id);


                if (przedmiot == null)
                {
                    return(HttpNotFound());
                }

                var viewModel = new NewPrzedmiotViewModel()
                {
                    Przedmiot = przedmiot,
                    Producent = _context.Producents.ToList(),
                    Kategoria = _context.Kategorias.ToList()
                };
                return(View("New", viewModel));
            }

            return(View("ReadOnlyList"));
        }
Ejemplo n.º 3
0
        public ActionResult Save(Przedmiot przedmiot)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new NewPrzedmiotViewModel
                {
                    Przedmiot = przedmiot,
                    Kategoria = _context.Kategorias.ToList(),
                    Producent = _context.Producents.ToList()
                };


                return(View("New", viewModel));
            }



            if (przedmiot.ID == 0)
            {
                _context.Przedmiots.Add(przedmiot);
            }
            else
            {
                var przedmiotDb = _context.Przedmiots.Single(c => c.ID == przedmiot.ID);

                przedmiotDb.Nazwa       = przedmiot.Nazwa;
                przedmiotDb.Cena        = przedmiot.Cena;
                przedmiotDb.Opis        = przedmiot.Opis;
                przedmiotDb.Zdjecie     = przedmiot.Zdjecie;
                przedmiotDb.ProducentId = przedmiot.ProducentId;
                przedmiotDb.KategoriaId = przedmiot.KategoriaId;
            }

            _context.SaveChanges();
            return(RedirectToAction("Index", "Przedmiots"));
        }