Beispiel #1
0
        public ActionResult Edit(int chapterId, Chapter chapter)
        {
            if (ModelState.IsValid)
            {
                chapter.Id = chapterId;
                Storage.UpdateChapter(chapter);

                return RedirectToRoute("Chapters", new { action = "Index", DisciplineId = HttpContext.Session["DisciplineId"] });
            }
            else
            {
                return View(chapter);
            }
        }
Beispiel #2
0
        public ActionResult Create(int disciplineId, Chapter chapter)
        {
            if (ModelState.IsValid)
            {
                chapter.DisciplineRef = disciplineId;
                Storage.AddChapter(chapter);

                return RedirectToAction("Index");
            }
            else
            {
                return View(chapter);
            }
        }
Beispiel #3
0
        public JsonResult Edit(int chapterId, Chapter chapter)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    chapter.Id = chapterId;
                    chapter = Storage.UpdateChapter(chapter);

                    return Json(new { success = true, chapterId = chapterId, chapterRow = PartialViewAsString("ChapterRow", chapter) });
                }
                return Json(new { success = false, chapterId = chapterId, html = PartialViewAsString("Edit", chapter) });
            }
            catch (Exception ex)
            {
                return Json(new { success = false, html = ex.Message });
            }
        }
Beispiel #4
0
        public JsonResult Create(Chapter chapter, int disciplineId)
        {
            try
            {
                chapter.DisciplineRef = disciplineId;

                if (ModelState.IsValid)
                {
                    Storage.AddChapter(chapter);

                    return Json(new { success = true, disciplineId = chapter.DisciplineRef, chapterRow = PartialViewAsString("ChapterRow", chapter) });
                }

                return Json(new { success = false, disciplineId = chapter.DisciplineRef, html = PartialViewAsString("Create", chapter) });
            }
            catch (Exception ex)
            {
                return Json(new { success = false, html = ex.Message });
            }
        }
        public Chapter UpdateChapter(Chapter chapter)
        {
            var db = this.GetDbContext();
            Chapter oldChapter = GetChapter(db, chapter.Id);

            oldChapter.Name = chapter.Name;
            oldChapter.Updated = DateTime.Now;

            db.SubmitChanges();

            this.UpdateDiscipline(GetDiscipline(oldChapter.DisciplineRef));
            return oldChapter;
        }
Beispiel #6
0
 partial void UpdateChapter(Chapter instance);
Beispiel #7
0
 public void DeletingTopicWhenChapterDeleted()
 {
     Discipline cur = new Discipline {Name = "Discipline"};
     _Storage.AddDiscipline(cur);
     Curriculum as1 = new Curriculum {Discipline = cur, UserGroupRef = 1};
     _Storage.AddCurriculum(as1);
     Chapter st = new Chapter {Name = "Chapter", Discipline = cur};
     var chapterId = _Storage.AddChapter(st);
     Topic topic = new Topic {Name = "Topic", Chapter = st, TopicType = _Storage.GetTopicType(1)};
     int id = _Storage.AddTopic(topic);
     _Storage.DeleteChapter(chapterId);
     Assert.AreEqual(null, _Storage.GetTopic(id));
 }
Beispiel #8
0
        public void UpdateTopic()
        {
            Discipline cur = new Discipline {Name = "Discipline"};
            _Storage.AddDiscipline(cur);

            Curriculum as1 = new Curriculum {Discipline = cur, UserGroupRef = 1};
            _Storage.AddCurriculum(as1);

            Chapter st = new Chapter {Name = "Chapter", Discipline = cur};
            _Storage.AddChapter(st);

            Topic topic = new Topic {Name = "Topic", Chapter = st, TopicType = _Storage.GetTopicType(1)};
            int id = _Storage.AddTopic(topic);
            topic.Name = "UpdatedName";
            _Storage.UpdateTopic(topic);
            AdvAssert.AreEqual(topic, _Storage.GetTopic(id));

            try
            {
                _Storage.UpdateTopic(null);
                Assert.Fail();
            }
            catch (Exception)
            {
                Assert.True(true);
            }
        }
