Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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 });
            }
        }
Ejemplo n.º 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 });
            }
        }
Ejemplo n.º 5
0
        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;
        }
Ejemplo n.º 6
0
 partial void UpdateChapter(Chapter instance);
Ejemplo n.º 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));
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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));
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 12
0
      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));

      }
Ejemplo n.º 13
0
 partial void DeleteChapter(Chapter instance);
Ejemplo n.º 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);
 }
Ejemplo n.º 15
0
        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;
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 17
0
        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;
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 19
0
        public void UpdateChapter(Chapter chapter)
        {
            var db = GetDbContext();
            Chapter oldChapter = GetChapter(db, chapter.Id);

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

            db.SubmitChanges();
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 21
0
        public int AddChapter(Chapter chapter)
        {
            var id = this.storage.AddChapter(chapter);
            
            this.cacheProvider.Invalidate("chapters");

            return id;
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 23
0
 public Chapter UpdateChapter(Chapter chapter)
 {
     var updatedChapter = this.storage.UpdateChapter(chapter);
     this.cacheProvider.Invalidate("chaprters", "chapter-" + chapter.Id);
     return updatedChapter;
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 25
0
        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;
        }
Ejemplo n.º 26
0
 private void detach_Chapters(Chapter entity)
 {
     this.SendPropertyChanging();
     entity.Discipline = null;
 }
Ejemplo n.º 27
0
 partial void InsertChapter(Chapter instance);