コード例 #1
0
        public ActionResult Edit(Teacher teacher, List <int> schoolgroupIds)
        {
            var dbTeacher = db.Teachers.Include(t => t.SchoolGroups).Single(t => t.Id == teacher.Id);

            if (TryUpdateModel(dbTeacher))
            {
                dbTeacher.SchoolGroups.Clear();
                //   teacher.SchoolGroups = new List<SchoolGroup>();
                if (schoolgroupIds != null)
                {
                    foreach (var group in schoolgroupIds)
                    {
                        // dit is een extra db query per foreach lus... is niet mooi natuurlijk, maar werkt wel
                        // als je tijd hebt mag je nadenken hoe dit mooier kan :P
                        SchoolGroup sg = db.SchoolGroups.Where(s => s.Id == group).FirstOrDefault();
                        dbTeacher.SchoolGroups.Add(sg);
                    }
                }


                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(teacher));
        }
コード例 #2
0
        public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                var        periodTypes = db.PeriodKinds;
                PeriodKind periodType  = new PeriodKind();
                foreach (var item in periodTypes)
                {
                    if (item.Name == PeriodType)
                    {
                        periodType = item;
                    }
                }

                SchoolGroup group = new SchoolGroup()
                {
                    Name         = helper.CreateName(),
                    IdPeriodKind = periodType.IdPeriodKind,
                    StartDate    = helper.RoundDate(DateTime.Now),
                    CloseDate    = helper.RoundDate(DateTime.Now.AddMonths(periodType.Months))
                };

                db.SchoolGroups.Add(group);
                db.SaveChanges();
                return(RedirectToPage("../search/groups"));
            }

            HasError = true;
            return(RedirectToPage("add_group", new { HasError }));
        }
コード例 #3
0
 public ActionResult Edit([Bind(Include = "Id,GroupName")] SchoolGroup schoolGroup)
 {
     if (ModelState.IsValid)
     {
         db.Entry(schoolGroup).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(schoolGroup));
 }
コード例 #4
0
        public void GivenNonExistingSchoolGroupName_WhenGetByName_ThenReturnNull()
        {
            SchoolGroup firstClass = new SchoolGroup("A");

            School school = new School();

            school.Add(firstClass);

            Assert.IsNull(school.GetByName("B"));
        }
コード例 #5
0
        public void GivenExistingSchoolGroupName_WhenGetByName_ThenReturnIt()
        {
            SchoolGroup firstClass = new SchoolGroup("A");

            School school = new School();

            school.Add(firstClass);

            Assert.AreEqual(firstClass, school.GetByName("A"));
        }
コード例 #6
0
        public void GivenExistingSchoolGroupName_WhenRemove_ThenRemoveAndTrue()
        {
            SchoolGroup sc     = new SchoolGroup("A");
            School      school = new School();

            school.Add(sc);
            bool result = school.Remove("A");

            CollectionAssert.DoesNotContain(new List <SchoolGroup>(school.GetAllSchoolGroups()), sc);
            Assert.IsTrue(result);
        }
コード例 #7
0
        public ActionResult Create([Bind(Include = "Id,GroupName")] SchoolGroup schoolGroup)
        {
            if (ModelState.IsValid)
            {
                db.SchoolGroups.Add(schoolGroup);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(schoolGroup));
        }
コード例 #8
0
 public void Add_Click(object sender, RoutedEventArgs e)
 {
     if (!IsWrongTextBoxValue())
     {
         var OwnerWindowInstance = this.Owner as GroupsWindow;
         var group = new SchoolGroup(NameTextBox.Text, int.Parse(StudentsQuantityTextBox.Text));
         OwnerWindowInstance.SchoolGroupDict.dictionaryList.Add(group);
         OwnerWindowInstance.GroupsList.Items.Add(group);
         ((Owner as GroupsWindow).Owner as EditorWindow).HomePage.GroupsIndicator.Fill = ColorPalette.GetPredefinedColor(PredefinedColors.Green);
         ElementsModification.ResetControlText <TextBox>(this);
     }
 }
コード例 #9
0
 private void ContextMenuCopyButton_Click(object sender, RoutedEventArgs e)
 {
     if (GroupsList.SelectedItems != null)
     {
         foreach (SchoolGroup item in GroupsList.SelectedItems)
         {
             var group = new SchoolGroup(item.Name, item.StudentQuantity);
             SchoolGroupDict.dictionaryList.Add(group);
             GroupsList.Items.Add(group);
         }
     }
 }
