public void Sholud_AddNewToCourseList()
        {
            //arrang
            var course = _courseBuilder.Build();

            //act
            _courseRepository.Create(course);

            //assert
            _courseRepository.Courses.Should().Contain(course);
        }
        public void created_course_is_assigned_to_correct_instructor()
        {
            //using (var Uow = new MOOCollab2UOW())
            using (var Uow = new TestDb())
            {
                //Arrange
                var courseRepo = new CourseRepository(Uow);
                var instructorRepo = new InstructorRepository(Uow);
                var testInstructor = instructorRepo.Find(1);

                courseRepo.Create(new Course
                {
                    OwnerId = 1,//course to instructor with Id of one
                    Title = "Test",
                    Resume = "Argh",//test text
                    Status = true
                });
                courseRepo.SaveChanges();
            }

            //using (var Uow = new MOOCollab2UOW())
            using (var Uow = new TestDb())
            {
                //Arrange
                var instructorRepo = new InstructorRepository(Uow);

                //Act
                var instructor = instructorRepo.FindAll()
                                .Include(i => i.Courses)
                                .FirstOrDefault(i => i.Id == 1);
                //assert  //Check if instructor has the new course
                Assert.IsNotNull(instructor.Courses.FirstOrDefault(c => c.Resume == "Argh"));
            }
        }
        public void CreateTest()
        {
            DbContextHelper.Init(typeof(CourseDbContext), GlobalSettings.DATABASE.ConnectionString, 8);

            CourseRepository repo = new CourseRepository();

            Assert.AreEqual(true, repo.Create("Computer Network", "Foundation", 2, 3));
        }
        public async Task <ActionResult> Create([Bind(Include = "Id, Name, Cost, CourseDateTime, Duration")] Course course)
        {
            if (ModelState.IsValid)
            {
                await _courseRepo.Create(course);

                return(RedirectToAction("Index"));
            }
            return(View(course));
        }
        public void Create_Should_Add_A_New_Course()
        {
            // Arrange
            var newCourse = new Course()
            {
                Id = 5, Title = "Fifth title", Code = "Fifth Code", Duration = 3
            };

            // Act
            var created = _repository.Create(newCourse).Result;
            var courses = _repository.GetAllCourses().Result;
            var result  = courses.Count();

            // Assert
            int expectedCount = 5;

            Assert.IsInstanceOfType(created, typeof(Course));
            Assert.AreEqual(expectedCount, result);
            Assert.IsInstanceOfType(courses[4], typeof(Course));
        }
        public IActionResult CreateCourse(CreateCourseModel createCourseModel)
        {
            Course course = new Course
            {
                Date        = DateTime.Now,
                Subject     = createCourseModel.Subject,
                TeacherName = createCourseModel.TeacherName,
                Inform      = createCourseModel.Inform,
            };

            _courseRepository.Create(course);
            return(CreatedAtRoute("GetId", new { Id = course.Id }, course));
        }
Beispiel #7
0
        public ActionResult Create(CourseViewModel viewModel)
        {
            var subjectRepository = new SubjectRepository(_context);
            var userRepository    = new UserRepository(_context);
            var courseRepository  = new CourseRepository(_context);

            if (ModelState.IsValid)
            {
                try
                {
                    var subject = subjectRepository.GetById(viewModel.SubjectId);
                    var teacher = (Teacher)userRepository.GetById(viewModel.TeacherInChargeId);
                    courseRepository.Create(CourseViewModel.ToEntity(viewModel, subject, teacher));
                    _context.Save(_loggedUser);

                    TempData["MessageType"]  = "success";
                    TempData["MessageTitle"] = Resource.ContentManagementToastrTitle;
                    TempData["Message"]      = Resource.CourseCreatedToastrMessage;
                    return(Redirect(TempData["BackURL"].ToString()));
                }
                catch (Exception ex)
                {
                    TempData["MessageType"]  = "error";
                    TempData["MessageTitle"] = Resource.ContentManagementToastrTitle;
                    TempData["Message"]      = ex.Message;
                }
            }

            var subjects = subjectRepository.ListActiveSubjects();

            ViewBag.Subjects = new SelectList(subjects, "Id", "Name");

            var activeTeachers = userRepository.ListActiveTeachers();

            ViewBag.Teachers = new SelectList(activeTeachers, "Id", "Name");
            return(View(viewModel));
        }
        public IActionResult AddCourse(CourseModel courseModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(courseModel));
            }
            Subject subject = subjectRepository.FindByName(courseModel.SubjectName);

            if (subject == null)
            {
                subject      = new Subject();
                subject.Name = courseModel.SubjectName;
                subject      = subjectRepository.Create(subject);
            }
            Course course = new Course();

            course.Name        = courseModel.Name;
            course.Description = courseModel.Description;
            course.AuthorId    = BitConverter.ToInt32(HttpContext.Session.Get("userId"));
            Author author = authorRepository.Read(course.AuthorId);

            course.SubjectId = subject.Id;
            course.Author    = author;
            if (subject.Courses == null)
            {
                subject.Courses = new List <Course>();
            }
            subject.Courses.Add(course);
            if (author.Courses == null)
            {
                author.Courses = new List <Course>();
            }
            author.Courses.Add(course);
            courseRepository.Create(course);
            return(RedirectToAction("Courses", "Course"));
        }
Beispiel #9
0
 public void CreateCourse(Courses course)
 {
     repo.Create(course);
 }
Beispiel #10
0
        public void SaveCourse(Courses course)
        {
            CourseRepository repository = new CourseRepository();

            repository.Create(course);
        }
