예제 #1
0
 public ActionResult EditTitles(int id, AdminControllerTitleVM titleModel)
 {
     TryUpdateModel(titleModel);
     if (ModelState.IsValid)
     {
         Title           title           = null;
         TitleRepository titleRepository = new TitleRepository();
         if (id > 0)
         {
             title      = titleRepository.GetById(id);
             title.Name = titleModel.Title;
             titleRepository.Save(title);
             return(RedirectToAction("ManageTitles"));
         }
         else
         {
             title = titleRepository.GetAll(filter: t => t.Name == titleModel.Title).FirstOrDefault();
             if (title == null)
             {
                 title      = new Title();
                 title.Name = titleModel.Title;
                 titleRepository.Save(title);
                 return(RedirectToAction("ManageTitles"));
             }
             else
             {
                 throw new ArgumentException("Invalid Title");
             }
         }
     }
     return(View(titleModel));
 }
예제 #2
0
        public ActionResult ManageTitles()
        {
            TitleRepository        titleRepository = new TitleRepository();
            AdminControllerTitleVM titleModel      = new AdminControllerTitleVM();

            titleModel.titleList = titleRepository.GetAll();
            return(View(titleModel));
        }
예제 #3
0
        public ActionResult EditTeachers(int id)
        {
            TeacherRepository        teacherRepository = new TeacherRepository();
            TitleRepository          titleRepository   = new TitleRepository();
            Teacher                  teacher           = new Teacher();
            AdminControllerTeacherVM teacherModel      = new AdminControllerTeacherVM();
            List <SelectListItem>    SelectListTitle   = new List <SelectListItem>();
            SelectListItem           select            = null;
            Title title = new Title();

            teacher.Title = title;

            if (id > 0)
            {
                teacher = teacherRepository.GetById(id);
                select  = new SelectListItem()
                {
                    Text = teacher.Title.Name, Value = teacher.Title.Id.ToString()
                };
                SelectListTitle.Add(select);
            }

            teacherModel.TitleList = titleRepository.GetAll();
            foreach (var item in teacherModel.TitleList)
            {
                if (item.Id != teacher.Title.Id)
                {
                    select = new SelectListItem()
                    {
                        Text = item.Name, Value = item.Id.ToString()
                    };
                    SelectListTitle.Add(select);
                }
            }

            if (id > 0)
            {
                teacher = teacherRepository.GetById(id);
                teacherModel.FirstName = teacher.FirstName;
                teacherModel.LastName  = teacher.LastName;
                teacherModel.UserName  = teacher.UserName;
                teacherModel.Password  = teacher.Password;
                teacherModel.isActive  = teacher.IsActive;
                teacherModel.Id        = id;
            }

            if (id == 0)
            {
                teacher.FirstName = teacherModel.FirstName;
                teacher.LastName  = teacherModel.LastName;
                teacher.UserName  = teacherModel.UserName;
                teacher.Password  = teacherModel.Password;
                teacher.IsActive  = teacherModel.isActive;
            }
            teacherModel.ListItems = SelectListTitle;
            return(View(teacherModel));
        }
예제 #4
0
        public void GetAll_Test()
        {
            // Arrange
            TestKolgraphEntities context = new TestKolgraphEntities();
            var repository = new TitleRepository(context);

            // Act
            IEnumerable <title> result = repository.GetAll();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(context.title.Count(), result.Count());
        }
예제 #5
0
        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));
        }
