public SubjectWindow(DeaneryLibrary.GroupItem group) { InitializeComponent(); Subjects = new SubjectRepository().GetSubjectsByGroupId(group.Id); _group_id = group.Id; DataContext = this; }
public void SubjectRepositoryTest1() { var repo = new SubjectRepository(); var subject = repo.GetAll().FirstOrDefault(); Assert.IsInstanceOfType(subject, typeof(Subject)); }
private void InitializeAppRepositories() { Students = new StudentsRepository(Student); Teachers = new TeachersRepository(Teacher); Subjects = new SubjectRepository(Subject); LessonPlans = new LessonPlanRepository(LessonPlan); StudentsLessonPlans = new StudentsLessonRepository(StudentsLessonPlan); }
public void oneTimeSetUp() { var connection = DbConnectionFactory.CreateTransient(); this.ctx = new ApplicationDbContext(connection); this.repo = new SubjectRepository(ctx); new DatabaseSeeder().CreateDependenciesAndSeed(ctx);//heavy duty }
public void Doldur1() { int id = Convert.ToInt32(Session["UserId"]); SubjectRepository konuislem = new SubjectRepository(); GridviewPaylasimlar.DataSource = sunumislem.HepsiniGetir().Where(p => p.TrainerID == id).ToList(); GridviewPaylasimlar.DataBind(); }
public SubjectsController(SubjectRepository subjectRepository, ClassesRepository classesRepository, SubjectsViewModelValidator subjectsViewModelValidator) { _subjectRepository = subjectRepository; _classesRepository = classesRepository; _subjectsViewModelValidator = subjectsViewModelValidator; }
public SubjectBusiness(IServiceProvider provider, SubjectRepository repository, SubjectRuleRepository rulerepository, SubjectStepRepository steprepository, SubjectTypeRepository repositoryTypeSubject) : base(provider, repository) { this._repository = repository; this._rulerepository = rulerepository; this._steprepository = steprepository; this._repositoryTypeSubject = repositoryTypeSubject; }
public ApiScheduleService() { SessionFactory.Load(ConfigurationManager.ConnectionStrings["Audience"].ConnectionString); _facultyRepository = new FacultyRepository(); _groupRepository = new GroupRepository(); _subjRepository = new SubjectRepository(); }
public SubjectService(SubjectRepository subjectRepository) { _markRepository = new MarksRepository(new SchoolContext()); _database = new SchoolContext(); // _studentService = new StudentService(); _subjectRepository = subjectRepository; _markService = new MarkService(); }
public StudentService() { _context = new SchoolContext(); _subjectRepository = new SubjectRepository(_context); _studentRepository = new StudentRepository(_context); _markRepository = new MarksRepository(_context); _subjectService = new SubjectService(_subjectRepository); }
public ActionResult SubjectIndex(Guid id) { var subjectRepository = new SubjectRepository(_context); var subject = subjectRepository.GetById(id); var viewModel = SubjectViewModel.FromEntity(subject, 3); return(PartialView("_SubjectIndex", viewModel)); }
public ActionResult IndexAdmin(string term, string searchFieldName, int page = 1) { var subjectRepository = new SubjectRepository(_context); ViewBag.SearchFields = new SelectList(new[] { Resource.SubjectNameFieldName, Resource.KnowledgeAreaName, "Id" }); return(View(SubjectViewModel.FromEntityList(subjectRepository.Search(term, searchFieldName, page)))); }
public ActionResult Delete(string id) { var subjectRepository = new SubjectRepository(_context); subjectRepository.Delete(new Guid(id)); _context.Save(_loggedUser); return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
public void SetUp() { mongoProvider = new MongoProvider("mongodb://localhost:27017", "Student"); groupRepository = new GroupRepository(mongoProvider); subjectRepository = new SubjectRepository(mongoProvider); topicRepository = new TopicRepository(mongoProvider); teacherRepository = new TeacherRepository(mongoProvider); }
public TimeTableController(TimeTableManager timeTableManager, TimeTableRepository timeTableRepository, SubjectRepository subjectRepository, FacultyRepository facultyRepository, ClassesRepository classesRepository, TimeTableViewModelValidator tableViewModelValidator) { _timeTableManager = timeTableManager; _timeTableRepository = timeTableRepository; _subjectRepository = subjectRepository; _facultyRepository = facultyRepository; _classesRepository = classesRepository; _tableViewModelValidator = tableViewModelValidator; }
//public ActionResult DeleteTitle(int id) //{ // Title title = new Title(); // TitleRepository titleRepository = new TitleRepository(); // TeacherRepository teacherRepository = new TeacherRepository(); // title = titleRepository.GetById(id); // if (teacherRepository.GetAll(filter: t => t.TitleID == title.Id) == null) // { // titleRepository.Delete(title); // } // else // { // } // return RedirectToAction("ManageTitles"); //} #endregion #region ManageSubjects public ActionResult ManageSubjects() { SubjectRepository subjectRepository = new SubjectRepository(); AdminControllerSubjectVM subjectModel = new AdminControllerSubjectVM(); subjectModel.subjectList = subjectRepository.GetAll(); return(View(subjectModel)); }
public ucSubjectDetailView(string mode, int id = 0) { InitializeComponent(); FormMode = mode; _subjectID = id; _subjectRepository = new SubjectRepository(); ViewModeGenericWork(); }
public void AddSubjectTest() { SubjectRepository rep = new SubjectRepository(); Subject plan = new Subject() { SubjectName = "Test", TeacherId = 1 }; }
public void DeleteSubjectTest() { SubjectRepository rep = new SubjectRepository(); rep.Delete(16); Subject plan = rep.Read(16); Assert.IsNull(plan); }
public void UpdateSubjectTest() { SubjectRepository rep = new SubjectRepository(); Subject plan = rep.Read(11); plan.SubjectName = "Test2"; rep.Update(plan); Assert.AreEqual("Test2", plan.SubjectName); }
public void DeleteByNullValue() { // Arrange SubjectRepository subjectRepository = new SubjectRepository(dbContext); // Act // Assert Assert.ThrowsException <ArgumentNullException>(() => subjectRepository.Delete(entityToDelete: null)); }
public UnitOfWork(LibraryContext context) { Context = context; Books = new BookRepository(Context); Members = new MemberRepository(Context); Issues = new TransactionRepository(Context); Authors = new AuthorRepository(Context); Subjects = new SubjectRepository(Context); }
public ActionResult ManageCourseSubject() { AdminControllerCourseSubjectVM courseSubModel = new AdminControllerCourseSubjectVM(); SubjectRepository subjectRepository = new SubjectRepository(); CourseRepository courseRepository = new CourseRepository(); courseSubModel.courseList = courseRepository.GetAll(); courseSubModel.subjectList = subjectRepository.GetAll(); return(View(courseSubModel)); }
public void DeleteByNullKey_Exception() { // Arrange SubjectRepository subjectRepository = new SubjectRepository(dbContext); object wrongId = null; // Act // Assert Assert.ThrowsException <ArgumentNullException>(() => subjectRepository.Delete(wrongId)); }
public CourseController(SubscriberRepository subscriberRepository, AuthorRepository authorRepository, CourseRepository courseRepository, SubscriptionRepository subscriptionRepository, SubjectRepository subjectRepository) { this.authorRepository = authorRepository; this.subscriberRepository = subscriberRepository; this.courseRepository = courseRepository; this.subscriptionRepository = subscriptionRepository; this.subjectRepository = subjectRepository; }
public void DeleteByWrongKey_Exception() { // Arrange SubjectRepository subjectRepository = new SubjectRepository(dbContext); Guid wrongId = default(Guid); // Act // Assert Assert.ThrowsException <InvalidOperationException>(() => subjectRepository.Delete(wrongId)); }
public ActionResult Delete(SubjectViewModel subjectViewModel) { SubjectRepository repository = new SubjectRepository(); if (subjectViewModel.Id.ToString() != String.Empty) { repository.Delete(subjectViewModel.Id); } return(RedirectToAction("Index")); }
public WorkflowMainBusiness(IServiceProvider provider, WorkflowMainRepository repository, SubjectRepository repositorySubject, SubjectStepBusiness subjectStepBusiness, SubjectRepository subjectRepository, SubjectTypeRepository repositoryTypeSubject, WorkflowApprovalStepRepository workflowApprovalStepRepository, SubjectRuleRepository subjectRuleRepository, WorkflowApprovalRecordsRepository workflowApprovalRecordsRepository) : base(provider, repository) { this._repository = repository; this._repositorySubject = repositorySubject; this._subjectStepBusiness = subjectStepBusiness; this._subjectRepository = subjectRepository; this._repositoryTypeSubject = repositoryTypeSubject; this._workflowApprovalStepRepository = workflowApprovalStepRepository; this._subjectRuleRepository = subjectRuleRepository; this._workflowApprovalRecordsRepository = workflowApprovalRecordsRepository; }
public ActionResult Index() { SubjectRepository repository = new SubjectRepository(); List <Subject> subjects = repository.GetAll(); SubjectListViewModel model = new SubjectListViewModel(); model.Subjects = subjects; return(View(model)); }
public async Task GetByEmail_Should_Return_Correct_Value(string name, string surname, string email, int id) { //Act var result = await _sut.GetByEmail(email) as OkObjectResult; // Assert SubjectRepository.Verify(x => x.GetByEmail(It.IsAny <string>()), Times.Once); Assert.Equal(result.StatusCode, (int)HttpStatusCode.OK); Assert.Equal(((SubjectResponseModel)result.Value).Name, name); Assert.Equal(((SubjectResponseModel)result.Value).Surname, surname); Assert.Equal(((SubjectResponseModel)result.Value).Id, id); }
public void GetAll_Should_Return_Correct_Value(string name, string surname, string email) { //Act var result = _sut.Get() as OkObjectResult; // Assert SubjectRepository.Verify(x => x.GetAll(), Times.Once); Assert.Equal(result.StatusCode, (int)HttpStatusCode.OK); Assert.Equal(((List <SubjectResponseModel>)result.Value).First().Name, name); Assert.Equal(((List <SubjectResponseModel>)result.Value).First().Surname, surname); Assert.Equal(((List <SubjectResponseModel>)result.Value).First().Email, email); }
public void Count() { // Arrange SubjectRepository subjectRepository = new SubjectRepository(dbContext); int expectedSubjectInDb = dbContext.Subjects.Count(); // Act int actualSubjectInDb = subjectRepository.Count(); // Assert Assert.AreEqual(expectedSubjectInDb, actualSubjectInDb); }
public ActionResult DeleteSubject(int id) { SubjectRepository subjectRepo = new SubjectRepository(); SubjectDeleteSubjectVM model = new SubjectDeleteSubjectVM(); Subject subject = subjectRepo.GetByID(id); model.SubjectID = subject.ID; model.SubjectName = subject.Name; return View(model); }
public async Task Delete_Should_Return_IsDeleted_Value(string name, string surname, string email, int id) { //Act var result = await _sut.Delete(id) as OkObjectResult; // Assert SubjectRepository.Verify(x => x.Delete(It.IsAny <int>()), Times.Once); var model = (SubjectResponseModel)result.Value; Assert.True(model.IsDeleted); }
public ActionResult EditSubject(int? id) { SubjectEditSubjectVM model = new SubjectEditSubjectVM(); model.Action = "Create"; if (id != null) { SubjectRepository subjectRepo = new SubjectRepository(); Subject subject = subjectRepo.GetAll(filter: s => s.ID == id.Value).FirstOrDefault(); model.Action = "Edit"; model.SubjectID = subject.ID; model.SubjectName = subject.Name; } return View(model); }
public ActionResult DeleteSubject(SubjectDeleteSubjectVM model) { SubjectRepository subjectRepo = new SubjectRepository(); Subject subject = subjectRepo.GetByID(model.SubjectID); if (subject.CourseSubject.Count() > 0) { ModelState.AddModelError("Error", "Subject contains teacher or course"); model.SubjectID = subject.ID; model.SubjectName = subject.Name; return View(model); } subjectRepo.Delete(subject); return RedirectToAction("ListSubjects", "Subject"); }
public ActionResult AddGrade(int studentID, int subjectID) { GradeAddGradeVM model = new GradeAddGradeVM(); UserRepository<Student> sRepo = new UserRepository<Student>(); SubjectRepository subjRepo = new SubjectRepository(); GradeRepository gRepo = new GradeRepository(); Student student = sRepo.GetAll(filter: s => s.ID == studentID && s.Course.CourseSubject.Any(sub => sub.SubjectID == subjectID)).FirstOrDefault(); Subject subject = subjRepo.GetByID(subjectID); Grade grade = gRepo.GetAll(filter: g => g.StudentID == student.ID).FirstOrDefault(); model.StudentID = student.ID; model.SubjectID = subject.ID; return View(model); }
public ActionResult ListStudentsBySubject(int id) { UserRepository<Student> stuRepo = new UserRepository<Student>(); SubjectRepository subjectRepo = new SubjectRepository(); StudentListStudentsBySubjectVM model = new StudentListStudentsBySubjectVM(); Subject course = subjectRepo.GetByID(id); var students = stuRepo.GetAll(filter: s => s.Course.CourseSubject.Any(c => c.SubjectID == id)); model.Students = students; model.SubjectName = course.Name; return View(model); }
public void ExportSubjectListToCSV(int id) { GradeStudentsGradesVM model = new GradeStudentsGradesVM(); GradeRepository gradeRepo = new GradeRepository(); SubjectRepository subjRepo = new SubjectRepository(); UserRepository<Student> studentRepo = new UserRepository<Student>(); List<Student> students = studentRepo.GetAll(filter: s => s.Course.CourseSubject.Any(t => t.SubjectID == id)); List<Grade> grades = gradeRepo.GetAll(filter: s => s.SubjectID == id); Subject subject = subjRepo.GetByID(id); StringWriter sw = new StringWriter(); sw.WriteLine("\"Faculty number\",\"First name\",\"Last name\",\"Grade\""); Response.ClearContent(); Response.AddHeader("content-disposition", "attachment;filename="+ subject.Name +".csv"); Response.ContentType = "text/csv"; foreach (var student in students) { string grade = student.Grades.Select(x => x.GradeValue).FirstOrDefault().ToString(); grade = grade == "0" ? "" : grade; sw.WriteLine(string.Format("\"{0}\",\"{1}\",\"{2}\",\"{3}\"", student.FacultiNumber, student.FirstName, student.LastName, grade)); } Response.Write(sw.ToString()); Response.End(); }
public ActionResult StudentsGrades(int id) { GradeStudentsGradesVM model = new GradeStudentsGradesVM(); GradeRepository gradeRepo = new GradeRepository(); SubjectRepository subjRepo = new SubjectRepository(); UserRepository<Student> studentRepo = new UserRepository<Student>(); model.Students = studentRepo.GetAll(filter: s => s.Course.CourseSubject.Any(t => t.SubjectID == id)); Subject subject = subjRepo.GetByID(id); model.SubjectID = subject.ID; return View(model); }
public ActionResult EditArticle(int id) { if (AuthenticationManager.LoggedUser.GetType().BaseType.Equals(typeof(Teacher))) { ArticleControllerArticlesVM model = new ArticleControllerArticlesVM(); TeacherRepository teacherRepository = new TeacherRepository(); Article article = new Article(); ArticleRepository articleRepository = new ArticleRepository(); List<Subject> subjectList = new List<Subject>(); SubjectRepository subjectRepository = new SubjectRepository(); Teacher teacher = new Teacher(); List<SelectListItem> listSubjects = new List<SelectListItem>(); teacher = teacherRepository.GetById(AuthenticationManager.LoggedUser.Id); List<int> subjectId = new List<int>(); foreach (var item in teacher.CourseSubject) { subjectId.Add(item.Subject.Id); } subjectId = subjectId.Distinct().ToList(); foreach (var item in subjectId) { subjectList.Add(subjectRepository.GetById(item)); } if (id > 0) { article = articleRepository.GetById(id); model.ArticleId = article.Id; model.TeacherID = teacher.Id; model.Title = article.Title; model.Content = article.Content; model.DateCreated = article.DateCreated; model.DateModified = article.DateModified; model.Subject = article.Subject; model.Teacher = teacher; listSubjects.Add(new SelectListItem() { Text = article.Subject.Name, Value = article.Subject.Id.ToString(), Selected = true }); } if (id == 0) { model.ArticleId = 0; listSubjects.Add(new SelectListItem() { Text = "Select subject", Value = "" }); } foreach (var item in subjectList) { if (item.Id != model.ArticleId) { listSubjects.Add(new SelectListItem() { Text = item.Name, Value = item.Id.ToString() }); } } model.SubjectsListItems = listSubjects; return View(model); } return RedirectToAction("Articles"); }
public ActionResult EditSubjects(int id) { Subject subject = new Subject(); SubjectRepository subjectRepository = new SubjectRepository(); AdminControllerSubjectVM subjectModel = new AdminControllerSubjectVM(); if (id > 0) { subject = subjectRepository.GetById(id); subjectModel.Name = subject.Name; subjectModel.SubjectID = id; } if (id == 0) { subject.Name = subjectModel.Name; } return View(subjectModel); }
public JsonResult DeleteSubject(int id) { bool subjectInUse = false; CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository(); List<Course> courseList = new List<Course>(); courseList = courseSubjectRepository.GetAll(filter: cs => cs.Subject.Id == id).Select(c => c.Course).ToList(); if (courseList.Count > 0) { subjectInUse = true; } else { SubjectRepository subjectRepository = new SubjectRepository(); Subject subject = new Subject(); subject = subjectRepository.GetById(id); subjectRepository.Delete(subject); } return Json(subjectInUse, JsonRequestBehavior.AllowGet); }
public ActionResult Home() { AdminControllerAdminVM model = new AdminControllerAdminVM(); StudentRepository studentRepository = new StudentRepository(); TeacherRepository teacherRepository = new TeacherRepository(); CourseRepository courseRepository = new CourseRepository(); SubjectRepository subjectRepository = new SubjectRepository(); TitleRepository titleRepository = new TitleRepository(); model.ActiveStudentCount = studentRepository.GetAll(filter: s => s.IsActive == true).Count; model.InActiveStudentCount = studentRepository.GetAll(filter: s => s.IsActive == false).Count; model.ActiveTeacherCount = teacherRepository.GetAll(filter: t => t.IsActive == true).Count; model.InActiveTeacherCount = teacherRepository.GetAll(filter: t => t.IsActive == false).Count; model.CourseCount = courseRepository.GetAll().Count; model.SubjectCount = subjectRepository.GetAll().Count; model.TitleCount = titleRepository.GetAll().Count(); Administrator admin = new Administrator(); AdministratorRepository adminRepository = new AdministratorRepository(); admin = adminRepository.GetById(AuthenticationManager.LoggedUser.Id); model.FirstName = admin.FirstName; model.LastName = admin.LastName; return View(model); }
public ActionResult ManageCourseSubject() { AdminControllerCourseSubjectVM courseSubModel = new AdminControllerCourseSubjectVM(); SubjectRepository subjectRepository = new SubjectRepository(); CourseRepository courseRepository = new CourseRepository(); courseSubModel.courseList = courseRepository.GetAll(); courseSubModel.subjectList = subjectRepository.GetAll(); return View(courseSubModel); }
public JsonResult CheckForExistingName(string name, string type, int id) { bool exist = false; switch (type) { case "Admin": Administrator admin = new Administrator(); AdministratorRepository adminRepository = new AdministratorRepository(); admin = adminRepository.GetAll(filter: a => a.UserName == name && a.Id != id).FirstOrDefault(); if (admin != null) { exist = true; }; break; case "Student": Student student = new Student(); StudentRepository studentRepository = new StudentRepository(); student = studentRepository.GetAll(filter: s => s.UserName == name && s.Id != id).FirstOrDefault(); if (student != null) { exist = true; }; break; case "Teacher": Teacher teacher = new Teacher(); TeacherRepository teacherRepository = new TeacherRepository(); teacher = teacherRepository.GetAll(filter: t => t.UserName == name && t.Id != id).FirstOrDefault(); if (teacher != null) { exist = true; }; break; case "Course": Course course = new Course(); CourseRepository courseRepository = new CourseRepository(); course = courseRepository.GetAll(filter: c => c.Name == name).FirstOrDefault(); if (course != null) { exist = true; }; break; case "Title": Title title = new Title(); TitleRepository titleRepository = new TitleRepository(); title = titleRepository.GetAll(filter: t => t.Name == name).FirstOrDefault(); if (title != null) { exist = true; }; break; case "Subject": Subject subject = new Subject(); SubjectRepository subjectRepository = new SubjectRepository(); subject = subjectRepository.GetAll(filter: s => s.Name == name).FirstOrDefault(); if (subject != null) { exist = true; }; break; } return Json(exist, JsonRequestBehavior.AllowGet); }
public ActionResult EditSubjects(int id, AdminControllerSubjectVM subjectModel) { TryUpdateModel(subjectModel); if (ModelState.IsValid) { Subject subject = null; SubjectRepository subjectRepository = new SubjectRepository(); if (id > 0) { subject = subjectRepository.GetById(id); subject.Name = subjectModel.Name; subjectRepository.Save(subject); return RedirectToAction("ManageSubjects"); } else { subject = subjectRepository.GetAll(filter: s => s.Name == subjectModel.Name).FirstOrDefault(); if (subject == null) { subject = new Subject(); subject.Name = subjectModel.Name; subjectRepository.Save(subject); return RedirectToAction("ManageSubjects"); } else { throw new ArgumentException("Invalid subject name"); } } } return View(subjectModel); }
public ActionResult Index() { TeacherIndexVM model = new TeacherIndexVM(); CourseRepository courseRepo = new CourseRepository(); SubjectRepository subjRepo = new SubjectRepository(); CourseSubjectRepository csRepo = new CourseSubjectRepository(); model.Subjects = subjRepo.GetAll(filter: s => s.CourseSubject.Any(c => c.Teachers.Any(t => t.ID == UniversitySystem.Models.AuthenticationManager.LoggedUser.ID))); model.Courses = courseRepo.GetAll(filter: c => c.CourseSubject.Any(s => s.Teachers.Any(t => t.ID == UniversitySystem.Models.AuthenticationManager.LoggedUser.ID))); return View(model); }
public ActionResult EditSubject(SubjectEditSubjectVM model) { if (!ModelState.IsValid) { return View(); } SubjectRepository subjectRepo = new SubjectRepository(); Subject subject = new Subject(); if (model.SubjectID != 0) { subject = subjectRepo.GetByID(model.SubjectID); } subject.Name = model.SubjectName; subjectRepo.Save(subject); return RedirectToAction("ListSubjects", "Subject"); }
public ActionResult ExportSubjectGrade(int id) { Subject subject = new Subject(); SubjectRepository subjectRepository = new SubjectRepository(); subject = subjectRepository.GetById(id); Export export = new Export(); DataTable gradeTable = export.SubjectGrades(subject); GridView Grid = new GridView(); Grid.DataSource = gradeTable; Grid.DataBind(); string filename = "attachment; filename=" + subject.Name + "_" + ".xls"; Response.ClearContent(); Response.Buffer = true; Response.AddHeader("content-disposition", filename); Response.ContentType = "application/ms-excel"; Response.Charset = ""; StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); Grid.RenderControl(htw); Response.Output.Write(sw.ToString()); Response.Flush(); Response.End(); return View(); }
public ActionResult EditCourseSubject(int courseID) { AdminControllerCourseSubjectVM courseSubjectModel = new AdminControllerCourseSubjectVM(); SubjectRepository subjectRepository = new SubjectRepository(); CourseSubjectRepository courseSubjectRepo = new CourseSubjectRepository(); List<Subject> subjectList = courseSubjectRepo.GetAll(filter: cs => cs.Course.Id == courseID).Select(s => s.Subject).ToList(); courseSubjectModel.subjectList = subjectRepository.GetAll();//Except method is overriden List<SelectListItem> List = new List<SelectListItem>(); foreach (var item in courseSubjectModel.subjectList) { List.Add(new SelectListItem() { Text = item.Name, Value = item.Id.ToString() }); } courseSubjectModel.ListItems = List; courseSubjectModel.subjectList = subjectRepository.GetAll(); courseSubjectModel.courseID = courseID; courseSubjectModel.CourseSubjectID = courseID; return View(courseSubjectModel); }
/// <summary> /// List all subjects /// </summary> /// <returns>List of subjects</returns> public ActionResult ListSubjects() { SubjectListSubjectsVM model = new SubjectListSubjectsVM(); UserRepository<Student> stuRepo = new UserRepository<Student>(); SubjectRepository subjRepo = new SubjectRepository(); List<Student> student = stuRepo.GetAll(); var subjects = subjRepo.GetAll(); var subjectList = new Dictionary<Subject, int>(); foreach (var subject in subjects) { int count = 0; if (student.Any(s => s.Course.CourseSubject.Any(x => x.SubjectID == subject.ID))) { count = student.Count(x => x.Course.CourseSubject.Any(c => c.SubjectID == subject.ID)); } subjectList.Add(subject, count); } model.SubjectList = subjectList; return View(model); }
public JsonResult EditGrade(int gradeId, double gradeValue, int subjectId, int studentId) { Grade grade = new Grade(); GradeRepository gradeRepo = new GradeRepository(); SelectListItem gradeItem = null; if (gradeId != 0) { grade = gradeRepo.GetById(gradeId); gradeValue = System.Math.Round(gradeValue, 2); grade.GradeValue = gradeValue; gradeRepo.Save(grade); } else { UnitOfWork unitOfWork = new UnitOfWork(); StudentRepository studentRepository = new StudentRepository(unitOfWork); GradeRepository gradeRepository = new GradeRepository(unitOfWork); SubjectRepository subjectRepository = new SubjectRepository(unitOfWork); Student student = new Student(); student = studentRepository.GetById(studentId); Subject subject = new Subject(); subject = subjectRepository.GetById(subjectId); grade.SubjectID = subjectId; grade.Subject = subject; grade.Student = student; gradeValue = System.Math.Round(gradeValue, 2); grade.GradeValue = gradeValue; gradeRepository.Save(grade); unitOfWork.Commit(); } gradeItem = new SelectListItem() { Text = grade.GradeValue.ToString(), Value = grade.Id.ToString() }; return Json(gradeItem, JsonRequestBehavior.AllowGet); }
public ActionResult EditArticle(ArticleControllerArticlesVM model) { TryUpdateModel(model); if (model.SubjectID < 1 || !ModelState.IsValid) { model.ArticleId = 0; List<CourseSubject> courseSubject = new List<CourseSubject>(); Teacher teacher = new Teacher(); TeacherRepository teacherRepository = new TeacherRepository(); teacher = teacherRepository.GetById(AuthenticationManager.LoggedUser.Id); courseSubject = teacher.CourseSubject.ToList(); List<SelectListItem> listSubjects = new List<SelectListItem>(); listSubjects.Add(new SelectListItem() { Text = "Select subject", Value = "" }); foreach (var item in courseSubject) { if (item.Subject.Id != model.ArticleId) { listSubjects.Add(new SelectListItem() { Text = item.Subject.Name, Value = item.Subject.Id.ToString() }); } } model.SubjectsListItems = listSubjects; } if (ModelState.IsValid) { Article article = new Article(); ArticleRepository articleRepository = new ArticleRepository(); Subject subject = new Subject(); SubjectRepository subjectRepository = new SubjectRepository(); Teacher teacher = new Teacher(); TeacherRepository teacherRepository = new TeacherRepository(); teacher = teacherRepository.GetById(AuthenticationManager.LoggedUser.Id); if (model.ArticleId > 0) { article = articleRepository.GetById(model.ArticleId); article.Content = model.Content; article.DateCreated = model.DateCreated; article.DateModified = DateTime.Now; article.SubjectID = model.SubjectID; article.TeacherID = teacher.Id; article.Title = model.Title; } else { article.Content = model.Content; article.DateCreated = DateTime.Now; article.SubjectID = model.SubjectID; article.TeacherID = teacher.Id; article.Title = model.Title; } articleRepository.Save(article); return RedirectToAction("Articles"); } return View(model); }
public void ExportSubjectListToExcel(int id) { GradeStudentsGradesVM model = new GradeStudentsGradesVM(); GradeRepository gradeRepo = new GradeRepository(); SubjectRepository subjRepo = new SubjectRepository(); UserRepository<Student> studentRepo = new UserRepository<Student>(); List<Student> students = studentRepo.GetAll(filter: s => s.Course.CourseSubject.Any(t => t.SubjectID == id)); List<Grade> grades = gradeRepo.GetAll(filter: s => s.SubjectID == id); Subject subject = subjRepo.GetByID(id); var grid = new System.Web.UI.WebControls.GridView(); var products = new System.Data.DataTable(subject.Name); products.Columns.Add("FacultiNumber", typeof(string)); products.Columns.Add("FirstName", typeof(string)); products.Columns.Add("LastName", typeof(string)); products.Columns.Add("Grade", typeof(string)); foreach (var student in students) { string grade = student.Grades.Select(x => x.GradeValue).FirstOrDefault().ToString(); grade = grade == "0" ? "" : grade; products.Rows.Add(student.FacultiNumber, student.FirstName, student.LastName, grade); } grid.DataSource = products; // grid.DataSource = model.Students; grid.DataBind(); Response.ClearContent(); Response.AddHeader("content-disposition", "attachment; filename=" + subject.Name + ".xlsx"); Response.ContentType = "application/excel"; StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); grid.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); }
public ActionResult Index() { if (AuthenticationManager.LoggedUser == null || !AuthenticationManager.LoggedUser.GetType().BaseType.Equals(typeof(Teacher))) { return RedirectToAction("Login", "Default"); } TeacherControllerTeacherVM model = new TeacherControllerTeacherVM(); Teacher teacher = new Teacher(); TeacherRepository teacherRepository = new TeacherRepository(); teacher = teacherRepository.GetById(AuthenticationManager.LoggedUser.Id); model.FirstName = teacher.FirstName; model.LastName = teacher.LastName; CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository(); CourseRepository courseRepository = new CourseRepository(); SubjectRepository subjectRepository = new SubjectRepository(); List<int> subjectList = new List<int>(); Dictionary<string, List<Subject>> courseSubjectList = new Dictionary<string, List<Subject>>(); List<Subject> subjects = new List<Subject>(); List<int> courseList = new List<int>(); foreach (var courseSubject in teacher.CourseSubject) { courseList.Add(courseSubject.Course.Id); subjectList.Add(courseSubject.Subject.Id); } subjectList = subjectList.Distinct().ToList(); courseList = courseList.Distinct().ToList(); Course course = new Course(); foreach (var courseID in courseList) { course = courseRepository.GetById(courseID); subjects = courseSubjectRepository.GetAll(filter: c => c.Course.Id == courseID && subjectList.Contains(c.Subject.Id)).Select(s => s.Subject).ToList(); courseSubjectList.Add(course.Name, subjects); } model.CourseSubjectList = courseSubjectList; return View(model); }
public ActionResult EditCourseSubject(AdminControllerCourseSubjectVM courseSubjectModel) { CourseSubject courseSubject = new CourseSubject(); CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository(); TryUpdateModel(courseSubjectModel); if (ModelState.IsValid && courseSubjectModel.CourseSubjectID > 0) { courseSubject.CourseID = courseSubjectModel.courseID; courseSubject.SubjectID = courseSubjectModel.subjectID; courseSubjectRepository.Save(courseSubject); return RedirectToAction("ShowSubjects", "Admin", new { @id = courseSubjectModel.courseID }); } if (courseSubjectModel.ListItems == null) { List<SelectListItem> List = new List<SelectListItem>(); SubjectRepository subjectRepository = new SubjectRepository(); courseSubjectModel.subjectList = subjectRepository.GetAll(); foreach (var item in courseSubjectModel.subjectList) { List.Add(new SelectListItem() { Text = item.Name, Value = item.Id.ToString() }); } courseSubjectModel.ListItems = List; } return View(courseSubjectModel); }
public ActionResult ManageSubjects() { SubjectRepository subjectRepository = new SubjectRepository(); AdminControllerSubjectVM subjectModel = new AdminControllerSubjectVM(); subjectModel.subjectList = subjectRepository.GetAll(); return View(subjectModel); }
public SubjectBusiness(SubjectRepository subjectRepo) { _subjectRepo = subjectRepo; }