Пример #1
0
        public ActionResult DodajSkolu(SkolaViewModel skola)
        {
            var validImageTypes = new string[]
            {
                "image/gif",
                "image/jpeg",
                "image/pjpeg",
                "image/png"
            };

            if (skola.ImageUpload == null || skola.ImageUpload.ContentLength == 0)
            {
                ModelState.AddModelError("ImageUpload", "This field is required");
            }
            else if (!validImageTypes.Contains(skola.ImageUpload.ContentType))
            {
                ModelState.AddModelError("ImageUpload", "Please choose either a GIF, JPG or PNG image.");
            }

            if (ModelState.IsValid)
            {
                var s = new Skola
                {
                    IdSkole       = skola.IdSkole,
                    Naziv         = skola.Naziv,
                    Adresa        = skola.Adresa,
                    Opstina       = skola.Opstina,
                    PostanskiBroj = skola.PostanskiBroj,
                    MaticniBroj   = skola.MaticniBroj,
                    PIB           = skola.PIB,
                    BrojRacuna    = skola.BrojRacuna,
                    WebStranica   = skola.WebStranica,
                    Beleska       = skola.Beleska
                };

                if (skola.ImageUpload != null && skola.ImageUpload.ContentLength > 0)
                {
                    var uploadDir = "~/Slike";
                    var imagePath = Path.Combine(Server.MapPath(uploadDir), skola.ImageUpload.FileName);
                    var imageUrl  = Path.Combine(uploadDir, skola.ImageUpload.FileName);
                    skola.ImageUpload.SaveAs(imagePath);
                    s.Pecat = imageUrl;
                }

                _context.Skola.Add(s);
                _context.SaveChanges();
                return(RedirectToAction("Index", "Skola"));
            }

            return(View(skola));
        }
Пример #2
0
 public ActionResult DodajTipMaila(TipMailaViewModel tipM)
 {
     if (ModelState.IsValid)
     {
         var tm = new TipMaila
         {
             IdTipaMaila = tipM.IdTipaMaila,
             Tip         = tipM.Tip
         };
         _context.TipMaila.Add(tm);
         _context.SaveChanges();
         return(RedirectToAction("Index", "TipMaila"));
     }
     return(View(tipM));
 }
Пример #3
0
 public ActionResult DodajTipTelefona(TipTelefonaViewModel tipT)
 {
     if (ModelState.IsValid)
     {
         var tt = new TipTelefona
         {
             IdTipaTelefona = tipT.IdTipaTelefona,
             Tip            = tipT.Tip
         };
         _context.TipTelefona.Add(tt);
         _context.SaveChanges();
         return(RedirectToAction("Index", "TipTelefona"));
     }
     return(View(tipT));
 }
 public ActionResult DodajKorisnika(KorisnikViewModel korisnik)
 {
     if (ModelState.IsValid)
     {
         var k = new Korisnik
         {
             IdKorisnika   = korisnik.IdKorisnika,
             KorisnickoIme = korisnik.KorisnickoIme,
             Lozinka       = korisnik.Lozinka,
             PravoPristupa = korisnik.PravoPristupa
         };
         _context.Korisnik.Add(k);
         _context.SaveChanges();
         return(RedirectToAction("Index", "Korisnik"));
     }
     return(View(korisnik));
 }
Пример #5
0
 public ActionResult DodajTelefon(KontaktTelefon kontaktTelefon)
 {
     if (!ModelState.IsValid)
     {
         var viewModel = new KontaktTelefonViewModel
         {
             IdTelefona   = kontaktTelefon.IdTelefona,
             BrojTelefona = kontaktTelefon.BrojTelefona,
             Lokal        = kontaktTelefon.Lokal,
             Tipovi       = _context.TipTelefona.ToList(),
             Osobe        = _context.Osoba.ToList()
         };
         return(View("DodajTelefon", viewModel));
     }
     _context.KontaktTelefon.Add(kontaktTelefon);
     _context.SaveChanges();
     return(RedirectToAction("Index", "KontaktTelefon"));
 }
Пример #6
0
        public ActionResult DodajMail(MailListe mailListe)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new MailListeViewModel
                {
                    IdMaila = mailListe.IdMaila,
                    Adresa  = mailListe.Adresa,
                    Osobe   = _context.Osoba.ToList(),
                    Tipovi  = _context.TipMaila.ToList()
                };
                return(View("DodajMail", viewModel));
            }

            _context.MailListe.Add(mailListe);
            _context.SaveChanges();
            return(RedirectToAction("Index", "MailListe"));
        }
Пример #7
0
        public ActionResult DodajOsobu(Osoba osoba)
        {
            if (!ModelState.IsValid)
            {
                var s = new OsobaViewModel
                {
                    IdOsobe    = osoba.IdOsobe,
                    Ime        = osoba.Ime,
                    Prezime    = osoba.Prezime,
                    RadnoMesto = osoba.RadnoMesto,
                    Skole      = _context.Skola.ToList()
                };

                return(View("DodajOsobu", s));
            }
            _context.Osoba.Add(osoba);
            _context.SaveChanges();
            return(RedirectToAction("Index", "Osoba"));
        }
        public ActionResult Izbrisi(long?id, FormCollection fcNotUsed)
        {
            SkolaContext _context;

            _context = new SkolaContext();
            var korisnik = _context.Korisnik.Where(x => x.IdKorisnika == id).FirstOrDefault();

            _context.Korisnik.Remove(korisnik);
            _context.SaveChanges();
            return(RedirectToAction("Index", "Korisnik"));
        }
Пример #9
0
        public ActionResult Izbrisi(long?id, FormCollection fcNotUsed)
        {
            SkolaContext _context;

            _context = new SkolaContext();
            var osoba = _context.Osoba.Where(x => x.IdOsobe == id).FirstOrDefault();

            _context.Osoba.Remove(osoba);
            _context.SaveChanges();
            return(RedirectToAction("Index", "Osoba"));
        }