예제 #6
0
 public List <Title> GetAll()
 {
     return(TR.GetAll().ToList());
 }
 public ActionResult ManageTitles()
 {
     TitleRepository titleRepository = new TitleRepository();
     AdminControllerTitleVM titleModel = new AdminControllerTitleVM();
     titleModel.titleList = titleRepository.GetAll();
     return View(titleModel);
 }
 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 EditTitles(int id, AdminControllerTitleVM titleModel)
 {
     TryUpdateModel(titleModel);
     if (ModelState.IsValid)
     {
         Title title = null;
         TitleRepository titleRepository = new TitleRepository();
         if (id > 0)
         {
             title = titleRepository.GetById(id);
             title.Name = titleModel.Title;
             titleRepository.Save(title);
             return RedirectToAction("ManageTitles");
         }
         else
         {
             title = titleRepository.GetAll(filter: t => t.Name == titleModel.Title).FirstOrDefault();
             if (title == null)
             {
                 title = new Title();
                 title.Name = titleModel.Title;
                 titleRepository.Save(title);
                 return RedirectToAction("ManageTitles");
             }
             else
             {
                 throw new ArgumentException("Invalid Title");
             }
         }
     }
     return View(titleModel);
 }
        public ActionResult EditTeachers(int id, AdminControllerTeacherVM teacherModel)
        {
            UnitOfWork uOw = new UnitOfWork();
            Teacher teacher = null;
            Title title = new Title();
            TitleRepository titleRepository = new TitleRepository(uOw);
            TeacherRepository teacherRepository = new TeacherRepository(uOw);

            TryUpdateModel(teacherModel);
            if (teacherModel.ListItems == null)
            {
                teacherModel.TitleList = titleRepository.GetAll();
                List<SelectListItem> SelectListTitle = new List<SelectListItem>();

                foreach (var item in teacherModel.TitleList)
                {
                    SelectListTitle.Add(new SelectListItem() { Text = item.Name, Value = item.Id.ToString() });
                }
                teacherModel.ListItems = SelectListTitle;
            }

            if (ModelState.IsValid)
            {
                if (id > 0)
                {
                    teacher = teacherRepository.GetById(id);
                    teacher.FirstName = teacherModel.FirstName;
                    teacher.LastName = teacherModel.LastName;
                    teacher.UserName = teacherModel.UserName;
                    teacher.Password = teacherModel.Password;
                    title = titleRepository.GetById(teacherModel.TitleID);
                    teacher.Title = title;
                    teacher.IsActive = teacherModel.isActive;
                    teacherRepository.Save(teacher);
                    uOw.Commit();
                    return RedirectToAction("ManageTeachers");
                }
                else
                {
                    teacher = teacherRepository.GetAll(filter: t => t.UserName == teacherModel.UserName).FirstOrDefault();
                    if (teacher == null)
                    {
                        teacher = new Teacher();
                        teacher.FirstName = teacherModel.FirstName;
                        teacher.LastName = teacherModel.LastName;
                        teacher.UserName = teacherModel.UserName;
                        teacher.Password = SecurityService.CreateHash(teacherModel.Password);
                        title = titleRepository.GetById(teacherModel.TitleID);
                        teacher.Title = title;
                        teacher.IsActive = teacherModel.isActive;
                        teacherRepository.Save(teacher);
                        uOw.Commit();
                        return RedirectToAction("ManageTeachers");
                    }
                    else
                    {
                        throw new ArgumentException("Invalid username !");
                    }
                }
            }
            return View(teacherModel);
        }
        public ActionResult EditTeachers(int id)
        {
            TeacherRepository teacherRepository = new TeacherRepository();
            TitleRepository titleRepository = new TitleRepository();
            Teacher teacher = new Teacher();
            AdminControllerTeacherVM teacherModel = new AdminControllerTeacherVM();
            List<SelectListItem> SelectListTitle = new List<SelectListItem>();
            SelectListItem select = null;
            Title title = new Title();
            teacher.Title = title;

            if (id > 0)
            {
                teacher = teacherRepository.GetById(id);
                select = new SelectListItem() { Text = teacher.Title.Name, Value = teacher.Title.Id.ToString() };
                SelectListTitle.Add(select);
            }

            teacherModel.TitleList = titleRepository.GetAll();
            foreach (var item in teacherModel.TitleList)
            {
                if (item.Id != teacher.Title.Id)
                {
                    select = new SelectListItem() { Text = item.Name, Value = item.Id.ToString() };
                    SelectListTitle.Add(select);
                }
            }

            if (id > 0)
            {
                teacher = teacherRepository.GetById(id);
                teacherModel.FirstName = teacher.FirstName;
                teacherModel.LastName = teacher.LastName;
                teacherModel.UserName = teacher.UserName;
                teacherModel.Password = teacher.Password;
                teacherModel.isActive = teacher.IsActive;
                teacherModel.Id = id;
            }

            if (id == 0)
            {
                teacher.FirstName = teacherModel.FirstName;
                teacher.LastName = teacherModel.LastName;
                teacher.UserName = teacherModel.UserName;
                teacher.Password = teacherModel.Password;
                teacher.IsActive = teacherModel.isActive;
            }
            teacherModel.ListItems = SelectListTitle;
            return View(teacherModel);
        }
        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 List<SelectListItem> TeacherTitle()
        {
            TitleRepository titleRepo = new TitleRepository();
            List<SelectListItem> list = new List<SelectListItem>();

            var title = titleRepo.GetAll();

            foreach (var item in title)
            {
                list.Add(new SelectListItem() { Text = item.Name, Value = item.ID.ToString() });
            }
            return list;
        }
        public ActionResult EditTeacher(int id)
        {
            TeacherEditTeacherVM model = new TeacherEditTeacherVM();
            TitleRepository titleRepo = new TitleRepository();
            List<SelectListItem> list = new List<SelectListItem>();
            UserRepository<Teacher> teacherRepo = new UserRepository<Teacher>();

            Teacher teacher = teacherRepo.GetByID(id);

            var teacherTitle = titleRepo.GetByID(teacher.Title.ID);

            list.Add(new SelectListItem() { Text = teacherTitle.Name, Value = teacherTitle.ID.ToString() });
            var title = titleRepo.GetAll();

            foreach (var item in title)
            {
                if (item.ID != teacher.Title.ID)
                {
                    list.Add(new SelectListItem() { Text = item.Name, Value = item.ID.ToString() });
                }

            }
            model.FirstName = teacher.FirstName;
            model.LastName = teacher.LastName;
            model.Active = teacher.Active;
            model.TeacherID = teacher.ID;
            model.TitleList = list;

            return View(model);
        }
