Ejemplo n.º 1
0
 public StudentVDomu(Student student, Studentski_dom dom, int dolzina_bivanja, string tip)
 {
     this.Student         = student;
     this.Dom             = dom;
     this.Dolzina_bivanja = dolzina_bivanja;
     this.Tip             = tip;
 }
        /*public Storitve()
         * {
         *  DodelitevPodatkov();
         * }*/

        public void DodelitevPodatkov()
        {
            Student student1 = new Student(1, 051207215, "Jan", "Kačičnik", 1998);

            student.Add(student1);
            Student student2 = new Student(2, 051051051, "Sandi", "Voršič", 1999);

            student.Add(student2);
            Student student3 = new Student(3, 123123123, "Simon", "Turk", 1994);

            student.Add(student3);
            Student student4 = new Student(4, 413413413, "David", "Novak", 1996);

            student.Add(student4);
            Student student5 = new Student(5, 653635635, "Špela", "Horvat", 1995);

            student.Add(student5);
            Student student6 = new Student(6, 67371477, "Simona", "Dogša", 1998);

            student.Add(student6);
            Student student7 = new Student(7, 031809213, "Krunoslav", "Galič", 1997);

            student.Add(student7);

            Studentski_dom dom1 = new Studentski_dom(1, "Studentski dom 1", 1960);

            domovi.Add(dom1);
            Studentski_dom dom2 = new Studentski_dom(2, "Studentski dom 2", 1940);

            domovi.Add(dom2);
            Studentski_dom dom3 = new Studentski_dom(3, "Studentski dom 3", 1999);

            domovi.Add(dom3);
            Studentski_dom dom4 = new Studentski_dom(4, "Studentski dom 4", 2001);

            domovi.Add(dom4);

            StudentVDomu svd1 = new StudentVDomu(student1, dom1, 2, "enoposteljna");

            studentje_v_domu.Add(svd1);
            StudentVDomu svd2 = new StudentVDomu(student5, dom2, 1, "dvoposteljna");

            studentje_v_domu.Add(svd2);
            StudentVDomu svd3 = new StudentVDomu(student2, dom2, 1, "dvoposteljna");

            studentje_v_domu.Add(svd3);
            StudentVDomu svd4 = new StudentVDomu(student6, dom3, 2, "enoposteljna");

            studentje_v_domu.Add(svd4);
            StudentVDomu svd5 = new StudentVDomu(student4, dom4, 3, "enoposteljna");

            studentje_v_domu.Add(svd5);
            StudentVDomu svd6 = new StudentVDomu(student3, dom2, 4, "enoposteljna");

            studentje_v_domu.Add(svd6);
            StudentVDomu svd7 = new StudentVDomu(student7, dom1, 5, "dvoposteljna");

            studentje_v_domu.Add(svd7);
        }
        public bool UrediDom(int Id, string ime, int stevilkadoma)
        {
            bool DomUrejen = false;

            using (StudentskiDomoviContext kontekst = new StudentskiDomoviContext())
            {
                Studentski_dom u = kontekst.Studentski_dom.First(uporabnik => uporabnik.Id == Id);
                u.Ime           = ime;
                u.Stevilka_Doma = stevilkadoma;
                kontekst.SaveChanges();
                DomUrejen = true;
            }
            return(DomUrejen);
        }
        public bool DodajStudentaVDomu(Student student, Studentski_dom studentski_dom, int dolzina_bivanja, string tip)
        {
            bool StudentVDomuDodan = false;

            using (StudentskiDomoviContext kontekst = new StudentskiDomoviContext())
            {
                int steviloDomov = kontekst.Studentski_dom.Count();

                StudentVDomu novStudentVDomu = new StudentVDomu(student, studentski_dom, dolzina_bivanja, tip);

                kontekst.Student_v_domu.Add(novStudentVDomu);
                kontekst.SaveChanges();


                if (steviloDomov < kontekst.Student_v_domu.Count())
                {
                    StudentVDomuDodan = true;
                }

                return(StudentVDomuDodan);
            }
        }
        public bool DodajStudentskiDom(int stevilka_doma, string ime_doma, int leto_nastanka)
        {
            bool DomDodan = false;

            using (StudentskiDomoviContext kontekst = new StudentskiDomoviContext())
            {
                int steviloDomov = kontekst.Studentski_dom.Count();

                Studentski_dom novStudentskiDom = new Studentski_dom(stevilka_doma, ime_doma, leto_nastanka);

                kontekst.Studentski_dom.Add(novStudentskiDom);
                kontekst.SaveChanges();


                if (steviloDomov < kontekst.Studentski_dom.Count())
                {
                    DomDodan = true;
                }

                return(DomDodan);
            }
        }
        public Studentski_dom VrniDom()
        {
            /*List<Studentski_dom> zacasniDomovi = new List<Studentski_dom>();
             *
             * List<KeyValuePair<Studentski_dom, int>> _domovi = new List<KeyValuePair<Studentski_dom, int>>();
             *
             * foreach (Studentski_dom studentski_Dom in domovi)
             * {
             *  Studentski_dom dom = studentski_Dom;
             *  List<Student> studenti = new List<Student>();
             *
             *  foreach (StudentVDomu item1 in studentje_v_domu)
             *  {
             *      if (item1.Dom.Stevilka_Doma == studentski_Dom.Stevilka_Doma)
             *      {
             *          studenti.Add(item1.Student);
             *      }
             *  }
             *
             *  _domovi.Add(new KeyValuePair<Studentski_dom, int>(dom, student.Count));
             * }
             *
             * int max = _domovi.Max(x => x.Value);
             *
             * foreach (KeyValuePair<Studentski_dom, int> item in _domovi)
             * {
             *  if (item.Value == max)
             *  {
             *      zacasniDomovi.Add(item.Key);
             *  }
             * }
             *
             * return zacasniDomovi;*/

            int            Zacasno_1          = 0;
            int            Zacasno_2          = 0;
            Studentski_dom DomZnajvecStudenti = new Studentski_dom();

            for (int i = 1; i < studentje_v_domu.Count; i++)
            {
                if (i == 1)
                {
                    DomZnajvecStudenti = studentje_v_domu[i].Dom;
                }

                for (int j = 0; j < studentje_v_domu.Count; j++)
                {
                    if (studentje_v_domu[i - 1].Dom == studentje_v_domu[j].Dom)
                    {
                        Zacasno_1++;
                    }
                    if (studentje_v_domu[i].Dom == studentje_v_domu[j].Dom)
                    {
                        Zacasno_2++;
                    }
                }
                if (Zacasno_2 > Zacasno_1)
                {
                    DomZnajvecStudenti = studentje_v_domu[i].Dom;
                }
                Zacasno_1 = 0;
                Zacasno_2 = 0;
            }
            return(DomZnajvecStudenti);
        }
            protected override void Seed(StudentskiDomoviContext kontekst)
            {
                Student student1 = new Student(1, 051207215, "Jan", "Kačičnik", 1998);

                kontekst.Student.Add(student1);
                Student student2 = new Student(2, 051051051, "Sandi", "Voršič", 1999);

                kontekst.Student.Add(student2);
                Student student3 = new Student(3, 123123123, "Simon", "Turk", 1994);

                kontekst.Student.Add(student3);
                Student student4 = new Student(4, 413413413, "David", "Novak", 1996);

                kontekst.Student.Add(student4);
                Student student5 = new Student(5, 653635635, "Špela", "Horvat", 1995);

                kontekst.Student.Add(student5);
                Student student6 = new Student(6, 737147627, "Simona", "Dogša", 1998);

                kontekst.Student.Add(student6);
                Student student7 = new Student(7, 031809213, "Krunoslav", "Galič", 1997);

                kontekst.Student.Add(student7);

                Studentski_dom dom1 = new Studentski_dom(1, "Studentski dom 1", 1960);

                kontekst.Studentski_dom.Add(dom1);
                Studentski_dom dom2 = new Studentski_dom(2, "Studentski dom 2", 1940);

                kontekst.Studentski_dom.Add(dom2);
                Studentski_dom dom3 = new Studentski_dom(3, "Studentski dom 3", 1999);

                kontekst.Studentski_dom.Add(dom3);
                Studentski_dom dom4 = new Studentski_dom(4, "Studentski dom 4", 2001);

                kontekst.Studentski_dom.Add(dom4);

                StudentVDomu svd1 = new StudentVDomu(student1, dom1, 2, "enoposteljna");

                kontekst.Student_v_domu.Add(svd1);
                StudentVDomu svd2 = new StudentVDomu(student5, dom2, 1, "dvoposteljna");

                kontekst.Student_v_domu.Add(svd2);
                StudentVDomu svd3 = new StudentVDomu(student2, dom3, 1, "dvoposteljna");

                kontekst.Student_v_domu.Add(svd3);
                StudentVDomu svd4 = new StudentVDomu(student6, dom3, 2, "enoposteljna");

                kontekst.Student_v_domu.Add(svd4);
                StudentVDomu svd5 = new StudentVDomu(student4, dom4, 3, "enoposteljna");

                kontekst.Student_v_domu.Add(svd5);
                StudentVDomu svd6 = new StudentVDomu(student3, dom2, 4, "enoposteljna");

                kontekst.Student_v_domu.Add(svd6);
                StudentVDomu svd7 = new StudentVDomu(student7, dom1, 5, "dvoposteljna");

                kontekst.Student_v_domu.Add(svd7);



                base.Seed(kontekst);
            }