Beispiel #9
0
        public void GetGroupsAssignedToTopic()
        {
            Discipline cur = new Discipline {Name = "Discipline"};
            Discipline cur1 = new Discipline {Name = "Discipline1"};

            IUserService userService = _Tests.LmsService.FindService<IUserService>();
            Group gr1 = userService.GetGroup(2);
            Group gr2 = userService.GetGroup(1);

            _Storage.AddDiscipline(cur);
            _Storage.AddDiscipline(cur1);

            Curriculum ass = new Curriculum {Discipline = cur, UserGroupRef = gr1.Id, Id = 1};
            Curriculum ass1 = new Curriculum {Discipline = cur1, UserGroupRef = gr2.Id, Id = 2};
            _Storage.AddCurriculum(ass);
            _Storage.AddCurriculum(ass1);

            Chapter chapter = new Chapter {Name = "Chapter", Discipline = cur};
            Chapter chapter1 = new Chapter {Name = "Chapter1", Discipline = cur1};
            _Storage.AddChapter(chapter);
            _Storage.AddChapter(chapter1);

            Topic topic = new Topic {Name = "Topic", Chapter = chapter, TopicType = _Storage.GetTopicType(1)};
            Topic topic1 = new Topic {Name = "Topic1", Chapter = chapter1, TopicType = _Storage.GetTopicType(1)};
            var id = _Storage.AddTopic(topic);
            var id1 = _Storage.AddTopic(topic1);

            Assert.AreEqual(gr1.Id, _Storage.GetGroupsAssignedToTopic(id).First().Id);
            Assert.AreEqual(gr2.Id, _Storage.GetGroupsAssignedToTopic(id1).First().Id);
            _Storage.DeleteTopic(id1);
            try
            {
                _Storage.GetGroupsAssignedToTopic(id1);
                Assert.Fail();
            }
            catch (Exception)
            {
                Assert.True(true);
            }
            try
            {
                _Storage.DeleteCurriculum(1);
                _Storage.GetGroupsAssignedToTopic(id);
                Assert.Fail();
            }
            catch (Exception)
            {
                Assert.True(true);
            }
        }
Beispiel #10
0
 public void DeleteChapterIfDisciplineIsDeleted()
 {
     Discipline discipline = new Discipline {Name = "Discipline"};
     var currId = _Storage.AddDiscipline(discipline);
     Chapter chapter = new Chapter {Name = "Chapter", Discipline = discipline};
     var chapterId = _Storage.AddChapter(chapter);
     _Storage.DeleteDiscipline(currId);
     Assert.AreEqual(null, _Storage.GetChapter(chapterId));
 }
Beispiel #11
0
 public void UpdateChapter()
 {
     Discipline curric = new Discipline {Name = "Discipline1", Id = 1};
     Chapter chapter = new Chapter {Name = "Chapter1", Discipline = curric, Id = 1};
     _Storage.AddChapter(chapter);
     chapter.Name = "ChangedName";
     _Storage.UpdateChapter(chapter);
     AdvAssert.AreEqual(chapter, _Storage.GetChapter(1));
     try
     {
         _Storage.UpdateChapter(null);
         Assert.Fail();
     }
     catch (Exception)
     {
         Assert.True(true);
     }
 }
      public void ClearTables()
      {
         Console.Error.WriteLine("inside clear tables");

         var disciplines = new Discipline[] { };
         var chapters = new Chapter[] { };
         var topics = new Topic[] { };

         this.mockContext.SetupGet(c => c.Disciplines).Returns(new MemoryTable<Discipline>(disciplines));
         this.mockContext.SetupGet(c => c.Chapters).Returns(new MemoryTable<Chapter>(chapters));
         this.mockContext.SetupGet(c => c.Topics).Returns(new MemoryTable<Topic>(topics));

      }
Beispiel #13
0
 partial void DeleteChapter(Chapter instance);
Beispiel #14
0
 public void DeleteCourse()
 {
     Course course = _Tests.CourseStorage.GetCourse(1);
     Discipline cur = new Discipline {Name = "Discipline"};
     var currId = _Storage.AddDiscipline(cur);
     Curriculum as1 = new Curriculum {Discipline = cur, UserGroupRef = 1};
     _Storage.AddCurriculum(as1);
     Chapter st = new Chapter {Name = "Chapter", Discipline = cur};
     var chapterId = _Storage.AddChapter(st);
     Topic topic = new Topic
                       {
                           Name = "Topic",
                           Chapter = st,
                           TopicType = _Storage.GetTopicType(1),
                           CourseRef = course.Id
                       };
     _Storage.AddTopic(topic);
     _Tests.CourseStorage.DeleteCourse(course.Id);
     Assert.AreEqual(false, _Storage.GetDiscipline(currId).IsValid);
 }
        public int AddChapter(Chapter chapter)
        {
            var db = GetDbContext();
            chapter.Created = DateTime.Now;
            chapter.Updated = DateTime.Now;
            chapter.IsDeleted = false;

            db.Chapters.InsertOnSubmit(chapter);
            db.SubmitChanges();

            //add corresponding CurriculumChapters
            var curriculums = GetCurriculumsByDisciplineId(chapter.DisciplineRef);
            foreach (var curriculum in curriculums)
            {
                var curriculumChapter = new CurriculumChapter
                {
                    ChapterRef = chapter.Id,
                    CurriculumRef = curriculum.Id
                };
                AddCurriculumChapter(curriculumChapter);
            }

            return chapter.Id;
        }
