Пример #1
0
        public void LessonIsCorrectlyAddedToCourse()
        {
            Teacher  teacher = new Teacher("temp", "temp", "temp", User.Privilege.teacher);
            DateTime time    = DateTime.Now;
            Room     room    = new Room("temp");
            Course   course  = new Course("temp", teacher, DateTime.Now, DateTime.Now, 0);
            Lesson   lesson  = new Lesson(course, time, time, room);

            course.AddLessonToCourse(lesson);
            course.AddLessonToCourse(lesson);
            Assert.AreEqual(course.lessons.Count, 2);
        }
Пример #2
0
        public ActionResult Create(IFormCollection collection)
        {
            try
            {
                var name                 = new StringValues();
                var description          = new StringValues();
                var courseIdentification = new StringValues();
                var token                = new StringValues();
                if (collection.TryGetValue("Name", out name) &&
                    collection.TryGetValue("Description", out description) &&
                    collection.TryGetValue("token", out token) &&
                    collection.TryGetValue("CourseIdentification", out courseIdentification))
                {
                    var username = AuthLogic.CheckToken(token.ToString());
                    if (username == "")
                    {
                        throw new Exception("NotAuthorized");
                    }
                    ViewData["token"] = token;

                    // Add lesson to Course
                    var lesson = new Lesson();
                    lesson.ModelLesson             = new NekoUchi.Model.Lesson();
                    lesson.ModelLesson.Name        = name.ToString();
                    lesson.ModelLesson.Description = description.ToString();
                    lesson.ModelLesson.Words       = new List <NekoUchi.Model.Word>();

                    if (Course.AddLessonToCourse(courseIdentification.ToString(), lesson.ModelLesson))
                    {
                        return(RedirectToAction("Details", new { token = token.ToString(), courseId = courseIdentification.ToString(), lessonName = name.ToString() }));
                    }
                }
                throw new Exception("Something happened...");
            }
            catch
            {
                throw new Exception("Something happened...");
            }
        }