private static void ParseInput(string path)
        {
            using (var reader = new StreamReader(path))
            {
                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine();

                    if (line == null)
                    {
                        continue;
                    }

                    var words = line
                        .Split(new char[] { ' ', '|' }, StringSplitOptions.RemoveEmptyEntries)
                        .ToArray();

                    var student = new Student()
                    {
                        FirstName = words[0],
                        LastName = words[1]
                    };

                    var course = new Course()
                    {
                        Name = words[2]
                    };

                    AddOrCreate(course, student);
                }
            }
        }
Пример #2
0
        public void AddingCourseToStudent_ShouldPass()
        {
            var student = new Student("Pesho");
            var course = new Course("Math");
            course.Subscribe(student);

            Assert.AreEqual(course.Students.Count, 1);
        }
Пример #3
0
        public void CreateCourse()
        {
            var courseFacade = new CourseFacade();
            var course = new Course() { Grade = "2", Subject = "English" };
            courseFacade.CreateCourse(course);

            Assert.IsTrue(course.Id > 0);
        }
        public IView Create(string name)
        {
            this.EnsureAuthorization(Role.Lecturer);

            var course = new Course(name);
            this.Data.Courses.Add(course);
            return this.View(course);
        }
        private static void AddOrCreate(Course course, Student student)
        {
            if (!StudentsCourses.ContainsKey(course))
            {
                StudentsCourses[course] = new OrderedBag<Student>();
            }

            StudentsCourses[course].Add(student);
        }
Пример #6
0
        public void UnsibscribingStudentFromCourse_ShouldPass(string name)
        {
            var course = new Course("Math");
            var student = new Student(name);
            course.Subscribe(student);
            course.Unsubscribe(student);

            Assert.AreEqual(course.Students.Count, 0);
        }
Пример #7
0
        public void StudentShouldSubscribeToCourseOnlyOnce()
        {
            var student = new Student("Pesho");
            var course = new Course("Math");
            course.Subscribe(student);
            course.Subscribe(student);
            course.Subscribe(student);

            Assert.AreEqual(course.Students.Count, 1);
        }
        public IView Create(string name)
        {
            this.ValidateLoggedUser();
            this.ValidatePremissions();

            var course = new Course(name);
            this.Data.CoursesRepository.Add(course);

            return this.View(course);
        }
Пример #9
0
        public void AddingMultipleStudentsToCourse()
        {
            var course = new Course("Biology");

            for (int i = 0; i < 35; i++)
            {
                var student = new Student(i.ToString());
                course.Subscribe(student);
            }

            Assert.AreEqual(course.Students.Count, Constants.MAX_STUDENTS_IN_COURSE);
        }
Пример #10
0
 public void SetInfo(Course course)
 {
     var context = new CourseContext();
     var template = context.CourseTemplates.FirstOrDefault(t => t.Id == course.CourseTemplateId);
     int duration = 0;
     if (template != null)
     {
     duration = template.NumberOfHours;
     }
       Id = course.Id;
       DisplayName = String.Format("{0} - {1:g} bis {2:t} - {3} SFr.", course.Name, course.StartDateTime, course.StartDateTime.AddHours(duration), course.Price);
 }
Пример #11
0
        public CourseViewModel(Course course)
        {
            var local = timeZoneProvider["Europe/Zurich"];

            this.Id = course.Id;
            this.Name = course.Name;
            this.Remark = course.Remark;
            this.CourseTemplateId = course.CourseTemplateId;
            this.LocationId = course.LocationId;
            this.StartDateTime = local.AtStrictly(LocalDateTime.FromDateTime(course.StartDateTime)).ToDateTimeUnspecified();
            this.MaxParticipants = course.MaxParticipants;
            this.Price = course.Price;
        }
Пример #12
0
        public IView Create(string name)
        {
            if (!this.HasCurrentUser)
            {
                throw new ArgumentException("There is no currently logged in user.");
            }

            if (!this.User.IsInRole(Role.Lecturer))
            {
                throw new DivideByZeroException("The current user is not authorized to perform this operation.");
            }

            var course = new Course(name);
            this.Data.Courses.Add(course);
            return this.View(course);
        }
