예제 #1
0
        // GET: /Students/
        public ActionResult Index()
        {
            try
            {
                dbTIREntities  db                = new dbTIREntities();
                SiteUser       siteUser          = ((SiteUser)Session["SiteUser"]);
                StudentService studentService    = new StudentService(siteUser, db);
                SchoolService  schoolService     = new SchoolService(siteUser, db);
                ModelServices  modelService      = new ModelServices();
                string         currentSchoolYear = schoolService.GetCurrentSchoolYear();
                ViewBag.DistrictDesc = siteUser.Districts[0].Name;
                int schoolYearId = modelService.SchoolYearId();
                ViewBag.SchoolId  = modelService.DropDownDataSchool("", siteUser.EdsUserId, schoolYearId, true);
                ViewBag.AllowEdit = HelperService.AllowUiEdits(siteUser.RoleDesc, "STUDENT");
                //ViewBag.SchoolYear = HelperService.SchoolYearDescription(db);
                ViewBag.SchoolYearList = schoolService.DropDownDataSchoolYear(currentSchoolYear);
                ViewBag.AllowEdit      = HelperService.AllowUiEdits(siteUser.RoleDesc, "STUDENT");
                ViewBag.SchoolYear     = currentSchoolYear;

                return(View(new SiteModels()
                {
                    Students = studentService.GetViewData(currentSchoolYear, "", "")
                }));
            }
            catch (Exception ex)
            {
                Logging log = new Logging();
                log.LogException(ex);
                return(View("GeneralError"));
            }
        }
예제 #2
0
        public ActionResult Search(string searchStudent, string hiddenDistrictFilterSearch, string hiddenSchoolFilterSearch, string hiddenSchoolYearFilterSearch)
        {
            try
            {
                dbTIREntities  db             = new dbTIREntities();
                SiteUser       siteUser       = ((SiteUser)Session["SiteUser"]);
                StudentService studentService = new StudentService(siteUser, db);
                SchoolService  schoolService  = new SchoolService(siteUser, db);
                ModelServices  modelService   = new ModelServices();

                ViewBag.DistrictDesc = siteUser.Districts[0].Name;
                int schoolYearId = modelService.GetSchoolYearId(Convert.ToInt32(hiddenSchoolYearFilterSearch));
                ViewBag.SchoolId       = modelService.DropDownDataSchool(hiddenSchoolFilterSearch, siteUser.EdsUserId, schoolYearId, true);
                ViewBag.AllowEdit      = HelperService.AllowUiEdits(siteUser.RoleDesc, "STUDENT");
                ViewBag.SchoolYearList = schoolService.DropDownDataSchoolYear(hiddenSchoolYearFilterSearch);

                ViewBag.SchoolYear = hiddenSchoolYearFilterSearch;

                return(View("Index", new SiteModels()
                {
                    Students = studentService.GetViewData(hiddenSchoolYearFilterSearch, hiddenSchoolFilterSearch, searchStudent)
                }));
            }
            catch (Exception ex)
            {
                Logging log = new Logging();
                log.LogException(ex);
                return(View("GeneralError"));
            }
        }
예제 #3
0
        public void PopulateViewData(StudentExt studentExt)
        {
            dbTIREntities  db             = new dbTIREntities();
            SiteUser       siteUser       = ((SiteUser)Session["SiteUser"]);
            StudentService studentService = new StudentService(siteUser, db);
            ModelServices  modelService   = new ModelServices();

            studentExt.DistrictId     = siteUser.Districts[0].Id;
            studentExt.DistrictDesc   = siteUser.Districts[0].Name;
            studentExt.StudentClasses = studentExt.StudentId != 0 ? modelService.GetClassesByStudent(studentExt.StudentId, studentExt.SchoolYear) : null;
            studentExt.SchoolYears    = studentExt.StudentId != 0 ? modelService.GetSchoolYearByStudent(studentExt.StudentId) : null;

            studentExt.DropDown = new DropDownData();
            int schoolYearId = modelService.GetSchoolYearId(studentExt.SchoolYear);

            studentExt.DropDown.School = new SchoolDropDown(modelService.GetSchoolDropDownData(siteUser.EdsUserId, schoolYearId), false);
            studentExt.DropDown.School.SelectedSchool = studentExt.ServingSchoolId;
            studentExt.DropDown.Grade = new GradeDropDown(studentService.DropDownDataForGrade());
            studentExt.DropDown.Grade.SelectedGrade = (studentExt.GradeLevel != null) ? (int)studentExt.GradeLevel : -1;
            studentExt.DropDown.Gender = new GenderDropDown(modelService.DropDownDataForGender());
            studentExt.DropDown.Gender.SelectedGender = (studentExt.GenderId != null) ? (int)studentExt.GenderId : 1;
            studentExt.DropDown.Lineage = new LineageDropDown(studentService.DropDownDataForLineage());
            studentExt.DropDown.Lineage.SelectedLineage         = (studentExt.LineageId != null) ? (int)studentExt.LineageId : -1;
            studentExt.DropDown.HomeLanguage                    = new LanguageDropDown(studentService.DropDownDataForLanguage());
            studentExt.DropDown.HomeLanguage.SelectedLanguage   = (studentExt.HomeLanguageId != null) ? (int)studentExt.HomeLanguageId : -1;
            studentExt.DropDown.NativeLanguage                  = new LanguageDropDown(studentService.DropDownDataForLanguage());
            studentExt.DropDown.NativeLanguage.SelectedLanguage = (studentExt.NativeLanguageId != null) ? (int)studentExt.NativeLanguageId : -1;
            studentExt.DropDown.Race = new RaceDropDown(modelService.DropDownDataForRace());
            studentExt.DropDown.Race.SelectedRace = (studentExt.RaceId != null) ? (int)studentExt.RaceId : -1;
            ViewBag.SchoolYear = studentExt.SchoolYear;
        }
        // GET: /Students/
        public ActionResult Index()
        {
            try
            {
                dbTIREntities db = new dbTIREntities();
                SiteUser siteUser = ((SiteUser)Session["SiteUser"]);
                StudentService studentService = new StudentService(siteUser, db);
                SchoolService schoolService = new SchoolService(siteUser, db);
                ModelServices modelService = new ModelServices();
                string currentSchoolYear = schoolService.GetCurrentSchoolYear();
                ViewBag.DistrictDesc = siteUser.Districts[0].Name;
                int schoolYearId = modelService.SchoolYearId();
                ViewBag.SchoolId = modelService.DropDownDataSchool("", siteUser.EdsUserId, schoolYearId, true);
                ViewBag.AllowEdit = HelperService.AllowUiEdits(siteUser.RoleDesc, "STUDENT");
                //ViewBag.SchoolYear = HelperService.SchoolYearDescription(db);
                ViewBag.SchoolYearList = schoolService.DropDownDataSchoolYear(currentSchoolYear);
                ViewBag.AllowEdit = HelperService.AllowUiEdits(siteUser.RoleDesc, "STUDENT");
                ViewBag.SchoolYear = currentSchoolYear;

                return View(new SiteModels()
                {
                    Students = studentService.GetViewData(currentSchoolYear, "", "")
                });
            }
            catch (Exception ex)
            {
                Logging log = new Logging();
                log.LogException(ex);
                return View("GeneralError");
            }
        }