Beispiel #11
0
        static void Main(string[] args)
        {
            var nhService = new NHibernateService();

            var userRepository      = new UserRepository(nhService);
            var courseRepository    = new CourseRepository(nhService);
            var componentRepository = new ComponentRepository(nhService);
            var scoreRepository     = new ScoreRepository(nhService);

            #region Seeding

            var lecturer = new Lecturer()
            {
                Email        = "*****@*****.**",
                PasswordHash = EncryptionService.EncryptSHA1("pare"),
                Name         = "Tibor",
                Surname      = "Žukina",
                NationalIdentificationNumber = "12345"
            };
            var administrator = new Administrator()
            {
                Email        = "*****@*****.**",
                PasswordHash = EncryptionService.EncryptSHA1("123abc"),
                Name         = "Željko",
                Surname      = "Baranek",
                NationalIdentificationNumber = "123456"
            };
            var student = new Student()
            {
                Name    = "Zlatko",
                Surname = "Hrastić",
                Email   = "*****@*****.**",
                NationalIdentificationNumber = "343999999",
                StudentIdentificationNumber  = "0036476522",
                CoursesEnrolledIn            = new List <Course>(),
                PasswordHash = EncryptionService.EncryptSHA1("jabuka")
            };

            Component medjuispit = new Component()
            {
                MaximumPoints       = 30,
                MinimumPointsToPass = 0,
                Name = "Međuispit"
            };
            Component zavrsni = new Component()
            {
                MaximumPoints       = 40,
                MinimumPointsToPass = 14,
                Name = "Završni ispit"
            };

            var componentList = new List <Component>();
            componentList.Add(medjuispit);
            componentList.Add(zavrsni);

            Course MockCourse = new Course()
            {
                Id   = 1,
                Name = "Objektno oblikovanje",
                NaturalIdentifier = "ObjOblFER2016OO",
                EctsCredits       = 5,
                Components        = componentList,
                LecturersInCharge = new List <Lecturer>(),
                StudentsEnrolled  = new List <Student>()
            };

            Course MockCourse2 = new Course()
            {
                Id   = 2,
                Name = "Napredni algoritmi i strukture podataka",
                NaturalIdentifier = "NASP-FER-2016OO",
                EctsCredits       = 5,
                Components        = null,
                LecturersInCharge = new List <Lecturer>(),
                StudentsEnrolled  = new List <Student>()
            };

            var score = new Score()
            {
                Component = medjuispit,
                Student   = student,
                Value     = 20
            };

            var service = new UserServices(userRepository);
            service.CreateUser(student);
            service.CreateUser(lecturer);
            service.CreateUser(administrator);

            MockCourse.StudentsEnrolled.Add(student);
            MockCourse.LecturersInCharge.Add(lecturer);

            courseRepository.Create(MockCourse);
            courseRepository.Create(MockCourse2);

            scoreRepository.CreateOrUpdate(score);

            #endregion

            System.Console.WriteLine("Seed successfully completed.");
            System.Console.Read();
        }
 public int createCourse(Course course)
 {
     return(courseRepository.Create(course));
 }
Beispiel #13
0
 public void AddCourse(Course course)
 {
     Courserepo.Create(course);
 }
        private static string ManageCourses(OperationType operationType, params object[] args)
        {
            string message = "";

            switch (operationType)
            {
            case OperationType.Create:
                List <Hole>   holesToBeCreated   = new List <Hole>();
                List <Player> playersToBeCreated = new List <Player>();
                if (args.Length > 3)
                {
                    int[] holesToBeCreatedId   = args[2] as int[];
                    int[] playersToBeCreatedId = args[3] as int[];
                    holesToBeCreated   = finder.FindHoles(holesToBeCreatedId);
                    playersToBeCreated = finder.FindPlayers(playersToBeCreatedId);
                }

                Course toBeCreated = DBFactory.GetCourse(DEFALT_INT_ID, args[0], args[1], holesToBeCreated, playersToBeCreated);
                courseRepository.Create(toBeCreated);
                break;

            case OperationType.Read:
                int readKey = int.Parse(args[0].ToString());
                message = courseRepository.Read(readKey).ToString() + Environment.NewLine;
                break;

            case OperationType.Delete:
                int deleteKey = int.Parse(args[0].ToString());
                courseRepository.Delete(deleteKey);
                break;

            case OperationType.Update:
                List <Hole>   holesToBeUpdated   = new List <Hole>();
                List <Player> playersToBeUpdated = new List <Player>();
                if (args.Length > 4)
                {
                    int[] holesToBeUpdatedId  = args[3] as int[];
                    int[] playersToBeUpdateId = args[4] as int[];
                    holesToBeUpdated   = finder.FindHoles(holesToBeUpdatedId);
                    playersToBeUpdated = finder.FindPlayers(playersToBeUpdateId);
                }

                Course toBeUpdated = DBFactory.GetCourse(args[0], args[1], args[2], holesToBeUpdated, playersToBeUpdated);
                courseRepository.Create(toBeUpdated);
                break;

            case OperationType.Find:
                List <Course> coursesFound  = courseRepository.Find(args[0].ToString());
                StringBuilder stringBuilder = new StringBuilder();
                foreach (var item in coursesFound)
                {
                    stringBuilder.AppendLine(item.ToString());
                }
                message = stringBuilder.ToString();
                break;

            case OperationType.ReadAll:
                List <Course> courses = courseRepository.ReadAll();
                stringBuilder = new StringBuilder();
                foreach (var item in courses)
                {
                    stringBuilder.AppendLine(item.ToString());
                }
                message = stringBuilder.ToString();
                break;
            }
            return(message + "Next:");
        }
Beispiel #15
0
 public void CreateCourse(Course course)
 {
     repository.Create(course);
 }
Beispiel #16
0
 public void CreateCouses(Course course)
 {
     courseRepository.Create(course);
 }