Beispiel #16
0
 public void MakeDisciplineInvalid()
 {
     Discipline discipline = new Discipline {Name = "Discipline1"};
     var id = _Storage.AddDiscipline(discipline);
     Chapter chapter = new Chapter {Discipline = discipline, Name = "Chapter1"};
     _Storage.AddChapter(chapter);
     Topic topic = new Topic
                       {Name = "Topic1", Chapter = chapter, TopicType = _Storage.GetTopicType(1), CourseRef = 1};
     _Storage.AddTopic(topic);
     _Storage.MakeDisciplineInvalid(id);
     Assert.AreEqual(false, _Storage.GetDiscipline(id).IsValid);
 }
        public int AddChapter(Chapter chapter)
        {
            var db = GetDbContext();
            chapter.Created = DateTime.Now;
            chapter.Updated = DateTime.Now;
            chapter.IsDeleted = false;

            db.Chapters.InsertOnSubmit(chapter);
            db.SubmitChanges();

            return chapter.Id;
        }
Beispiel #18
0
 public void DeleteChapters()
 {
     var disciplines = CreateDefaultData();
     var chapters = disciplines.Select(item => new Chapter {Name = "Chapter", Discipline = item}).ToList();
     var ids = chapters.Select(item => _Storage.AddChapter(item)).ToList();
     Chapter notDeleted = new Chapter {Name = "NotDeletedChapter", Discipline = disciplines[0]};
     var id = _Storage.AddChapter(notDeleted);
     _Storage.DeleteChapters(ids);
     Assert.AreEqual(0, _Storage.GetChapters(ids).ToArray().Count());
     AdvAssert.AreEqual(notDeleted, _Storage.GetChapter(id));
     try
     {
         _Storage.DeleteChapters(null);
         Assert.Fail();
     }
     catch (Exception)
     {
         Assert.True(true);
     }
     try
     {
         _Storage.DeleteChapters(ids);
         Assert.Fail();
     }
     catch (Exception)
     {
         Assert.True(true);
     }
 }
        public void UpdateChapter(Chapter chapter)
        {
            var db = GetDbContext();
            Chapter oldChapter = GetChapter(db, chapter.Id);

            oldChapter.Name = chapter.Name;
            oldChapter.Updated = DateTime.Now;

            db.SubmitChanges();
        }
Beispiel #20
0
        public void GetTopicsByCourseId()
        {
            Discipline cur = new Discipline {Name = "Discipline", Id = 1};
            _Storage.AddDiscipline(cur);

            Chapter chapter = new Chapter {Name = "Chapter", Discipline = cur, Id = 1};
            _Storage.AddChapter(chapter);

            Course course = new Course {Name = "Course", Id = 1};
            Topic topic = new Topic
                              {
                                  Name = "Topic",
                                  Chapter = chapter,
                                  TopicType = _Storage.GetTopicType(1),
                                  Id = 1,
                                  CourseRef = course.Id
                              };
            Topic topic1 = new Topic
                               {
                                   Name = "Topic1",
                                   Chapter = chapter,
                                   TopicType = _Storage.GetTopicType(1),
                                   Id = 2,
                                   CourseRef = course.Id
                               };
            _Storage.AddTopic(topic);
            AdvAssert.AreEqual(topic, _Storage.GetTopicsByCourseId(course.Id).First());
            _Storage.AddTopic(topic1);
            List<Topic> expected = new List<Topic> {topic, topic1};
            AdvAssert.AreEqual(expected, _Storage.GetTopicsByCourseId(course.Id).ToList());
            try
            {
                _Storage.DeleteTopic(topic.Id);
                _Storage.DeleteTopic(topic1.Id);
                _Storage.GetTopicsByCourseId(course.Id);
                Assert.Fail();
            }
            catch (Exception)
            {
                Assert.True(true);
            }
        }
        public int AddChapter(Chapter chapter)
        {
            var id = this.storage.AddChapter(chapter);
            
            this.cacheProvider.Invalidate("chapters");

            return id;
        }
