public IActionResult Uredi(int StudentID)
        {
            if (HttpContext.GetLogiraniKorisnik() == null)
            {
                return(Redirect("/Autentifikacija/Index"));
            }
            MojDbContext          db     = new MojDbContext();
            List <SelectListItem> opcine = db.Opcina.OrderBy(a => a.NazivOpcine).Select(a => new SelectListItem {
                Value = a.ID.ToString(), Text = a.NazivOpcine
            }).ToList();

            //ViewData["opcine"] = opcine;
            StudentDodajVM tempStudent = StudentID == 0 ? new StudentDodajVM() : db.Student.Where(w => w.ID == StudentID)
                                         .Select(a => new StudentDodajVM
            {
                ID  = a.ID,
                Ime = a.Ime,
                OpcinaPrebivalistaID = a.OpcinaPrebivalistaID,
                OpcinaRodjenjaID     = a.OpcinaRodjenjaID,
                Prezime = a.Prezime
            }).Single();

            tempStudent.Opcine = opcine;

            //ViewData["student"] = tempStudent;

            return(View("Uredi", tempStudent));
        }
        public IActionResult Snimi(StudentDodajVM x)
        {
            if (HttpContext.GetLogiraniKorisnik() == null)
            {
                return(Redirect("/Autentifikacija/Index"));
            }
            MojDbContext db = new MojDbContext();

            Student student;

            if (x.ID == 0)
            {
                student = new Student();
                db.Add(student);
                TempData["porukaInfo"] = "Uspješno ste dodali studenta " + x.Ime;
            }
            else
            {
                student = db.Student.Find(x.ID);
                TempData["porukaInfo"] = "Uspješno ste editovali studenta " + student.Ime;
            }


            student.Ime                  = x.Ime;
            student.Prezime              = x.Prezime;
            student.OpcinaRodjenjaID     = x.OpcinaRodjenjaID;
            student.OpcinaPrebivalistaID = x.OpcinaPrebivalistaID;


            db.SaveChanges();

            return(Redirect("/Student/Poruka"));
        }
Exemple #3
0
        public IActionResult Snimi(StudentDodajVM x)
        {
            Student student;

            if (x.id == 0) //insert
            {
                student          = new Student();
                student.Korisnik = new Korisnik
                {
                };
                _db.Add(student);
                TempData["PorukaInfo"] = "Uspješno ste dodali studenta " + x.ime; //transport podataka iz akcije 1 u (akciju 2 + njegov view)
            }
            else
            {                                                                          //update
                student = _db.Student.Include(s => s.Korisnik).Single(s => s.ID == x.id);
                TempData["PorukaInfo"] = "Uspješno ste updateovali studenta " + x.ime; //transport podataka iz akcije 1 u (akciju 2 + njegov view)
            }

            student.Korisnik.Ime            = x.ime;
            student.Korisnik.Email          = x.email;
            student.Korisnik.EmailConfirmed = true;
            student.Korisnik.UserName       = x.email;
            student.Korisnik.Prezime        = x.prezime;
            student.OpstinaPrebivalistaID   = x.opstinaPrebivalistaID;
            student.OpstinaRodjenjaID       = x.opstinaRodjenjaID;


            if (x.slikaStudentaNew != null)
            {
                string ekstenzija  = Path.GetExtension(x.slikaStudentaNew.FileName);
                string contentType = x.slikaStudentaNew.ContentType;

                var    filename = $"{Guid.NewGuid()}{ekstenzija}";
                string folder   = "wwwroot/uploads/";
                bool   exists   = System.IO.Directory.Exists(folder);
                if (!exists)
                {
                    System.IO.Directory.CreateDirectory(folder);
                }

                x.slikaStudentaNew.CopyTo(new FileStream(folder + filename, FileMode.Create));
                student.SlikaStudenta = filename;
            }

            if (x.id == 0)
            {
                _ = _userManager.CreateAsync(student.Korisnik, "Mostar2020!").Result;
            }

            _db.SaveChanges(); //insert into Student value (...) ili update Student

            return(Redirect("/Student"));
        }
Exemple #4
0
        public IActionResult Uredi(int StudentID)
        {
            //if (HttpContext.GetLogiraniKorisnik() == null)
            //    return Redirect("/Autentifikacija/Index");

            List <SelectListItem> opstine = db.Opstina
                                            .OrderBy(o => o.Naziv)
                                            .Select(o => new SelectListItem
            {
                Value = o.ID.ToString(),
                Text  = o.Naziv
            })
                                            .ToList();

            //ViewData["opstine"] = opstine;
            // StudentDodajVM s = StudentID == 0 ? new StudentDodajVM()
            StudentDodajVM s;

            if (StudentID == 0)
            {
                s = new StudentDodajVM()
                {
                }
            }
            ;
            else
            {
                s = db.Student
                    .Where(s => s.ID == StudentID)
                    .Select(s => new StudentDodajVM
                {
                    ID      = s.ID,
                    Ime     = s.Ime,
                    Prezime = s.Prezime,
                    OpstinaPrebivalistaID = s.OpstinaPrebivalistaID,
                    OpstinaRodjenjaID     = s.OpstinaRodjenjaID,
                }).Single();
            }
            s.opstine = opstine;

            //  ViewData["student"] = s;
            return(View("Uredi", s));
        }
        public IActionResult Uredi(int StudentID)
        {
            List <SelectListItem> opstine = _db.Opstina
                                            .OrderBy(a => a.Naziv)
                                            .Select(a => new SelectListItem
            {
                Text  = a.Naziv,
                Value = a.ID.ToString()
            })
                                            .ToList();

            StudentDodajVM s;

            if (StudentID == 0)
            {
                s = new StudentDodajVM()
                {
                }
            }
            ;
            else
            {
                s = _db.Student
                    .Where(w => w.ID == StudentID)
                    .Select(a => new StudentDodajVM
                {
                    id      = a.ID,
                    ime     = a.Korisnik.Ime,
                    prezime = a.Korisnik.Prezime,
                    email   = a.Korisnik.Email,
                    opstinaPrebivalistaID = a.OpstinaPrebivalistaID,
                    opstinaRodjenjaID     = a.OpstinaRodjenjaID,
                    slikaStudentaCurrent  = a.SlikaStudenta
                                            //opstine = opstine
                }).Single();
            }

            s.opstine = opstine;

            return(Ok(s));
        }
Exemple #6
0
        public IActionResult Dodaj()
        {
            StudentDodajVM model = new StudentDodajVM
            {
                gradovi = VirtualDB.Grad.Select(s => new SelectListItem
                {
                    Value = s.id.ToString(),
                    Text  = s.Naziv
                }).ToList(),
                zanimanja = new List <SelectListItem> {
                    new SelectListItem {
                        Text = "IT"
                    },
                    new SelectListItem {
                        Text = "DevOps"
                    },
                    new SelectListItem {
                        Text = "Developer"
                    },
                }
            };

            return(View(model));
        }