コード例 #10
0
        public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                Subject subject = new Subject();
                foreach (var item in db.Subjects)
                {
                    if (int.Parse(SubjectID) == item.IdSubject)
                    {
                        subject = item;
                    }
                }

                SchoolGroup schoolGroup = new SchoolGroup();
                foreach (var item in db.SchoolGroups)
                {
                    if (int.Parse(GroupID) == item.IdGroup)
                    {
                        schoolGroup = item;
                    }
                }

                if (schoolGroup.Name == null || subject.Name == null)
                {
                    return(RedirectToPage("add_group_subject"));
                }

                bool flag = true;
                foreach (var groupSubject in GroupSubjects)
                {
                    if (groupSubject.IdGroup == schoolGroup.IdGroup && groupSubject.IdSubject == subject.IdSubject)
                    {
                        flag = false;
                        break;
                    }
                }

                //If flag then is a new Groups SchoolGroup row
                if (flag)
                {
                    GroupSubject GroupSubject = new GroupSubject()
                    {
                        IdGroup   = schoolGroup.IdGroup,
                        IdSubject = subject.IdSubject
                    };

                    db.GroupSubjects.Add(GroupSubject);
                    db.SaveChanges();
                }
            }

            return(RedirectToPage("add_group_subject"));
        }
コード例 #11
0
        public void GivenTwoDifferentSchoolGroups_WhenAdd_ThenAllCreateInSchool()
        {
            SchoolGroup firstClass  = new SchoolGroup("A");
            SchoolGroup secondClass = new SchoolGroup("B");

            School school = new School();

            school.Add(firstClass);
            school.Add(secondClass);

            Assert.AreEqual(2, school.GetAllSchoolGroups().Count);
        }
コード例 #12
0
        public void GivenTwoEqualsSchoolGroups_WhenAdd_ThenOnlyOneCreateInSchool()
        {
            SchoolGroup firstClass  = new SchoolGroup("A");
            SchoolGroup secondClass = new SchoolGroup("A");

            School school = new School();

            school.Add(firstClass);
            school.Add(secondClass);

            Assert.AreEqual(1, school.GetAllSchoolGroups().Count);
        }
コード例 #13
0
        public void GivenSecondTeacherWithTheSameSubject_WhenAddTeacher_ThenFalse()
        {
            Teacher teacher = new Teacher(new SchoolSubject("Informatyka", 2, 2));

            teacher.Add(new SchoolSubject("Matematyka", 2, 2));
            Teacher     teacher2    = new Teacher(new SchoolSubject("Informatyka", 2, 2));
            SchoolGroup schoolGroup = new SchoolGroup("A");

            schoolGroup.AddTeacher(teacher);
            schoolGroup.AddTeacher(teacher2);

            CollectionAssert.DoesNotContain(
                new List <Teacher> (schoolGroup.GetAllTeachers()), teacher2);
        }
コード例 #14
0
        // GET: SchoolGroups/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SchoolGroup schoolGroup = db.SchoolGroups.Find(id);

            if (schoolGroup == null)
            {
                return(HttpNotFound());
            }
            return(View(schoolGroup));
        }
コード例 #15
0
        public void GivenStudentsWithDifferentId_WhenAdd_ThenAllPersist()
        {
            Student     student1    = new Student(1, "Ab");
            Student     student2    = new Student(2, "Ac");
            SchoolGroup schoolClass = new SchoolGroup("A");

            schoolClass.AddStudent(student1);
            schoolClass.AddStudent(student2);

            CollectionAssert.AreEqual(
                new List <Student> {
                student1, student2
            },
                new List <Student>(schoolClass.GetAllStudents()));
        }
コード例 #16
0
        public void GivenTeacherWithDifferentSubjects_WhenAddTeacher_ThenTrue()
        {
            Teacher     teacher     = new Teacher(new SchoolSubject("Informatyka", 2, 2));
            Teacher     teacher2    = new Teacher(new SchoolSubject("Matematyka", 2, 2));
            SchoolGroup schoolGroup = new SchoolGroup("A");

            schoolGroup.AddTeacher(teacher);
            schoolGroup.AddTeacher(teacher2);

            CollectionAssert.AreEqual(
                new List <Teacher> {
                teacher, teacher2
            },
                new List <Teacher>(schoolGroup.GetAllTeachers()));
        }
コード例 #17
0
        public void GivenStudentsWithTheSameId_WhenAdd_ThenOnlyFirstPersist()
        {
            Student     Student1    = new Student(1, "Ab");
            Student     Student2    = new Student(1, "Ac");
            SchoolGroup schoolClass = new SchoolGroup("A");

            schoolClass.AddStudent(Student1);
            schoolClass.AddStudent(Student2);

            CollectionAssert.AreEqual(
                new List <Student> {
                Student1
            },
                new List <Student>(schoolClass.GetAllStudents()));
        }
コード例 #18
0
        // GET: SchoolGroups/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SchoolGroup schoolGroup = db.SchoolGroups
                                      .Include(gs => gs.Students)
                                      .Include(gt => gt.Teachers).Single(t => t.Id == id);

            if (schoolGroup == null)
            {
                return(HttpNotFound());
            }
            return(View(schoolGroup));
        }