Beispiel #22
0
        public void GetTopicsAvailableForUser()
        {
            Discipline curr = new Discipline {Name = "Discipline"};
            Discipline curr1 = new Discipline {Name = "Discipline1"};
            _Storage.AddDiscipline(curr);
            _Storage.AddDiscipline(curr1);

            DateTime dtStart = new DateTime(2011, 11, 11, 0, 0, 0);
            DateTime dtIn = new DateTime(2040, 11, 11, 0, 0, 0);
            DateTime dtOf = new DateTime(2011, 11, 12, 0, 0, 0);
            Curriculum as1 = new Curriculum {Discipline = curr, UserGroupRef = 1};
            Curriculum as2 = new Curriculum {Discipline = curr1, UserGroupRef = 1};
            _Storage.AddCurriculum(as1);
            _Storage.AddCurriculum(as2);

            Timeline tml = new Timeline {Curriculum = as1, StartDate = dtStart, EndDate = dtIn};
            Timeline tml1 = new Timeline {Curriculum = as2, StartDate = dtStart, EndDate = dtOf};
            _Storage.AddTimeline(tml);
            _Storage.AddTimeline(tml1);

            Chapter st = new Chapter {Name = "Chapter1", Discipline = curr};
            Chapter st1 = new Chapter {Name = "Chapter2", Discipline = curr1};
            _Storage.AddChapter(st);
            _Storage.AddChapter(st1);

            Topic th1 = new Topic {Name = "Topic1", Chapter = st, TopicType = _Storage.GetTopicType(1)};
            Topic th2 = new Topic {Name = "Topic2", Chapter = st1, TopicType = _Storage.GetTopicType(1)};
            _Storage.AddTopic(th1);
            _Storage.AddTopic(th2);

            List<TopicDescription> result = new List<TopicDescription>
                                                {
                                                    new TopicDescription
                                                        {
                                                            Topic = th1,
                                                            Chapter = st,
                                                            Discipline = curr,
                                                            Timelines = new List<Timeline> {tml}
                                                        }
                                                };
            IUserService serv = _Tests.LmsService.FindService<IUserService>();
            User us = serv.GetUsers().First();
            AdvAssert.AreEqual(result, _Storage.GetTopicsAvailableForUser(us));

            Timeline tml2 = new Timeline
                                {
                                    ChapterRef = st.Id,
                                    Curriculum = as1,
                                    StartDate = dtStart,
                                    EndDate = new DateTime(2011, 12, 9, 0, 0, 0)
                                };
            _Storage.AddTimeline(tml2);
            result.Clear();
            AdvAssert.AreEqual(result, _Storage.GetTopicsAvailableForUser(us));
            try
            {
                User notExistedUser = new User
                                          {
                                              Id = Guid.NewGuid(),
                                              Username = "******",
                                              Email = "*****@*****.**",
                                              Password = ""
                                          };
                _Storage.GetTopicsAvailableForUser(notExistedUser);
                Assert.Fail();
            }
            catch (Exception)
            {
                Assert.True(true);
            }
        }
 public Chapter UpdateChapter(Chapter chapter)
 {
     var updatedChapter = this.storage.UpdateChapter(chapter);
     this.cacheProvider.Invalidate("chaprters", "chapter-" + chapter.Id);
     return updatedChapter;
 }
Beispiel #24
0
 public void DeleteTopic()
 {
     Discipline cur = new Discipline {Name = "Discipline"};
     _Storage.AddDiscipline(cur);
     Curriculum as1 = new Curriculum {Discipline = cur, UserGroupRef = 1};
     _Storage.AddCurriculum(as1);
     Chapter st = new Chapter {Name = "Chapter", Discipline = cur};
     _Storage.AddChapter(st);
     Topic topic = new Topic {Name = "Topic", Chapter = st, TopicType = _Storage.GetTopicType(1)};
     int id = _Storage.AddTopic(topic);
     _Storage.DeleteTopic(id);
     Assert.AreEqual(null, _Storage.GetTopic(id));
     Assert.AreEqual(0, _Storage.GetTopicAssignmentsByTopicId(id).Count());
     try
     {
         _Storage.DeleteTopic(0);
         Assert.Fail();
     }
     catch (Exception)
     {
         Assert.True(true);
     }
 }
        public int AddChapter(Chapter chapter)
        {
            var db = this.GetDbContext();
            chapter.Created = DateTime.Now;
            chapter.Updated = DateTime.Now;
            chapter.IsDeleted = false;

            db.Chapters.InsertOnSubmit(chapter);
            db.SubmitChanges();

            this.lmsService.Inform(DisciplineNotifications.ChapterCreated, chapter);

            this.UpdateDiscipline(GetDiscipline(chapter.DisciplineRef));
            return chapter.Id;
        }
Beispiel #26
0
 private void detach_Chapters(Chapter entity)
 {
     this.SendPropertyChanging();
     entity.Discipline = null;
 }
Beispiel #27
0
 partial void InsertChapter(Chapter instance);