Пример #1
0
        public IActionResult Uredi(int NarucilacId, int KorisnickiNalogId)
        {
            Narucilac       n  = _db.Narucilac.Find(NarucilacId);
            KorisnickiNalog kn = _db.KorisnickiNalog.Where(w => w.Id == n.KorisnickiNalogId).SingleOrDefault();

            NarucilacUrediVM model = new NarucilacUrediVM();

            model.gradLista = _db.Grad.Select(x => new SelectListItem
            {
                Text  = x.Naziv,
                Value = x.GradId.ToString()
            }).ToList();

            model.NarucilacId   = NarucilacId;
            model.ImePrezime    = n.ImePrezime;
            model.GradId        = n.GradId;
            model.KorisnickoIme = n.KorisnickiNalog.KorisnickoIme;
            model.Lozinka       = n.KorisnickiNalog.Lozinka;

            model.Telefon = n.Telefon;
            model.Email   = n.Email;
            model.Adresa  = n.Adresa;

            model.gradLista = _db.Grad.Select(x => new SelectListItem
            {
                Text  = x.Naziv,
                Value = x.GradId.ToString()
            }).ToList();

            return(View(model));
        }
Пример #2
0
        public IActionResult UrediSave(NarucilacUrediVM model)
        {
            Narucilac       n  = _db.Narucilac.Find(model.NarucilacId);
            KorisnickiNalog kn = _db.KorisnickiNalog.Where(w => w.Id == n.KorisnickiNalogId).FirstOrDefault();

            if (n == null)
            {
                n  = new Narucilac();
                kn = new KorisnickiNalog();
                _db.Add(kn);
                _db.Add(n);
            }
            kn.KorisnickoIme    = model.KorisnickoIme;
            kn.Lozinka          = model.Lozinka;
            n.ImePrezime        = model.ImePrezime;
            n.KorisnickiNalogId = kn.Id;
            n.Email             = model.Email;
            n.Telefon           = model.Telefon;
            n.Adresa            = model.Adresa;
            n.GradId            = model.GradId;

            _db.SaveChanges();
            return(Redirect("/ModulKorisnik/Narucilac/Index?KorisnikId=" + kn.Id));
        }