コード例 #1
0
        public async Task <IActionResult> Create([Bind("StuId,FirstName,LastName,mClassName")] MasterStudent masterStudent, string SelSubjectList)
        {
            if (ModelState.IsValid)
            {
                _context.Add(masterStudent);
                if (!string.IsNullOrEmpty(SelSubjectList))
                {
                    List <SubjectList>        list = JsonConvert.DeserializeObject <List <SubjectList> >(SelSubjectList);
                    List <SubjectStudentWise> lst  = list.Select(s => new SubjectStudentWise()
                    {
                        sswStudentId = masterStudent.StuId, sswSubjectId = s.id, sswStudentMarks = Convert.ToDecimal(s.marks)
                    }).ToList();
                    _context.SubjectStudentWises.AddRange(lst);
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }


            ViewData["mClassName"] = new SelectList(_context.MasterClasses, "mClassId", "mClassName", masterStudent.mClassName);
            ViewBag.SubjectList    = _context.MasterSubjects.Where(s => s.IsActive == true).ToList();
            ViewBag.SelSubjectList = SelSubjectList;
            return(View(masterStudent));
        }
コード例 #2
0
        public IActionResult KreirajStudenta(IFormCollection forma)
        {
            NumberFormatInfo format = new NumberFormatInfo();

            format.NumberDecimalSeparator = ".";
            if (forma["BScInfo"].Equals("3")) //ako osoba nije završila BSc tada se upisuje kao običan a ne MasterStudent -> nema potrebe za ekvivalentiranjem
            {
                if (!forma["izabraniSmjer"].Equals("Izaberite smjer"))
                {
                    Student noviStudent = new Student(forma["ime"], forma["prezime"], forma["datumRodjenja"], forma["prebivaliste"], null, null, forma["izabraniSpol"], forma["izabraniSmjer"], null);
                    if (validirajStudenta(noviStudent))
                    {
                        logg.generišiKorisničkePodatke(noviStudent);
                        return(RedirectToAction("UspješnoKreiranStudent", new { id = noviStudent.BrojIndeksa }));
                    }
                    else
                    {
                        return(RedirectToAction("prikaziGresku", new { lokacija = "kreiraj-studenta", idPoruke = 1 }));
                    }
                }

                else
                {
                    return(RedirectToAction("prikaziGresku", new { lokacija = "kreiraj-studenta", idPoruke = 1 }));
                }
            }
            else if (forma["BScInfo"].Equals("1")) // osoba je završila BSc studij na ovom fakultetu
            {
                if (!forma["izabraniSmjer"].Equals("Izaberite smjer"))
                {
                    MasterStudent noviStudent = new MasterStudent(forma["ime"], forma["prezime"], forma["datumRodjenja"], forma["prebivaliste"], null, null, forma["izabraniSpol"], forma["izabraniSmjer"], null, double.Parse(forma["prosjekBSC"], format));
                    if (validirajStudenta(noviStudent))
                    {
                        logg.generišiKorisničkePodatke(noviStudent);
                        return(RedirectToAction("UspješnoKreiranStudent", new { id = noviStudent.BrojIndeksa }));
                    }
                    else
                    {
                        return(RedirectToAction("prikaziGresku", new { lokacija = "kreiraj-studenta", idPoruke = 1 }));
                    }
                }
            }
            else if (forma["BScInfo"].Equals("2")) //osoba je završila BSc ali na nekom drugom fakultetu pa će ovdje trebati implementirati onaj adapter pattern --- ovo ranije sve radi!
            {
                MasterStudentAdapter adapter     = new MasterStudentAdapter();
                MasterStudent        noviStudent = new MasterStudent(forma["ime"], forma["prezime"], forma["datumRodjenja"], forma["prebivaliste"], null, null, forma["izabraniSpol"], forma["izabraniSmjer"], null, double.Parse(forma["prosjekBSC"], format));
                if (validirajStudenta(noviStudent))
                {
                    logg.generišiKorisničkePodatke(adapter.ekvivalentirajStudenta(noviStudent, int.Parse(forma["drzavaBSC"])));
                    return(RedirectToAction("UspješnoKreiranStudent", new { id = noviStudent.BrojIndeksa }));
                }
                else
                {
                    return(RedirectToAction("prikaziGresku", new { lokacija = "kreiraj-studenta", idPoruke = 1 }));
                }
            }
            return(null);
        }
コード例 #3
0
 private bool validirajStudenta(Student tempStudent)
 {
     if (tempStudent is MasterStudent)
     {
         MasterStudent noviStudent = (MasterStudent)tempStudent;
         return(!(noviStudent.Ime == null || noviStudent.Prezime == null || noviStudent.DatumRođenja == null || noviStudent.MjestoPrebivališta == null || noviStudent.Odsjek == null || noviStudent.Odsjek.Equals("Izaberite smjer") || noviStudent.ProsjekNaBSC < 0 || noviStudent.ProsjekNaBSC > 10));
     }
     return(!(tempStudent.Ime == null || tempStudent.Prezime == null || tempStudent.DatumRođenja == null || tempStudent.MjestoPrebivališta == null || tempStudent.Odsjek == null || tempStudent.Odsjek.Equals("Izaberite smjer")));
 }
コード例 #4
0
        private MasterStudent transform(IStudent student)
        {
            MasterStudent _transformedStudent = new MasterStudent()
            {
                Type    = "Master",
                Name    = student.Name,
                Surname = student.Surname
            };

            return(_transformedStudent);
        }
コード例 #5
0
        public void GenerateStudents()
        {
            #region Sample Single Initialization
            IStudent Studenti1 = new MasterStudent
            {
                Type    = "Master",
                Name    = "St1Name",
                Surname = "St1Surname"
            };
            IStudent Studenti2 = new BachelorStudent
            {
                Type    = "Bachelor",
                Name    = "St2Name",
                Surname = "St2Surname"
            };

            Studentet.Add(Studenti1);
            Studentet.Add(Studenti2);
            #endregion

            #region Sample Group Initialization
            for (int i = 2; i < 100; i++)
            {
                if (i % 2 == 0)
                {
                    Studentet.Add(new BachelorStudent
                    {
                        Type    = "Master",
                        Name    = "St" + i.ToString() + "Name",
                        Surname = "St" + i.ToString() + "Surname"
                    });;;
                }
                else
                {
                    Studentet.Add(new MasterStudent
                    {
                        Type    = "Bachelor",
                        Name    = "St" + i.ToString() + "Name",
                        Surname = "St" + i.ToString() + "Surname"
                    });
                }
            }
            #endregion
        }
コード例 #6
0
        public async Task <IActionResult> Edit(int id, [Bind("StuId,FirstName,LastName,mClassName")] MasterStudent masterStudent, string SelSubjectList)
        {
            if (id != masterStudent.StuId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.SubjectStudentWises.RemoveRange(_context.SubjectStudentWises.Where(s => s.sswStudentId == masterStudent.StuId).ToList());
                    _context.Update(masterStudent);
                    if (!string.IsNullOrEmpty(SelSubjectList))
                    {
                        List <SubjectList>        list = JsonConvert.DeserializeObject <List <SubjectList> >(SelSubjectList);
                        List <SubjectStudentWise> lst  = list.Select(s => new SubjectStudentWise()
                        {
                            sswStudentId = masterStudent.StuId, sswSubjectId = s.id, sswStudentMarks = Convert.ToDecimal(s.marks)
                        }).ToList();
                        _context.SubjectStudentWises.AddRange(lst);
                    }
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MasterStudentExists(masterStudent.StuId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["mClassName"] = new SelectList(_context.MasterClasses.Where(s => s.IsActive == true), "mClassId", "mClassName", masterStudent.mClassName);
            ViewBag.SubjectList    = _context.MasterSubjects.Where(s => s.IsActive == true).ToList();
            ViewBag.SelSubjectList = SelSubjectList;
            return(View(masterStudent));
        }
コード例 #7
0
 public JsonResult InsertStudent(MasterStudent Student)
 {
     return(Json(BsLogic.InsertStudent(Student)));
 }
コード例 #8
0
 public string InsertStudent(MasterStudent Student)
 {
     DB.MasterStudent.Add(Student);
     return("Success");
 }