public ActionResult Edit(int disciplineId, Discipline discipline) { try { if (ModelState.IsValid) { discipline.Id = disciplineId; discipline = Storage.UpdateDiscipline(discipline); return Json( new { success = true, disciplineId = disciplineId, disciplineRow = PartialViewAsString( "DisciplineRow", discipline.ToViewDisciplineModel(Validator.GetValidationError(discipline))) }); } return Json(new { success = false, chapterId = disciplineId, html = PartialViewAsString("Edit", discipline) }); } catch (Exception ex) { return Json(new { success = false, html = ex.Message }); } }
public string GetValidationError(Discipline discipline) { string error = Localization.GetMessage("CorrectTopics"); var chapters = this._storage.GetDiscipline(discipline.Id).Chapters.Where(item => !item.IsDeleted); var count = 0; foreach (var chapter in chapters) { var topics = chapter.Topics.Where(item => !item.IsDeleted); foreach (var topic in topics) { if (topic.TheoryCourseRef == null && topic.TestCourseRef == null) { if (count == 0) { error += " " + topic.Name; } else { error += ", " + topic.Name; } count++; } else { if (topic.TheoryCourseRef != null) { if (this._storage.GetCourse((int)topic.TheoryCourseRef) == null) { if (count == 0) { error += " " + topic.Name; } else { error += ", " + topic.Name; } count++; } } else if ((int)topic.TestCourseRef != -1) { if (this._storage.GetCourse((int)topic.TestCourseRef) == null) { if (count == 0) { error += " " + topic.Name; } else { error += ", " + topic.Name; } count++; } } } } } return error; }
public ActionResult Edit(int disciplineId, Discipline discipline) { discipline.Id = disciplineId; Storage.UpdateDiscipline(discipline); return RedirectToAction("Index"); }
public ActionResult Create(Discipline discipline) { if (ModelState.IsValid) { Storage.AddDiscipline(discipline); return RedirectToAction("Index"); } else { return View(discipline); } }
public IndexModel(ILmsService iLmsService) { IEnumerable<Discipline> allowedDisciplines; User teacherUser; teacherUser = iLmsService.FindService<IUserService>().GetCurrentUser(); //TODO: review this method allowedDisciplines=new Discipline[]{}; //allowedDisciplines = iLmsService.FindService<IDisciplineService>().GetDisciplinesWithTopicsOwnedByUser(teacherUser); // if (allowedDisciplines != null & allowedDisciplines.Count() != 0) _AllowedDisciplines = allowedDisciplines; else _AllowedDisciplines = null; _TeacherUser = teacherUser; }
public void GetDiscipline() { List<Discipline> disciplines = CreateDefaultData(); var ids = disciplines.Select(item => _Storage.AddDiscipline(item)).ToList(); disciplines.Select((item, i) => i).ToList() .ForEach(i => AdvAssert.AreEqual(disciplines[i], _Storage.GetDiscipline(ids[i]))); #region WhyDoesItWork Discipline cur = _Storage.GetDiscipline(0); Assert.AreEqual(null, cur); Discipline disciplineWithExistesId = new Discipline {Name = "ExistedDiscipline", Id = ids[0]}; _Storage.AddDiscipline(disciplineWithExistesId); _Storage.GetDiscipline(ids[0]); #endregion try { _Storage.GetDiscipline(0); Assert.Fail(); } catch (Exception) { Assert.True(true); } try { disciplineWithExistesId = new Discipline {Name = "ExistedDiscipline", Id = ids[0]}; _Storage.AddDiscipline(disciplineWithExistesId); _Storage.GetDiscipline(ids[0]); Assert.Fail(); } catch (Exception) { Assert.True(true); } }
public JsonResult Create(Discipline discipline) { try { if (ModelState.IsValid) { Storage.AddDiscipline(discipline); return Json( new { success = true, disciplineRow = PartialViewAsString( "DisciplineRow", discipline.ToViewDisciplineModel(Validator.GetValidationError(discipline))) }); } return Json(new { success = false, html = PartialViewAsString("Create", discipline) }); } catch (Exception ex) { return Json(new { success = false, html = ex.Message }); } }
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 int AddDiscipline(Discipline discipline) { var db = this.GetDbContext(); discipline.Created = DateTime.Now; discipline.Updated = DateTime.Now; discipline.IsDeleted = false; discipline.IsValid = true; discipline.Owner = this.GetCurrentUser().Username; db.Disciplines.InsertOnSubmit(discipline); db.SubmitChanges(); this.lmsService.Inform(DisciplineNotifications.DisciplineCreated, discipline); return discipline.Id; }
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 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); } }
public Discipline UpdateDiscipline(Discipline discipline) { var updatedDiscipline = this.storage.UpdateDiscipline(discipline); this.cacheProvider.Invalidate("disciplines", "discipline-" + discipline.Id); return updatedDiscipline; }
public void GetCurriculums() { IUserService userService = _Tests.LmsService.FindService<IUserService>(); Group gr = userService.GetGroup(2); Discipline cur = new Discipline {Name = "Discipline"}; _Storage.AddDiscipline(cur); List<Curriculum> curAss = new List<Curriculum>(); curAss.Add(new Curriculum {Discipline = cur, UserGroupRef = gr.Id}); var curAssId = curAss.Select(item => _Storage.AddCurriculum(item)).ToList(); Assert.AreEqual(curAss, _Storage.GetCurriculums(curAssId)); try { _Storage.GetCurriculums(null); Assert.Fail(); } catch (Exception ex) { Assert.AreEqual(true, true); } }
private bool IsDisciplineValid(Discipline discipline) { var chapters = this.GetChapters(item => item.DisciplineRef == discipline.Id); foreach (var chapter in chapters) { var topics = this.GetTopics(item => item.ChapterRef == chapter.Id); var theoryCourseRefs = topics.Select(item => item.TheoryCourseRef).Where(item => item.HasValue && item.Value >= 0); var testCourseRefs = topics.Select(item => item.TestCourseRef).Where(item => item.HasValue && item.Value >= 0); var union = theoryCourseRefs.Distinct().Union(testCourseRefs.Distinct()); if(union.Count() != theoryCourseRefs.Count() + testCourseRefs.Count()) { return false; } foreach (var topic in topics) { if (topic.TheoryCourseRef == null && topic.TestCourseRef == null) { return false; } else { if (topic.TheoryCourseRef != null) { if (this.GetCourse((int)topic.TheoryCourseRef).Deleted == true) { return false; } } else if ((int)topic.TestCourseRef != -1) { if (this.GetCourse((int)topic.TestCourseRef).Deleted == true) { return false; } } } } } return true; }
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)); }
public void DeletingGroup() { Group gr = _Tests.UserStorage.GetGroup(1); Discipline cur = new Discipline {Name = "Discipline"}; var id = _Storage.AddDiscipline(cur); Curriculum ass = new Curriculum {Discipline = cur, UserGroupRef = gr.Id}; _Storage.AddCurriculum(ass); _Tests.UserStorage.DeleteGroup(gr.Id); cur.IsValid = false; _Storage.UpdateDiscipline(cur); Discipline c = new Discipline(); Assert.AreEqual(false, _Storage.GetDiscipline(id).IsValid); }
public void DeletingUser() { Guid g = new Guid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"); User us = _Tests.UserStorage.GetUser(item => item.Id == g); Discipline cur = new Discipline {Name = "Discipline", Owner = us.Username}; var id = _Storage.AddDiscipline(cur); _Tests.UserStorage.DeleteUser(item => item.Id == us.Id); Assert.AreEqual(false, _Storage.GetDiscipline(id).IsValid); }
public void UpdateDiscipline() { Discipline discipline = new Discipline {Id = 1, Name = "Discipline1"}; _Storage.AddDiscipline(discipline); discipline.Name = "UpdatedDiscipline"; _Storage.UpdateDiscipline(discipline); var actualDiscipline = _Storage.GetDiscipline(discipline.Id); AdvAssert.AreEqual(discipline, actualDiscipline); try { _Storage.UpdateDiscipline(null); Assert.Fail(); } catch (Exception) { Assert.True(true); } }
public void GetDisciplineASsignments() { IUserService userService = _Tests.LmsService.FindService<IUserService>(); Group gr = userService.GetGroup(2); Group group = userService.GetGroup(1); Discipline cur = new Discipline {Name = "Discipline"}; _Storage.AddDiscipline(cur); List<Curriculum> curAss = new List<Curriculum>(); curAss.Add(new Curriculum {Discipline = cur, UserGroupRef = gr.Id}); curAss.Add(new Curriculum {Discipline = cur, UserGroupRef = group.Id}); curAss.Add(new Curriculum {Discipline = cur, UserGroupRef = gr.Id}); curAss.ForEach(item => _Storage.AddCurriculum(item)); Assert.AreEqual(curAss, _Storage.GetCurriculums().ToList()); }
public void GetCurriculumsByGroupId() { IUserService userService = _Tests.LmsService.FindService<IUserService>(); Group gr = userService.GetGroup(2); int groupId = gr.Id; Discipline cur = new Discipline {Name = "Discipline"}; _Storage.AddDiscipline(cur); List<Curriculum> curAss = new List<Curriculum>(); curAss.Add(new Curriculum {Discipline = cur, UserGroupRef = gr.Id}); curAss.ForEach(item => _Storage.AddCurriculum(item)); Assert.AreEqual(curAss, _Storage.GetCurriculumsByGroupId(groupId).ToList()); try { _Storage.GetDisciplineAssignmnetsByDisciplineId(groupId + 1); Assert.Fail(); } catch (Exception ex) { Assert.AreEqual(true, true); } }
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); } }
public Discipline UpdateDiscipline(Discipline discipline) { var db = this.GetDbContext(); var updatingDiscipline = GetDiscipline(db, discipline.Id); var oldDiscipline = new Discipline { Id = updatingDiscipline.Id }; updatingDiscipline.Name = discipline.Name; updatingDiscipline.Updated = DateTime.Now; updatingDiscipline.IsValid = this.IsDisciplineValid(discipline); db.SubmitChanges(); var data = new object[2]; data[0] = oldDiscipline; data[1] = updatingDiscipline; this.lmsService.Inform(DisciplineNotifications.DisciplineEdited, data); return updatingDiscipline; }
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 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 DisciplineResult(Discipline discipline, string update) { this.discipline = discipline; this.update = update; }
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)); }
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 void GetCurriculum() { IUserService userService = _Tests.LmsService.FindService<IUserService>(); Group gr = userService.GetGroup(2); Discipline cur = new Discipline {Name = "Discipline"}; _Storage.AddDiscipline(cur); Curriculum curAss = new Curriculum {Discipline = cur, UserGroupRef = gr.Id}; int curAssId = _Storage.AddCurriculum(curAss); AdvAssert.AreEqual(curAss, _Storage.GetCurriculum(curAssId)); try { _Storage.GetCurriculum(0); Assert.Fail(); } catch (Exception ex) { Assert.AreEqual(true, true); } }
public ActionResult Edit(int disciplineId, Discipline discipline) { try { discipline.Id = disciplineId; Storage.UpdateDiscipline(discipline); return RedirectToAction("Index"); } catch (Exception e) { throw e; } }
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); }