예제 #15
0
        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));
        }
예제 #16
0
        public ActionResult EditTeachers(int id, AdminControllerTeacherVM teacherModel)
        {
            UnitOfWork        uOw               = new UnitOfWork();
            Teacher           teacher           = null;
            Title             title             = new Title();
            TitleRepository   titleRepository   = new TitleRepository(uOw);
            TeacherRepository teacherRepository = new TeacherRepository(uOw);

            TryUpdateModel(teacherModel);
            if (teacherModel.ListItems == null)
            {
                teacherModel.TitleList = titleRepository.GetAll();
                List <SelectListItem> SelectListTitle = new List <SelectListItem>();

                foreach (var item in teacherModel.TitleList)
                {
                    SelectListTitle.Add(new SelectListItem()
                    {
                        Text = item.Name, Value = item.Id.ToString()
                    });
                }
                teacherModel.ListItems = SelectListTitle;
            }

            if (ModelState.IsValid)
            {
                if (id > 0)
                {
                    teacher           = teacherRepository.GetById(id);
                    teacher.FirstName = teacherModel.FirstName;
                    teacher.LastName  = teacherModel.LastName;
                    teacher.UserName  = teacherModel.UserName;
                    teacher.Password  = teacherModel.Password;
                    title             = titleRepository.GetById(teacherModel.TitleID);
                    teacher.Title     = title;
                    teacher.IsActive  = teacherModel.isActive;
                    teacherRepository.Save(teacher);
                    uOw.Commit();
                    return(RedirectToAction("ManageTeachers"));
                }
                else
                {
                    teacher = teacherRepository.GetAll(filter: t => t.UserName == teacherModel.UserName).FirstOrDefault();
                    if (teacher == null)
                    {
                        teacher           = new Teacher();
                        teacher.FirstName = teacherModel.FirstName;
                        teacher.LastName  = teacherModel.LastName;
                        teacher.UserName  = teacherModel.UserName;
                        teacher.Password  = SecurityService.CreateHash(teacherModel.Password);
                        title             = titleRepository.GetById(teacherModel.TitleID);
                        teacher.Title     = title;
                        teacher.IsActive  = teacherModel.isActive;
                        teacherRepository.Save(teacher);
                        uOw.Commit();
                        return(RedirectToAction("ManageTeachers"));
                    }
                    else
                    {
                        throw new ArgumentException("Invalid username !");
                    }
                }
            }
            return(View(teacherModel));
        }