/// <summary>
 /// Adds a new subject to the database.
 /// </summary>
 /// <param name="newSubject">Subject object containing the new subjects data.</param>
 /// <returns>True if success.</returns>
 public bool AddNewSubject(Subject newSubject)
 {
     Subject insertedSubject = Context.Subjects.Add(newSubject);
     Context.SaveChanges();
     if (insertedSubject.Id > 0)
     {
         return true;
     }
     return false;
 }
Example #2
0
        public void AddNewTeacherClassesAndSubjectsToDb()
        {
            bool success = false;

            Subject subject1 = new Subject() { Name = "Test subject" };
            Subject subject2 = new Subject() { Name = "Test subject2" };
            using (var sc = new SubjectContext())
            {
                sc.AddNewSubject(subject1);
                sc.AddNewSubject(subject2);
            }

            Class class1 = new Class() { Name = "Test class" };
            Class class2 = new Class() { Name = "Test class2" };
            using (var cc = new ClassContext())
            {
                cc.AddNewClass(class1);
                cc.AddNewClass(class2);
            }

            ICollection<Subject> subjects = new ObservableCollection<Subject>();
            ICollection<Class> classes = new ObservableCollection<Class>();

            subjects.Add(subject1);
            subjects.Add(subject2);

            classes.Add(class1);
            classes.Add(class2);

            Teacher newTeacher = new Teacher()
            {
                FirstName = "Fornavn",
                LastName = "Efternavn",
                SocialSecurityNumber = 010170,
                Address = "Hallovej 123",
                ZipCode = 1234,
                City = "Randers ikke",
                Subjects = subjects,
                Classes = classes
            };
            using (var tc = new TeacherContext())
            {
                success = tc.AddNewTeacher(newTeacher);
            }
            Assert.IsTrue(success);
        }
Example #3
0
        public static void Startup(TestContext testcontext)
        {
            Subject subject1 = new Subject() { Name = "Init subject" };
            Subject subject2 = new Subject() { Name = "Init subject2" };
            using (var sc = new SubjectContext())
            {
                sc.AddNewSubject(subject1);
                sc.AddNewSubject(subject2);
            }

            Class class1 = new Class() { Name = "Init class" };
            Class class2 = new Class() { Name = "Init class2" };
            using (var cc = new ClassContext())
            {
                cc.AddNewClass(class1);
                cc.AddNewClass(class2);
            }

            ICollection<Subject> subjects = new ObservableCollection<Subject>();
            ICollection<Class> classes = new ObservableCollection<Class>();

            subjects.Add(subject1);
            subjects.Add(subject2);

            classes.Add(class1);
            classes.Add(class2);

            Teacher newTeacher = new Teacher()
            {
                FirstName = "Ja",
                LastName = "Hallo",
                SocialSecurityNumber = 010203,
                Address = "Hallovej 123",
                ZipCode = 5678,
                City = "Viborg",
                Subjects = subjects,
                Classes = classes
            };
            using (var tc = new TeacherContext())
            {
                tc.AddNewTeacher(newTeacher);
            }
        }
Example #4
0
        public JiraAggregator(IRobot robot)
            : base("Jira Aggregator", robot)
        {
            _settings = new List<IPluginSetting>
            {
                new PluginSetting(Robot, this, "AtlassianJiraNotifyRoomName"),
                new PluginSetting(Robot, this, "AtlassianJiraHipchatAuthToken")
            };

            _jiraMessageBuilder = new JiraMessageBuilder(JiraBaseUrl);

            _subject = new Subject<JiraModel>();

            var maxWaitDuration = TimeSpan.FromMinutes(3.0);

            _subject
                .GroupBy(model => model.issue.key)
                .SelectMany(grp => grp.Publish(hot => hot.Buffer(() => hot.Throttle(maxWaitDuration, Scheduler))))
                .Subscribe(SendNotification);

            Robot.EventEmitter.On<JiraModel>("JiraEvent", OnJiraEvent);
        }
        /// <summary>
        /// Adds subjects to the database and refreshes the view.
        /// </summary>
        private void AutoAddSubjects()
        {
            Subject dansk = new Subject() { Name = "Dansk" };
            Subject engelsk = new Subject() { Name = "Engelsk" };
            Subject matematik = new Subject() { Name = "Matematik" };
            Subject biologi = new Subject() { Name = "Biologi" };

            using (SubjectContext sc = new SubjectContext())
            {
                sc.AddNewSubject(dansk);
                sc.AddNewSubject(engelsk);
                sc.AddNewSubject(matematik);
                sc.AddNewSubject(biologi);
            }
            canAutoAdd = false;
            addSubjects();
        }