Пример #13
0
        public IView Create(string name)
        {
            if (!this.HasCurrentUser)
            {
                throw new ArgumentException(GlobalMessages.NoUserLogged);
            }

            // BUG2: Boolean condition inverted.
            if (!this.User.IsInRole(Role.Lecturer))
            {
                throw new AuthorizationFailedException(GlobalMessages.AuthorizationFailed);
            }

            var course = new Course(name);
            Data.Courses.Add(course);
            return this.View(course);
        }
        public IView Create(string name)
        {
            this.EnsureAuthorization(Role.Lecturer);
            //if (!this.HasCurrentUser)
            //{
            //    throw new ArgumentException(Constants.NoCurrentlyLoggedUserMsg);
            //}

            //if (!this.CurrentUser.IsInRole(Role.Lecturer))
            //{
            //    throw new AuthorizationFailedException(Constants.NotAuthorizedUserMsg);
            //}
            var course = new Course(name);

            this.Data.Courses.Add(course);

            return this.View(course);
        }
Пример #15
0
 public Enroll(Course course)
     : base(course)
 {
     this.currentCourse = course;
 }
Пример #16
0
 public Details(Course course)
     : base(course)
 {
 }
 public Details(Course course)
     : base(course)
 {
     this.model = course;
 }
Пример #18
0
 public Enroll(Course course)
     : base(course)
 {
 }
Пример #19
0
        public void UnsubscribingNotSubscribedStudent_ShouldDoNothing()
        {
            var course = new Course("Math");
            var student = new Student("Pesho");
            var pesho = new Student("Pesho");
            course.Subscribe(student);
            course.Unsubscribe(pesho);

            Assert.AreEqual(course.Students.Count, 1);
        }
Пример #20
0
        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;
            }
        }
 public void TestInit()
 {
     datacontext = new DataContext();
     vm = new CourseCRUDViewModel(datacontext);//todo use that epicly fancy Moq stuff to do this...
     testCourse = new Course()
     {
         Name = "TestCourse",
         Duration = 5
     };
 }
Пример #22
0
 public Enrollment()
 {
     Student = new Student();
     Course = new Course();
 }
Пример #23
0
 public ActionResult Course_Update([DataSourceRequest] DataSourceRequest dsRequest, Course course)
 {
     if (course != null && ModelState.IsValid)
     {
         var toUpdate = this.context.Courses.FirstOrDefault(p => p.Id == course.Id);
         this.TryUpdateModel(toUpdate);
         this.context.SaveChanges();
     }
       return Json(new[] { course }.ToDataSourceResult(dsRequest, ModelState));
 }
Пример #24
0
        public ActionResult Course_Create([DataSourceRequest] DataSourceRequest dsRequest, Course course)
        {
            if (course != null && ModelState.IsValid)
            {
                //course.StartDateTime = course.StartDateTime.AddHours(-2);
                this.context.Courses.Add(course);
                this.context.SaveChanges();
            }

            return Json(new[] { course }.ToDataSourceResult(dsRequest, ModelState));
        }
Пример #25
0
 public AddLectures(Course course)
     : base(course)
 {
 }
Пример #26
0
 public Create(Course course)
     : base(course)
 {
 }
Пример #27
0
 public Create(Course course)
     : base(course)
 {
     this.currentCourse = course;
 }
 public AddLecture(Course course)
     : base(course)
 {
     this.currentCourse = course;
 }
Пример #29
0
        public ActionResult DeleteCourse([DataSourceRequest] DataSourceRequest dsRequest, Course course)
        {
            this.context.Courses.Remove(this.context.Courses.SingleOrDefault(c=>c.Id == course.Id));
            this.context.SaveChanges();

            return Json(new[] { course }.ToDataSourceResult(dsRequest, ModelState));
        }