コード例 #19
0
        // GET: SchoolGroups/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SchoolGroup schoolGroup = db.SchoolGroups
                                      .Include(gs => gs.Students) // lazy load staat uit door virtual / config. include nu complete students en teacher data?
                                      .Include(gt => gt.Teachers).Single(t => t.Id == id);

            if (schoolGroup == null)
            {
                return(HttpNotFound());
            }
            return(View(schoolGroup));
        }
コード例 #20
0
        public int GetTotalGroups(int IdTeacher)
        {
            IEnumerable <Assignature> assignatures = db.Assignatures;
            List <SchoolGroup>        groups       = new List <SchoolGroup>();

            int total = 0;

            foreach (var assignature in assignatures)
            {
                SchoolGroup group = GetGroup(assignature.IdGroup);
                if (assignature.IdTeacher == IdTeacher && !groups.Contains(group))
                {
                    groups.Add(group);
                    total++;
                }
            }

            return(total);
        }
コード例 #21
0
        public ActionResult DeleteConfirmed(int id)
        {
            SchoolGroup schoolGroup = db.SchoolGroups
                                      .Include(gs => gs.Students)
                                      .Include(gt => gt.Teachers).Single(t => t.Id == id);

            if (schoolGroup.Teachers != null | schoolGroup.Students != null)
            {
                // je zou hier niet kunnen komen zonder de html te editen en daarom is er in principe geen error melding nodig. we doen gewoon niet een groep weghalen als er nog iets inzit.
            }
            else
            {
                db.SchoolGroups.Remove(schoolGroup);
                db.SaveChanges();
            }



            return(RedirectToAction("Index"));
        }
コード例 #22
0
        private void ImportExcel_Click(object sender, RoutedEventArgs e)
        {
            string[,] data = ExcelFileTools.UploadExcelData();
            if (data?.GetLength(1) >= ElementsModification.FindVisualChildren <GridViewColumnHeader>(this).Count() - 2)
            {
                for (int i = 0; i < data.GetLength(0); i++)
                {
                    int.TryParse(data[i, 1], out int studQuantity);

                    var group = new SchoolGroup(data[i, 0], studQuantity);
                    SchoolGroupDict.dictionaryList.Add(group);
                    GroupsList.Items.Add(group);
                }
                (Owner as EditorWindow).HomePage.GroupsIndicator.Fill = ColorPalette.GetPredefinedColor(PredefinedColors.Green);
            }
            else if (data?.GetLength(1) < ElementsModification.FindVisualChildren <GridViewColumnHeader>(this).Count() - 2)
            {
                MessageBox.Show("Wrong Columns Format");
            }
        }
コード例 #23
0
        /// <summary>
        /// get all school news
        /// </summary>
        /// <returns></returns>
        public List <SchoolGroup> getSchoolGroup()
        {
            List <SchoolGroup> list = new List <SchoolGroup>();
            string             comd = "select * from SchoolType";
            SQLHelper          sh   = new SQLHelper();

            using (SqlDataReader read = sh.getDataReader(comd))
            {
                if (read.HasRows)
                {
                    while (read.Read())
                    {
                        SchoolGroup group = new SchoolGroup();
                        group.SchoolID   = read["schoolID"].ToString();
                        group.SchoolName = read["schoolName"].ToString();
                        list.Add(group);
                    }
                }
            }
            return(list);
        }
コード例 #24
0
        /// <summary>
        /// 获取学校的名字
        /// </summary>
        /// <returns></returns>
        public List <SchoolGroup> getSchoolName()
        {
            List <SchoolGroup> list = new List <SchoolGroup>();
            SchoolGroup        stu  = null;
            string             comd = "select distinct schoolid from schooltype and schoolid in (select schoolid from schooltype)";
            SQLHelper          h    = new SQLHelper();

            using (SqlDataReader read = h.getDataReader(comd))
            {
                if (read.HasRows)
                {
                    while (read.Read())
                    {
                        stu            = new SchoolGroup();
                        stu.SchoolID   = read["schoolID"].ToString();
                        stu.SchoolName = read["schoolname"].ToString();

                        list.Add(stu);
                    }
                }
            }
            return(list);
        }
コード例 #25
0
 public void GivenWhiteSpaceName_WhenInitialized_ThenException()
 {
     SchoolGroup schoolClass = new SchoolGroup(" ");
 }
コード例 #26
0
 public void GivenNullName_WhenInitialized_ThenException()
 {
     SchoolGroup schoolClass = new SchoolGroup(null);
 }
コード例 #27
0
 public bool LessThanMaxGroupSubjects(SchoolGroup group)
 {
     return(helper.LessThanMaxGroupSubjects(group.IdGroup));
 }