Example #6
0
 public Course()
 {
     Enrollments = new List<Enrollment>();
     CourseTutor = new Tutor();
     CourseSubject = new Subject();
 }
        public void Seed()
        {
            if (_ctx.Courses.Count() > 0)
            {
                return;
            }

            try
            {
                foreach (var subjectName in subjects)
                {
                    var subject = new Subject
                    {
                        Name = subjectName
                    };
                    _ctx.Subjects.Add(subject);
                    _ctx.SaveChanges();
                }

                for (int i = 0; i < tutorNames.Length; i++)
                {
                    var nameGenderMail = SplitValue(tutorNames[i]);
                    var tutor = new Tutor
                    {
                        Email = String.Format("{0}.{1}@{2}", nameGenderMail[0], nameGenderMail[1], nameGenderMail[3]),
                        UserName = String.Format("{0}{1}", nameGenderMail[0], nameGenderMail[1]),
                        Password = RandomString(8),
                        FirstName = nameGenderMail[0],
                        LastName = nameGenderMail[1],
                        Gender = ((Gender)Enum.Parse(typeof(Gender), nameGenderMail[2]))
                    };

                    _ctx.Tutors.Add(tutor);

                    var courseSubject = _ctx.Subjects.Where(s => s.Id == i + 1).Single();

                    foreach (var CourseDataItem in CoursesSeedData.Where(c => c.SubjectID == courseSubject.Id))
                    {
                        var course = new Course
                        {
                            Name = CourseDataItem.CourseName,
                            CourseSubject = courseSubject,
                            CourseTutor = tutor,
                            Duration = new Random().Next(3, 6),
                            Description = String.Format("The course will talk in depth about: {0}", CourseDataItem.CourseName)
                        };
                        _ctx.Courses.Add(course);
                    }
                }

                _ctx.SaveChanges();

                for (int i = 0; i < studentNames.Length; i++)
                {
                    var nameGenderMail = SplitValue(studentNames[i]);
                    var student = new Student()
                    {
                        Email = String.Format("{0}.{1}@{2}", nameGenderMail[0], nameGenderMail[1], nameGenderMail[3]),
                        UserName = String.Format("{0}{1}", nameGenderMail[0], nameGenderMail[1]),
                        Password = RandomString(8),
                        FirstName = nameGenderMail[0],
                        LastName = nameGenderMail[1],
                        Gender = ((Gender)Enum.Parse(typeof(Gender), nameGenderMail[2])),
                        DateOfBirth = DateTime.UtcNow.AddDays(-new Random().Next(7000, 8000)),
                        RegistrationDate = DateTime.UtcNow.AddDays(-new Random().Next(365, 730))
                    };

                    _ctx.Students.Add(student);

                    int maxCoursesId = _ctx.Courses.Max(c => c.Id);

                    //To enroll in 4 courses randomly
                    for (int z = 0; z < 4; z++)
                    {

                        int randomCourseId = new Random().Next(1, maxCoursesId);

                        var enrollment = new Enrollment
                        {
                            Student = student,
                            Course = _ctx.Courses.Where(c => c.Id == randomCourseId).Single(),
                            EnrollmentDate = DateTime.UtcNow.AddDays(-new Random().Next(10, 30))
                        };
                        _ctx.Enrollments.Add(enrollment);
                    }
                }

                _ctx.SaveChanges();
            }
            catch (Exception ex)
            {
                string message = ex.ToString();
                throw ex;
            }
        }