Exemplo n.º 1
0
    public ActionResult Add(PizzaFormViewModel PizzaFormViewModel)
    {
        if (!ModelState.IsValid)
        {
            return(View("Add", PizzaFormViewModel));
        }
        else
        {
            Dodatek dodatek = new Dodatek();
            dodatek.Id   = 1;
            dodatek.Name = "ser";
            _context.Add <Dodatek>(dodatek);

            Pizza pizza = new Pizza();
            pizza.Id        = 1;
            pizza.Name      = "Carbonara";
            pizza.Price     = 19.99M;
            pizza.DodatekId = 1;
            pizza.Dodatek   = dodatek;
            _context.Add <Pizza>(pizza);

            _context.SaveChanges();
            return(RedirectToAction("All", "Pizza"));
        }
    }
Exemplo n.º 2
0
    //[Authorize(Roles = "Admin")]
    public ActionResult Save(Dodatek Dodatek)
    {
        if (Dodatek.Id == 0)
        {
            _context.Add(Dodatek);
        }
        else
        {
            var DodatekInDb = _context.Dodatki.Single(c => c.Id == Dodatek.Id);
            DodatekInDb.Name = Dodatek.Name;
        }

        _context.SaveChanges();

        return(RedirectToAction("Index", "Pizza"));
    }