예제 #5
0
        public TeachersController()
        {
            _db            = new dbTIREntities();
            _modelServices = new ModelServices();

            ViewBag.SchoolYear = _modelServices.SchoolYearDescription();
        }
예제 #6
0
 public ActionResult Create([Bind(Include = "ClassId,SchoolId,ClassDesc,SchoolYearId,SubjectId,Grade,CreateDatetime,ChangeDatetime")] tblClass tblclass)
 {
     try
     {
         var           db            = new dbTIREntities();
         SiteUser      su            = (SiteUser)Session["SiteUser"];
         SchoolService schoolService = new SchoolService(su, db);
         ModelServices modelService  = new ModelServices();
         if (ModelState.IsValid)
         {
             ClassService classService = new ClassService((SiteUser)Session["SiteUser"], db);
             if (!(classService.IsClassExists(tblclass)))
             {
                 classService.AddClass(newClass: tblclass);
                 return(RedirectToAction("Edit", new { id = tblclass.ClassId, defaultWizardStep = ClassWizardSteps.Teachers }));
             }
             else
             {
                 int defaultDistrict = su.Districts[0].Id;
                 ViewBag.DistrictDesc = su.Districts[0].Name;
                 ModelState.AddModelError("ClassDesc", "Duplicate class name - please choose a unique name.");
             }
         }
         ViewBag.SchoolId     = modelService.DropDownDataSchool("", su.EdsUserId, tblclass.SchoolYearId, false);
         ViewBag.SchoolYearId = modelService.GetUserSchoolYear(su.EdsUserId, su.Districts[0].Id, tblclass.SchoolYearId);
         ViewBag.SubjectId    = new SelectList(db.tblSubjects.OrderBy(x => x.SubjectDesc), "SubjectId", "SubjectDesc", tblclass.SubjectId);
         return(View(tblclass));
     }
     catch (Exception ex)
     {
         Logging log = new Logging();
         log.LogException(ex);
         return(View("GeneralError"));
     }
 }
예제 #7
0
 public ActionResult UpdateGrid(string hiddenSchoolFilter, string hiddenSchoolYearFilter)
 {
     try
     {
         dbTIREntities db            = new dbTIREntities();
         SiteUser      siteUser      = ((SiteUser)Session["SiteUser"]);
         ClassService  classService  = new ClassService(siteUser, db);
         SchoolService schoolService = new SchoolService(siteUser, db);
         ModelServices modelService  = new ModelServices();
         ViewBag.DistrictDesc = siteUser.Districts[0].Name;
         int schoolYearId = modelService.GetSchoolYearId(Convert.ToInt32(hiddenSchoolYearFilter));
         ViewBag.SchoolId   = modelService.DropDownDataSchool(hiddenSchoolFilter, siteUser.EdsUserId, schoolYearId, true);
         ViewBag.SchoolYear = schoolService.DropDownDataSchoolYear(hiddenSchoolYearFilter);
         ViewBag.AllowEdit  = HelperService.AllowUiEdits(siteUser.RoleDesc, "CLASS");
         return(View("Index", new SiteModels()
         {
             SchoolClasses = classService.GetViewData(hiddenSchoolYearFilter, hiddenSchoolFilter)
         }));
     }
     catch (Exception ex)
     {
         Logging log = new Logging();
         log.LogException(ex);
         return(View("GeneralError"));
     }
 }
        public ActionResult UpdateGrid(string hiddenSchoolFilter, string hiddenSchoolYearFilter)
        {
            try
            {
                dbTIREntities db = new dbTIREntities();
                SiteUser siteUser = ((SiteUser)Session["SiteUser"]);
                StudentService studentService = new StudentService(siteUser, db);
                SchoolService schoolService = new SchoolService(siteUser, db);
                ModelServices modelService = new ModelServices();
                ViewBag.DistrictDesc = siteUser.Districts[0].Name;
                int schoolYearId = modelService.GetSchoolYearId(Convert.ToInt32(hiddenSchoolYearFilter));
                ViewBag.SchoolId = modelService.DropDownDataSchool(hiddenSchoolFilter, siteUser.EdsUserId, schoolYearId, true);
                ViewBag.AllowEdit = HelperService.AllowUiEdits(siteUser.RoleDesc, "STUDENT");
                ViewBag.SchoolYearList = schoolService.DropDownDataSchoolYear(hiddenSchoolYearFilter);

                ViewBag.SchoolYear = hiddenSchoolYearFilter;

                return View("Index", new SiteModels()
                {
                    Students = studentService.GetViewData(hiddenSchoolYearFilter, hiddenSchoolFilter)
                });
            }
            catch (Exception ex)
            {
                Logging log = new Logging();
                log.LogException(ex);
                return View("GeneralError");
            }
        }
