Beispiel #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));
        }
 public ActionResult beleziPrisustvo2(SkolaViewModel skolaView)
 {
     foreach (var i in skolaView.studenti)
     {
         prisustvuje prisustvuje = new prisustvuje {
             CasID_FK     = skolaView.idCas,
             StudentID_FK = i.StudentID,
             prisutan     = i.isChecked
         };
         db.prisustvujes.Add(prisustvuje);
         db.SaveChanges();
     }
     TempData["SuccMsg"] = "Uspešno upisano prisustvo";
     return(RedirectToAction("Prisustvo"));
 }
Beispiel #3
0
        public ActionResult IzmeniSkolu(SkolaViewModel skola, long?id)
        {
            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.");
            }
            var s = _context.Skola.Find(id);

            if (s == null)
            {
                return(new HttpNotFoundResult());
            }
            s.Naziv         = skola.Naziv;
            s.Adresa        = skola.Adresa;
            s.Opstina       = skola.Opstina;
            s.PostanskiBroj = skola.PostanskiBroj;
            s.MaticniBroj   = skola.MaticniBroj;
            s.PIB           = skola.PIB;
            s.BrojRacuna    = skola.BrojRacuna;
            s.WebStranica   = skola.WebStranica;
            s.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.Entry(s).State = EntityState.Modified;
            _context.SaveChanges();
            return(View(skola));
        }
Beispiel #4
0
        public ActionResult DodajSkolu()
        {
            var svm = new SkolaViewModel();

            return(View(svm));
        }
Beispiel #5
0
 public ActionResult Izmeni(SkolaViewModel skola, long?id)
 {
     IzmeniSkolu(skola, id);
     return(RedirectToAction("Index", "Skola"));
 }