예제 #9
0
 public ActionResult Edit([Bind(Include = "ClassId,SchoolId,ClassDesc,SchoolYearId,SubjectId,Grade")] tblClass tblclass)
 {
     try
     {
         var           db            = new dbTIREntities();
         SiteUser      siteUser      = (SiteUser)Session["SiteUser"];
         SchoolService schoolService = new SchoolService(siteUser, db);
         ModelServices modelService  = new ModelServices();
         if (ModelState.IsValid)
         {
             ClassService classService = new ClassService((SiteUser)Session["SiteUser"], db);
             if (!(classService.IsEditClassExists(tblclass)))
             {
                 classService.EditClass(editClass: tblclass);
                 return(RedirectToAction("Edit", new { id = tblclass.ClassId, defaultWizardStep = ClassWizardSteps.Teachers }));
             }
             else
             {
                 PopulateViewData(tblclass, null, null, null);
                 ModelState.AddModelError("ClassDesc", "Duplicate class name - please choose a unique name.");
                 return(View(tblclass));
             }
         }
         ViewBag.SchoolYearId = modelService.GetUserSchoolYear(siteUser.EdsUserId, siteUser.Districts[0].Id, tblclass.SchoolYearId);
         ViewBag.SchoolId     = modelService.DropDownDataSchool(tblclass.SchoolId.ToString(), siteUser.EdsUserId, tblclass.SchoolYearId, true);
         ViewBag.SubjectId    = new SelectList(db.tblSubjects, "SubjectId", "SubjectDesc", tblclass.SubjectId);
         return(View(tblclass));
     }
     catch (Exception ex)
     {
         Logging log = new Logging();
         log.LogException(ex);
         return(View("GeneralError"));
     }
 }
        public ActionResult Search(string searchClass, string hiddenSchoolFilterSearch, string hiddenSchoolYearFilterSearch)
        {
            try
            {
                dbTIREntities db = new dbTIREntities();

                SiteUser siteUser = ((SiteUser)Session["SiteUser"]);
                ClassService classService = new ClassService(siteUser, db);
                SchoolService schoolService = new SchoolService(siteUser, db);
                ModelServices modelService = new ModelServices();
                ViewBag.DistrictDesc = siteUser.Districts[0].Name;
                int schoolYearId = modelService.GetSchoolYearId(Convert.ToInt32(hiddenSchoolYearFilterSearch));
                ViewBag.SchoolId = modelService.DropDownDataSchool(hiddenSchoolFilterSearch, siteUser.EdsUserId, schoolYearId, true);
                ViewBag.SchoolYear = schoolService.DropDownDataSchoolYear(hiddenSchoolYearFilterSearch);
                ViewBag.AllowEdit = HelperService.AllowUiEdits(siteUser.RoleDesc, "CLASS");
                return View("Index", new SiteModels()
                {
                    SchoolClasses = classService.GetViewData(hiddenSchoolYearFilterSearch, hiddenSchoolFilterSearch, searchClass)
                });
            }
            catch (Exception ex)
            {
                Logging log = new Logging();
                log.LogException(ex);
                return View("GeneralError");
            }
        }
        public TeachersController()
        {
            _db = new dbTIREntities();
            _modelServices = new ModelServices();

            ViewBag.SchoolYear = _modelServices.SchoolYearDescription();
        }
예제 #12
0
        private void PopulateViewData(tblClass tblclass, ClassWizardSteps?defaultWizardStep, bool?showTeachersForDistrict, bool?showStudentsForDistrict)
        {
            ViewBag.DefaultWizardStep       = defaultWizardStep;
            ViewBag.ShowTeachersForDistrict = !showTeachersForDistrict.GetValueOrDefault();
            ViewBag.ShowStudentsForDistrict = !showStudentsForDistrict.GetValueOrDefault();

            var           db            = new dbTIREntities();
            SiteUser      siteUser      = (SiteUser)Session["SiteUser"];
            SchoolService schoolService = new SchoolService(siteUser, db);
            ClassService  classService  = new ClassService(siteUser, db);
            ModelServices modelService  = new ModelServices();

            int  userAssignedDistrict     = siteUser.Districts[0].Id;
            bool filterTeachersByDistrict = showTeachersForDistrict.GetValueOrDefault();
            int  districtId = userAssignedDistrict;
            // Get teachers for this class
            var teachersForThisClass = classService.GetTeachersForThisClass(tblclass);

            // Get teachers not in this class
            var teachersNotForThisClass = classService.GetTeachersNotForThisClass(tblclass, filterTeachersByDistrict, districtId);

            //Get students for this class
            var studentsForThisClass = classService.GetStudentForThisClass(tblclass);

            // Get students not for this class
            var availableStudents = classService.GetStudentNotForThisClass(tblclass, districtId);

            var availableStudentsForSchool = classService.GetStudentForSchool(tblclass, districtId);

            // Add data to ViewBag for form
            ViewBag.TeachersForThisClass = new MultiSelectList(teachersForThisClass, "TeacherId", "FullName", null);
            ViewBag.AvailableTeachers    = new MultiSelectList(teachersNotForThisClass, "TeacherId", "FullName", null);
            if (showStudentsForDistrict.GetValueOrDefault())
            {
                ViewBag.AvailableStudents = new MultiSelectList(availableStudents, "StudentId", "FullName", null);
            }
            else
            {
                ViewBag.AvailableStudents = new MultiSelectList(availableStudentsForSchool, "StudentId", "FullName", null);
            }
            ViewBag.StudentsForThisClass      = new MultiSelectList(studentsForThisClass, "StudentId", "FullName", null);
            ViewBag.StudentsForThisClassCount = studentsForThisClass.Count();
            ViewBag.SchoolId     = modelService.DropDownDataSchool(Convert.ToString(tblclass.SchoolId), siteUser.EdsUserId, tblclass.SchoolYearId, false);
            ViewBag.SchoolYearId = modelService.GetUserSchoolYear(siteUser.EdsUserId, siteUser.Districts[0].Id, tblclass.SchoolYearId);
            ViewBag.ClassDesc    = db.tblClasses.Where(x => x.ClassId == tblclass.ClassId).Select(x => x.ClassDesc).SingleOrDefault();
            ViewBag.SubjectId    = new SelectList(db.tblSubjects.OrderBy(x => x.SubjectDesc), "SubjectId", "SubjectDesc", tblclass.SubjectId);
            ViewBag.AllowEdit    = HelperService.AllowUiEdits(siteUser.RoleDesc, "CLASS");
        }
예제 #13
0
        public ActionResult Edit([Bind(Include = "StudentId,StudentSchoolYearId,SchoolYearId,DistrictId,FirstName,MiddleName,LastName,BirthDate,Hispanic,StateId,LocalId,EnrollmentDate,IepIndicator,LepIndicator,FrlIndicator,")] StudentExt studentExt, int hdSchoolId, int?hdLineageId, int hdGradeId, int hdGenderId, int?hdRaceId, int?hdHomeLanguageId, int?hdNativeLanguageId, int schoolYear)
        {
            try
            {
                dbTIREntities  db             = new dbTIREntities();
                SiteUser       siteUser       = ((SiteUser)Session["SiteUser"]);
                StudentService studentService = new StudentService(siteUser, db);
                ViewBag.AllowEdit = HelperService.AllowUiEdits(siteUser.RoleDesc, "STUDENT");
                if (ModelState.IsValid)
                {
                    studentExt.ServingSchoolId  = hdSchoolId;
                    studentExt.LineageId        = hdLineageId;
                    studentExt.NativeLanguageId = hdNativeLanguageId;
                    studentExt.HomeLanguageId   = hdHomeLanguageId;
                    studentExt.RaceId           = hdRaceId;
                    studentExt.GradeLevel       = (short)hdGradeId;
                    studentExt.GenderId         = hdGenderId;
                    studentExt.SchoolYear       = schoolYear;
                    if (studentService.IsStudentExist(studentExt.StateId, null, studentExt.StudentId))
                    {
                        PopulateViewData(studentExt);
                        ModelState.AddModelError("StateId", "State Id already exists");
                        return(View(studentExt));
                    }
                    else if (studentService.IsStudentExist(null, studentExt.LocalId, studentExt.StudentId))
                    {
                        PopulateViewData(studentExt);
                        ModelState.AddModelError("LocalId", "Local Id already exists");
                        return(View(studentExt));
                    }
                    else
                    {
                        studentService.SaveStudents(studentExt);
                    }
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                Logging log = new Logging();
                log.LogException(ex);
                return(View("GeneralError"));
            }
        }
예제 #14
0
 public ActionResult Create(int schoolYear)
 {
     try
     {
         dbTIREntities db           = new dbTIREntities();
         StudentExt    studentExt   = new StudentExt();
         ModelServices modelService = new ModelServices();
         studentExt.SchoolYear = schoolYear;
         PopulateViewData(studentExt);
         studentExt.SchoolYearDesc = HelperService.SchoolYearDescription(db);
         studentExt.SchoolYearId   = modelService.SchoolYearId();
         return(View(studentExt));
     }
     catch (Exception ex)
     {
         Logging log = new Logging();
         log.LogException(ex);
         return(View("GeneralError"));
     }
 }
 public ActionResult UpdateGrid(string hiddenSchoolFilter, string schoolYearFilter)
 {
     try
     {
         db = new dbTIREntities();
         siteUser = ((SiteUser)Session["SiteUser"]);
         userService = new UserService(siteUser, db);
         schoolService = new SchoolService(siteUser, db);
         modelService = new ModelServices();
         ViewBag.SchoolYearList = schoolService.DropDownDataSchoolYear(schoolYearFilter);
         int schoolYearId = modelService.GetSchoolYearId(Convert.ToInt32(schoolYearFilter));
         FillViewBagValues(siteUser.Districts[0].Name, hiddenSchoolFilter, siteUser.RoleDesc, schoolYearId);
         return View("Index", userService.GetViewData(schoolYearFilter, hiddenSchoolFilter, ""));
     }
     catch (Exception ex)
     {
         Logging log = new Logging();
         log.LogException(ex);
         return View("GeneralError");
     }
 }
예제 #16
0
        public ActionResult Edit(int studentId, int schoolYear)
        {
            try
            {
                dbTIREntities  db             = new dbTIREntities();
                SiteUser       siteUser       = ((SiteUser)Session["SiteUser"]);
                StudentService studentService = new StudentService(siteUser, db);
                ModelServices  modelService   = new ModelServices();

                StudentExt studentExt = studentService.GetStudentDetail(studentId, schoolYear);
                PopulateViewData(studentExt);
                ViewBag.AllowEdit = HelperService.AllowUiEdits(siteUser.RoleDesc, "STUDENT");
                return(View(studentExt));
            }
            catch (Exception ex)
            {
                Logging log = new Logging();
                log.LogException(ex);
                return(View("GeneralError"));
            }
        }
예제 #17
0
 // GET: /Classes/Create
 public ActionResult Create()
 {
     try
     {
         SiteUser      siteUser        = (SiteUser)Session["SiteUser"];
         var           db              = new dbTIREntities();
         SchoolService schoolService   = new SchoolService(siteUser, db);
         ModelServices modelService    = new ModelServices();
         int           defaultDistrict = siteUser.Districts[0].Id;
         ViewBag.DistrictDesc = siteUser.Districts[0].Name;
         int schoolYearId = modelService.SchoolYearId();
         ViewBag.SchoolId     = modelService.DropDownDataSchool("", siteUser.EdsUserId, schoolYearId, false);
         ViewBag.SchoolYearId = modelService.GetUserSchoolYear(siteUser.EdsUserId, defaultDistrict, schoolYearId);
         ViewBag.SubjectId    = new SelectList(db.tblSubjects.OrderBy(x => x.SubjectDesc), "SubjectId", "SubjectDesc");
         return(View());
     }
     catch (Exception ex)
     {
         Logging log = new Logging();
         log.LogException(ex);
         return(View("GeneralError"));
     }
 }
 public ActionResult Index()
 {
     try
     {
         db = new dbTIREntities();
         siteUser = ((SiteUser)Session["SiteUser"]);
         userService = new UserService(siteUser, db);
         schoolService = new SchoolService(siteUser, db);
         modelService = new ModelServices();
         int schoolYearId = modelService.SchoolYearId();
         string currentSchoolYear = schoolService.GetCurrentSchoolYear();
         ViewBag.SchoolYearList = schoolService.DropDownDataSchoolYear(currentSchoolYear);
         FillViewBagValues(siteUser.Districts[0].Name, string.Empty, siteUser.RoleDesc, schoolYearId);
         return View(userService.GetViewData(currentSchoolYear, "", ""));
     }
     catch (Exception ex)
     {
         Logging log = new Logging();
         log.LogException(ex);
         return View("GeneralError");
         //throw;
     }
 }
예제 #19
0
 // GET: /Classes/Edit/5
 public ActionResult Edit(int?id, ClassWizardSteps?defaultWizardStep, bool?showTeachersForDistrict, bool?showStudentsForDistrict)
 {
     try
     {
         if (id == null)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
         }
         var      db       = new dbTIREntities();
         tblClass tblclass = db.tblClasses.Find(id);
         if (tblclass == null)
         {
             return(HttpNotFound());
         }
         PopulateViewData(tblclass, defaultWizardStep, showTeachersForDistrict, showStudentsForDistrict);
         return(View(tblclass));
     }
     catch (Exception ex)
     {
         Logging log = new Logging();
         log.LogException(ex);
         return(View("GeneralError"));
     }
 }
        public ActionResult Edit(tblUserExt tblUserExtended)
        {
            try
            {
                db = new dbTIREntities();
                modelService = new ModelServices();
                siteUser = ((SiteUser)Session["SiteUser"]);
                userService = new UserService(siteUser, db);
                schoolService = new SchoolService(siteUser, db);
                int userAssignedDistrict = siteUser.Districts[0].Id;

                if (ModelState.IsValid)
                {
                    if (tblUserExtended.SelectedSchools != null && tblUserExtended.SelectedSchools.Count() > 0)
                    {
                        bool isEmailAddressExist = db.tblUsers.Where(x => x.UserEmail == tblUserExtended.UserEmail && x.UserId != tblUserExtended.UserId).Count() > 0 ? true : false;
                        bool isStateIdExist = db.tblUsers.Where(x => x.StateId == tblUserExtended.StateId && x.UserId != tblUserExtended.UserId).Count() > 0 ? true : false;

                        if ((!isEmailAddressExist) && (!isStateIdExist))
                        {
                            userService.UpdateUser(tblUserExtended);
                            HelperService.UpdateSiteUserProfile(siteUser, db);
                            return RedirectToAction("Index");
                        }
                        else
                        {
                            if (isEmailAddressExist)
                                ModelState.AddModelError("UserEmail", "Duplicate email - please choose a unique email.");
                            if (isStateIdExist)
                                ModelState.AddModelError("StateId", "Duplicate state id - please choose a unique state.");
                        }
                    }
                    else
                    {
                        ViewBag.SchoolMessage = "Required";
                    }
                }
                tblUserExtended.Schools = userService.GetSelectedSchoolCheckBoxes(tblUserExtended);
                FillViewBagValues(siteUser.Districts[0].Name, string.Empty, siteUser.RoleDesc, tblUserExtended.SchoolYearId);
                FillUserExtendedCommanData(modelService, tblUserExtended);
                return View(tblUserExtended);
            }
            catch (Exception ex)
            {
                Logging log = new Logging();
                log.LogException(ex);
                return View("GeneralError");
            }
        }
        public ActionResult Edit(int? id, int schoolYearId)
        {

            try
            {
                db = new dbTIREntities();
                modelService = new ModelServices();
                siteUser = ((SiteUser)Session["SiteUser"]);
                schoolService = new SchoolService(siteUser, db);
                userService = new UserService(siteUser, db);
                //tblUserExt tbluserExtended = null;
                if (id == null)
                {
                    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                }

                tblUser tbluser = db.tblUsers.Find(id);

                if (tbluser == null)
                {
                    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                }

                var context = new Models.ApplicationDbContext();
                var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));

                string aspNetUserName = "******";
                if (!String.IsNullOrEmpty(tbluser.AspNetUserId))
                {
                    ApplicationUser aspNetUser = userManager.FindById(tbluser.AspNetUserId);
                    if (aspNetUser != null)
                    {
                        aspNetUserName = aspNetUser.UserName;
                    }
                }
                //Get RoleId from tblUserDistrict instead of tblUser
                int roleId = userService.GetRoleId(id, schoolYearId);
                tblUserExt tbluserExtended = new tblUserExt()
                {
                    UserId = tbluser.UserId,
                    UserName = aspNetUserName,
                    FirstName = tbluser.FirstName,
                    LastName = tbluser.LastName,
                    UserEmail = tbluser.UserEmail,
                    StateId = tbluser.StateId,
                    Schools = tbluser.Schools,
                    SchoolYearId = schoolYearId,
                    RoleId = roleId
                };

                //Check that edited user's school must be from EDSUser schools or edsUser must have permissions to view user school
                bool isUserHasPermissionForSchool = userService.IsUserHasPermissionForSchool(tbluserExtended);
                if (!isUserHasPermissionForSchool)
                {
                    return RedirectToAction("Index");
                }

                //Get User schools
                tbluserExtended.Schools = userService.GetUserSchoolWithCheckBoxes(tbluserExtended);
                var dropDownEmpty = Enumerable.Repeat(new SelectListItem { Value = "", Text = "" }, count: 1);
                FillViewBagValues(siteUser.Districts[0].Name, string.Empty, siteUser.RoleDesc, schoolYearId);
                FillUserExtendedCommanData(modelService, tbluserExtended);
                return View(tbluserExtended);
            }
            catch (Exception ex)
            {
                Logging log = new Logging();
                log.LogException(ex);
                return View("GeneralError");
            }
        }
        public async Task<ActionResult> Create(tblUserExt tblUserExtended)
        {
            try
            {
                db = new dbTIREntities();
                modelService = new ModelServices();
                siteUser = ((SiteUser)Session["SiteUser"]);
                userService = new UserService(siteUser, db);
                schoolService = new SchoolService(siteUser, db);

                int userAssignedDistrict = siteUser.Districts[0].Id;
                string currentSchoolYear = schoolService.GetCurrentSchoolYear();

                if (ModelState.IsValid)
                {
                    if (tblUserExtended.SelectedSchools != null && tblUserExtended.SelectedSchools.Count() > 0)
                    {
                        var context = new Models.ApplicationDbContext();
                        var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));

                        // 1. Create ASPNET user
                        string userName = tblUserExtended.UserName;
                        string password = tblUserExtended.Password;

                        var isPasswordValid = password != null && password.Length >= 6 ? true : false;
                        var isUserNameExist = userManager.FindByName(userName);
                        bool isEmailAddressExist = db.tblUsers.Where(x => x.UserEmail == tblUserExtended.UserEmail).Count() > 0 ? true : false;
                        bool isStateIdExist = db.tblUsers.Where(x => x.StateId == tblUserExtended.StateId).Count() > 0 ? true : false;

                        if ((isUserNameExist == null) && (!isEmailAddressExist) && (!isStateIdExist) && (isPasswordValid))
                        {
                            var user = new ApplicationUser() { UserName = userName };
                            var result = await userManager.CreateAsync(user, password);
                            if (result.Succeeded)
                            {
                                // 2. Create EDS user
                                ApplicationUser newAspNetUser = userManager.FindByName(userName);
                                if (newAspNetUser != null)
                                {
                                    userService.CreateEdsUser(newAspNetUser.Id, tblUserExtended);
                                }
                            }
                            else
                            {
                                throw new Exception(String.Format("ERROR: {0}", result.Errors));
                            }
                            return RedirectToAction("Index");
                        }
                        else
                        {
                            if (isUserNameExist != null)
                                ModelState.AddModelError("UserName", "Duplicate name - please choose a unique name.");
                            if (isEmailAddressExist)
                                ModelState.AddModelError("UserEmail", "Duplicate email - please choose a unique email.");
                            if (isStateIdExist)
                                ModelState.AddModelError("StateId", "Duplicate state id - please choose a unique state.");
                            if (!isPasswordValid)
                                ModelState.AddModelError("Password", "Please enter password at least 6 characters.");
                        }
                    }
                    else
                    {
                        ViewBag.SchoolMessage = "Required";
                    }
                }

                tblUserExtended.Schools = userService.GetSelectedSchoolCheckBoxes(tblUserExtended);
                ViewBag.RoleId = new SelectList(modelService.GetRolesForRole((int)(siteUser.Role)), "RoleId", "RoleDesc", tblUserExtended.RoleId);
                FillViewBagValues(siteUser.Districts[0].Name, string.Empty, siteUser.RoleDesc, tblUserExtended.SchoolYearId);
                return View(tblUserExtended);
            }
            catch (Exception ex)
            {
                Logging log = new Logging();
                log.LogException(ex);
                return View("GeneralError");
            }
        }
        // GET: /User/Create
        public ActionResult Create()
        {
            try
            {
                db = new dbTIREntities();
                siteUser = ((SiteUser)Session["SiteUser"]);
                modelService = new ModelServices();
                schoolService = new SchoolService(siteUser, db);
                userService = new UserService(siteUser, db);

                int userAssignedDistrict = siteUser.Districts[0].Id;
                int schoolYearId = modelService.SchoolYearId();

                tblUserExt userExtended = new tblUserExt();
                userExtended.SchoolYearId = schoolYearId;
                userExtended.Schools = userService.GetSchoolWithCheckBoxes(userExtended);
                ViewBag.RoleId = new SelectList(modelService.GetRolesForRole((int)(siteUser.Role)), "RoleId", "RoleDesc");
                FillViewBagValues(siteUser.Districts[0].Name, string.Empty, siteUser.RoleDesc, schoolYearId);
                return View(userExtended);
            }
            catch (Exception ex)
            {
                Logging log = new Logging();
                log.LogException(ex);
                return View("GeneralError");
            }
        }
        public void PopulateViewData(StudentExt studentExt)
        {

            dbTIREntities db = new dbTIREntities();
            SiteUser siteUser = ((SiteUser)Session["SiteUser"]);
            StudentService studentService = new StudentService(siteUser, db);
            ModelServices modelService = new ModelServices();

            studentExt.DistrictId = siteUser.Districts[0].Id;
            studentExt.DistrictDesc = siteUser.Districts[0].Name;
            studentExt.StudentClasses = studentExt.StudentId != 0 ? modelService.GetClassesByStudent(studentExt.StudentId, studentExt.SchoolYear) : null;
            studentExt.SchoolYears = studentExt.StudentId != 0 ? modelService.GetSchoolYearByStudent(studentExt.StudentId) : null;

            studentExt.DropDown = new DropDownData();
            int schoolYearId = modelService.GetSchoolYearId(studentExt.SchoolYear);
            studentExt.DropDown.School = new SchoolDropDown(modelService.GetSchoolDropDownData(siteUser.EdsUserId, schoolYearId), false);
            studentExt.DropDown.School.SelectedSchool = studentExt.ServingSchoolId;
            studentExt.DropDown.Grade = new GradeDropDown(studentService.DropDownDataForGrade());
            studentExt.DropDown.Grade.SelectedGrade = (studentExt.GradeLevel != null) ? (int)studentExt.GradeLevel : -1;
            studentExt.DropDown.Gender = new GenderDropDown(modelService.DropDownDataForGender());
            studentExt.DropDown.Gender.SelectedGender = (studentExt.GenderId != null) ? (int)studentExt.GenderId : 1;
            studentExt.DropDown.Lineage = new LineageDropDown(studentService.DropDownDataForLineage());
            studentExt.DropDown.Lineage.SelectedLineage = (studentExt.LineageId != null) ? (int)studentExt.LineageId : -1;
            studentExt.DropDown.HomeLanguage = new LanguageDropDown(studentService.DropDownDataForLanguage());
            studentExt.DropDown.HomeLanguage.SelectedLanguage = (studentExt.HomeLanguageId != null) ? (int)studentExt.HomeLanguageId : -1;
            studentExt.DropDown.NativeLanguage = new LanguageDropDown(studentService.DropDownDataForLanguage());
            studentExt.DropDown.NativeLanguage.SelectedLanguage = (studentExt.NativeLanguageId != null) ? (int)studentExt.NativeLanguageId : -1;
            studentExt.DropDown.Race = new RaceDropDown(modelService.DropDownDataForRace());
            studentExt.DropDown.Race.SelectedRace = (studentExt.RaceId != null) ? (int)studentExt.RaceId : -1;
            ViewBag.SchoolYear = studentExt.SchoolYear;
        }
        public ActionResult Edit(int studentId, int schoolYear)
        {
            try
            {
                dbTIREntities db = new dbTIREntities();
                SiteUser siteUser = ((SiteUser)Session["SiteUser"]);
                StudentService studentService = new StudentService(siteUser, db);
                ModelServices modelService = new ModelServices();

                StudentExt studentExt = studentService.GetStudentDetail(studentId, schoolYear);
                PopulateViewData(studentExt);
                ViewBag.AllowEdit = HelperService.AllowUiEdits(siteUser.RoleDesc, "STUDENT");
                return View(studentExt);
            }
            catch (Exception ex)
            {
                Logging log = new Logging();
                log.LogException(ex);
                return View("GeneralError");
            }
        }
        public ActionResult Create(int schoolYear)
        {
            try
            {
                dbTIREntities db = new dbTIREntities();
                StudentExt studentExt = new StudentExt();
                ModelServices modelService = new ModelServices();
                studentExt.SchoolYear = schoolYear;
                PopulateViewData(studentExt);
                studentExt.SchoolYearDesc = HelperService.SchoolYearDescription(db);
                studentExt.SchoolYearId = modelService.SchoolYearId();
                return View(studentExt);

            }
            catch (Exception ex)
            {
                Logging log = new Logging();
                log.LogException(ex);
                return View("GeneralError");
            }
        }
 public ActionResult Edit([Bind(Include = "ClassId,SchoolId,ClassDesc,SchoolYearId,SubjectId,Grade")] tblClass tblclass)
 {
     try
     {
         var db = new dbTIREntities();
         SiteUser siteUser = (SiteUser)Session["SiteUser"];
         SchoolService schoolService = new SchoolService(siteUser, db);
         ModelServices modelService = new ModelServices();
         if (ModelState.IsValid)
         {
             ClassService classService = new ClassService((SiteUser)Session["SiteUser"], db);
             if (!(classService.IsEditClassExists(tblclass)))
             {
                 classService.EditClass(editClass: tblclass);
                 return RedirectToAction("Edit", new { id = tblclass.ClassId, defaultWizardStep = ClassWizardSteps.Teachers });
             }
             else
             {
                 PopulateViewData(tblclass, null, null, null);
                 ModelState.AddModelError("ClassDesc", "Duplicate class name - please choose a unique name.");
                 return View(tblclass);
             }
         }
         ViewBag.SchoolYearId = modelService.GetUserSchoolYear(siteUser.EdsUserId, siteUser.Districts[0].Id, tblclass.SchoolYearId); 
         ViewBag.SchoolId = modelService.DropDownDataSchool(tblclass.SchoolId.ToString(), siteUser.EdsUserId, tblclass.SchoolYearId, true);
         ViewBag.SubjectId = new SelectList(db.tblSubjects, "SubjectId", "SubjectDesc", tblclass.SubjectId);
         return View(tblclass);
     }
     catch (Exception ex)
     {
         Logging log = new Logging();
         log.LogException(ex);
         return View("GeneralError");
     }
 }
 // GET: /Classes/Create
 public ActionResult Create()
 {
     try
     {
         SiteUser siteUser = (SiteUser)Session["SiteUser"];
         var db = new dbTIREntities();
         SchoolService schoolService = new SchoolService(siteUser, db);
         ModelServices modelService = new ModelServices();
         int defaultDistrict = siteUser.Districts[0].Id;
         ViewBag.DistrictDesc = siteUser.Districts[0].Name;
         int schoolYearId = modelService.SchoolYearId();
         ViewBag.SchoolId = modelService.DropDownDataSchool("", siteUser.EdsUserId, schoolYearId, false);
         ViewBag.SchoolYearId = modelService.GetUserSchoolYear(siteUser.EdsUserId, defaultDistrict, schoolYearId);
         ViewBag.SubjectId = new SelectList(db.tblSubjects.OrderBy(x => x.SubjectDesc), "SubjectId", "SubjectDesc");
         return View();
     }
     catch (Exception ex)
     {
         Logging log = new Logging();
         log.LogException(ex);
         return View("GeneralError");
     }
 }
 public ActionResult Create([Bind(Include = "ClassId,SchoolId,ClassDesc,SchoolYearId,SubjectId,Grade,CreateDatetime,ChangeDatetime")] tblClass tblclass)
 {
     try
     {
         var db = new dbTIREntities();
         SiteUser su = (SiteUser)Session["SiteUser"];
         SchoolService schoolService = new SchoolService(su, db);
         ModelServices modelService = new ModelServices();
         if (ModelState.IsValid)
         {
             ClassService classService = new ClassService((SiteUser)Session["SiteUser"], db);
             if (!(classService.IsClassExists(tblclass)))
             {
                 classService.AddClass(newClass: tblclass);
                 return RedirectToAction("Edit", new { id = tblclass.ClassId, defaultWizardStep = ClassWizardSteps.Teachers });
             }
             else
             {
                 int defaultDistrict = su.Districts[0].Id;
                 ViewBag.DistrictDesc = su.Districts[0].Name;
                 ModelState.AddModelError("ClassDesc", "Duplicate class name - please choose a unique name.");
             }
         }
         ViewBag.SchoolId = modelService.DropDownDataSchool("", su.EdsUserId, tblclass.SchoolYearId, false);
         ViewBag.SchoolYearId = modelService.GetUserSchoolYear(su.EdsUserId, su.Districts[0].Id, tblclass.SchoolYearId);
         ViewBag.SubjectId = new SelectList(db.tblSubjects.OrderBy(x => x.SubjectDesc), "SubjectId", "SubjectDesc", tblclass.SubjectId);
         return View(tblclass);
     }
     catch (Exception ex)
     {
         Logging log = new Logging();
         log.LogException(ex);
         return View("GeneralError");
     }
 }
        public ActionResult Edit([Bind(Include = "StudentId,StudentSchoolYearId,SchoolYearId,DistrictId,FirstName,MiddleName,LastName,BirthDate,Hispanic,StateId,LocalId,EnrollmentDate,IepIndicator,LepIndicator,FrlIndicator,")] StudentExt studentExt, int hdSchoolId, int? hdLineageId, int hdGradeId, int hdGenderId, int? hdRaceId, int? hdHomeLanguageId, int? hdNativeLanguageId, int schoolYear)
        {
            try
            {
                dbTIREntities db = new dbTIREntities();
                SiteUser siteUser = ((SiteUser)Session["SiteUser"]);
                StudentService studentService = new StudentService(siteUser, db);
                ViewBag.AllowEdit = HelperService.AllowUiEdits(siteUser.RoleDesc, "STUDENT");
                if (ModelState.IsValid)
                {
                    studentExt.ServingSchoolId = hdSchoolId;
                    studentExt.LineageId = hdLineageId;
                    studentExt.NativeLanguageId = hdNativeLanguageId;
                    studentExt.HomeLanguageId = hdHomeLanguageId;
                    studentExt.RaceId = hdRaceId;
                    studentExt.GradeLevel = (short)hdGradeId;
                    studentExt.GenderId = hdGenderId;
                    studentExt.SchoolYear = schoolYear;
                    if (studentService.IsStudentExist(studentExt.StateId, null, studentExt.StudentId))
                    {
                        PopulateViewData(studentExt);
                        ModelState.AddModelError("StateId", "State Id already exists");
                        return View(studentExt);
                    }
                    else if (studentService.IsStudentExist(null, studentExt.LocalId, studentExt.StudentId))
                    {
                        PopulateViewData(studentExt);
                        ModelState.AddModelError("LocalId", "Local Id already exists");
                        return View(studentExt);
                    }
                    else
                    {
                        studentService.SaveStudents(studentExt);
                    }
                }

                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                Logging log = new Logging();
                log.LogException(ex);
                return View("GeneralError");
            }
        }
 // GET: /Classes/Edit/5
 public ActionResult Edit(int? id, ClassWizardSteps? defaultWizardStep, bool? showTeachersForDistrict, bool? showStudentsForDistrict)
 {
     try
     {
         if (id == null)
         {
             return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
         }
         var db = new dbTIREntities();
         tblClass tblclass = db.tblClasses.Find(id);
         if (tblclass == null)
         {
             return HttpNotFound();
         }
         PopulateViewData(tblclass, defaultWizardStep, showTeachersForDistrict, showStudentsForDistrict);
         return View(tblclass);
     }
     catch (Exception ex)
     {
         Logging log = new Logging();
         log.LogException(ex);
         return View("GeneralError");
     }
 }
        private void PopulateViewData(tblClass tblclass, ClassWizardSteps? defaultWizardStep, bool? showTeachersForDistrict, bool? showStudentsForDistrict)
        {
            ViewBag.DefaultWizardStep = defaultWizardStep;
            ViewBag.ShowTeachersForDistrict = !showTeachersForDistrict.GetValueOrDefault();
            ViewBag.ShowStudentsForDistrict = !showStudentsForDistrict.GetValueOrDefault();

            var db = new dbTIREntities();
            SiteUser siteUser = (SiteUser)Session["SiteUser"];
            SchoolService schoolService = new SchoolService(siteUser, db);
            ClassService classService = new ClassService(siteUser, db);
            ModelServices modelService = new ModelServices();

            int userAssignedDistrict = siteUser.Districts[0].Id;
            bool filterTeachersByDistrict = showTeachersForDistrict.GetValueOrDefault();
            int districtId = userAssignedDistrict;
            // Get teachers for this class
            var teachersForThisClass = classService.GetTeachersForThisClass(tblclass);

            // Get teachers not in this class
            var teachersNotForThisClass = classService.GetTeachersNotForThisClass(tblclass, filterTeachersByDistrict, districtId);

            //Get students for this class
            var studentsForThisClass = classService.GetStudentForThisClass(tblclass);

            // Get students not for this class
            var availableStudents = classService.GetStudentNotForThisClass(tblclass, districtId);

            var availableStudentsForSchool = classService.GetStudentForSchool(tblclass, districtId);

            // Add data to ViewBag for form
            ViewBag.TeachersForThisClass = new MultiSelectList(teachersForThisClass, "TeacherId", "FullName", null);
            ViewBag.AvailableTeachers = new MultiSelectList(teachersNotForThisClass, "TeacherId", "FullName", null);
            if (showStudentsForDistrict.GetValueOrDefault())
            {
                ViewBag.AvailableStudents = new MultiSelectList(availableStudents, "StudentId", "FullName", null);
            }
            else
            {
                ViewBag.AvailableStudents = new MultiSelectList(availableStudentsForSchool, "StudentId", "FullName", null);
            }
            ViewBag.StudentsForThisClass = new MultiSelectList(studentsForThisClass, "StudentId", "FullName", null);
            ViewBag.StudentsForThisClassCount = studentsForThisClass.Count();
            ViewBag.SchoolId = modelService.DropDownDataSchool(Convert.ToString(tblclass.SchoolId), siteUser.EdsUserId, tblclass.SchoolYearId, false);
            ViewBag.SchoolYearId = modelService.GetUserSchoolYear(siteUser.EdsUserId, siteUser.Districts[0].Id, tblclass.SchoolYearId); 
            ViewBag.ClassDesc = db.tblClasses.Where(x => x.ClassId == tblclass.ClassId).Select(x => x.ClassDesc).SingleOrDefault();
            ViewBag.SubjectId = new SelectList(db.tblSubjects.OrderBy(x => x.SubjectDesc), "SubjectId", "SubjectDesc", tblclass.SubjectId);
            ViewBag.AllowEdit = HelperService.AllowUiEdits(siteUser.RoleDesc, "CLASS");
        }