Esempio n. 1
0
        /// <summary>
        /// This function is used to update weighting data in tblAssessmentGradeWeighting
        /// </summary>
        /// <param name="model"></param>
        public void UpdateWeighting(WeightingViewModel model, int assessmentGrdeWeightingId)
        {
            using (var context = new dbTIREntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        var data = context.tblAssessmentGradeWeightings
                                   .Where(x => x.AssessmentGradeWeightingId == assessmentGrdeWeightingId)
                                   .FirstOrDefault();

                        data.Weighting = (decimal)model.Weighting;
                        context.tblAssessmentGradeWeightings.Add(data);
                        context.Entry(data).State = EntityState.Modified;
                        context.SaveChanges();
                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                        throw ex;
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// This function is used to add weighting data in tblAssessmentGradeWeighting
        /// </summary>
        /// <param name="model"></param>
        public void AddWeighting(WeightingViewModel model, int assessmentWeightingId)
        {
            using (var context = new dbTIREntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        tblAssessmentGradeWeighting tblGradeWeighting = new tblAssessmentGradeWeighting()
                        {
                            AssessmentWeightingId = assessmentWeightingId,
                            Grade     = Convert.ToInt16(model.Grade),
                            Weighting = (decimal)model.Weighting
                        };
                        context.tblAssessmentGradeWeightings.Add(tblGradeWeighting);
                        context.SaveChanges();

                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                        throw ex;
                    }
                }
            }
        }
 public ActionResult Edit(int studentId, string schoolYear, string schoolTerm, string assessmentType, string assessmentDesc, string localId, string subject)
 {
     try
     {
         if (TempData["AssessmentModel"] != null)
         {
             TempData["AssessmentModel"] = TempData["AssessmentModel"];
         }
         dbTIREntities db       = new dbTIREntities();
         SiteUser      siteUser = ((SiteUser)Session["SiteUser"]);
         assScoreService = new AssessmentScoreService(siteUser, db);
         List <StudentScore> studentScores = assScoreService.GetStudentAssessmentScore(studentId, schoolYear, schoolTerm, assessmentType, assessmentDesc, localId, subject);
         StudentScore        score         = studentScores.FirstOrDefault();
         //StudentExt studentExt = studentService.GetStudentDetail(studentId, schoolYear);
         //PopulateViewData(studentExt);
         // ViewBag.AllowEdit = HelperService.AllowUiEdits(siteUser.RoleDesc, "STUDENT");
         return(View(score));
     }
     catch (Exception ex)
     {
         Logging log = new Logging();
         log.LogException(ex);
         return(View("GeneralError"));
     }
 }
Esempio n. 4
0
        /// <summary>
        /// DeleteClass() used to delete a class.
        /// </summary>
        /// <param name="classId"></param>
        /// <returns></returns>
        public string DeleteClass(int classId)
        {
            string result = "Success";

            using (var context = new dbTIREntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        context.tblClassStudents.Where(x => x.ClassId == classId).Delete();
                        context.tblClassTeachers.Where(x => x.ClassId == classId).Delete();;
                        context.tblClasses.Where(x => x.ClassId == classId).Delete();;

                        context.SaveChanges();

                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                        result = String.Format("Error: An error occurred in DeleteClass() while deleting class. Error: {0}", ex.ToString());
                    }
                }
            }
            return(result);
        }
Esempio n. 5
0
        private void FillDropDowns(AssessmentClassScoreViewModel model, bool isPostBack)
        {
            siteUser       = ((SiteUser)Session["SiteUser"]);
            db             = new dbTIREntities();
            commonService  = new CommonService(siteUser, db);
            modelServices  = new ModelServices();
            model.DropDown = new DropDownData();
            int schoolYearId = int.Parse(model.SchoolYearId);

            model.DistrictName = siteUser.Districts[0].Name;
            model.DistrictId   = siteUser.Districts[0].Id;
            model.Assessment   = commonService.GetAssessmentType();
            model.SchoolYears  = commonService.GetSchoolYear();
            model.SchoolTerms  = commonService.GetSchoolTerm();
            model.Subjects     = commonService.GetSubjects();
            int[] userSchools = modelServices.getSchoolsByUserId(siteUser.EdsUserId).ToArray();
            model.DropDown.School = new SchoolDropDown(modelServices.GetSchoolDropDownData(siteUser.EdsUserId, schoolYearId), true, "--SELECT--", "");
            int[] schoolsTeacher = modelServices.getTeachersBySchoolsId(userSchools).ToArray();
            if (isPostBack)
            {
                model.DropDown.Teacher     = new TeacherDropDown(modelServices.TeacherDropDownDataBySchoolAndYear(new int[] { int.Parse(model.SchoolId) }, schoolYearId, model.DistrictId), "--SELECT--", "");
                model.DropDown.SchoolClass = new ClassDropDown(modelServices.GetClassesByTeacher(schoolYearId, new[] { int.Parse(model.TeacherId) }), "--SELECT--", "");
            }
            else
            {
                model.DropDown.Teacher     = new TeacherDropDown(modelServices.TeacherDropDownDataBySchoolAndYear(userSchools, schoolYearId, model.DistrictId), "--SELECT--", "");
                model.DropDown.SchoolClass = new ClassDropDown(modelServices.GetClassesByTeacher(schoolYearId, schoolsTeacher), "--SELECT--", "");
            }
        }
 private void SaveAssessmentClassScore(AssessmentClassScore assessmentScoreObj)
 {
     using (var context = new dbTIREntities())
     {
         using (var dbContextTransaction = context.Database.BeginTransaction())
         {
             try
             {
                 int defaultValue = EDS.Constants.SystemParameter.ScoreTargetDefaultValue.DefaultValue;
                 int?score        = assessmentScoreObj.Score != defaultValue ? assessmentScoreObj.Score : null;
                 int?projection   = assessmentScoreObj.Target != defaultValue ? assessmentScoreObj.Target : null;
                 tblAssessmentScore tblAssessmentScore = new tblAssessmentScore()
                 {
                     AssessmentId   = assessmentScoreObj.AssessmentId,
                     StudentId      = assessmentScoreObj.StudentId,
                     Score          = score,
                     Projection     = projection,
                     GradeLevel     = assessmentScoreObj.GradeLevel,
                     SchoolID       = assessmentScoreObj.SchoolId,
                     CreateDatetime = DateTime.UtcNow
                 };
                 context.tblAssessmentScores.Add(tblAssessmentScore);
                 context.SaveChanges();
                 dbContextTransaction.Commit();
             }
             catch (Exception ex)
             {
                 dbContextTransaction.Rollback();
                 throw ex;
             }
         }
     }
 }
        //
        // GET: /AssessmentClassScore/
        public ActionResult Search(AssessmentClassScoreViewModel model)
        {
            try
            {
                db = new dbTIREntities();
                siteUser = ((SiteUser)Session["SiteUser"]);
                assessmentClassScoreService = new AssessmentClassScoreService(siteUser, db);

                if (assessmentClassScoreService.IsAssessmentWeightingExists(model))
                {
                    InitializeAssessmentScoreMetadata(model);
                    if (model.ScoresDetails.Count == 0)
                    {
                        ViewBag.Message = "No Record Found.";
                    }
                }
                else
                {
                    ViewBag.Message = "This combination of subject and assessment does not exist in the system for the selected school year.";
                }
                FillDropDowns(model, true);
                return View("Index", model);
            }
            catch (Exception ex)
            {
                Logging log = new Logging();
                log.LogException(ex);
                return View("GeneralError");
            }
        }
 public ActionResult Edit(int studentId, string schoolYear, string schoolTerm, string assessmentType, string assessmentDesc, string localId, string subject)
 {
     try
     {
         if (TempData["AssessmentModel"] != null)
         {
             TempData["AssessmentModel"] = TempData["AssessmentModel"];
         }
         dbTIREntities db = new dbTIREntities();
         SiteUser siteUser = ((SiteUser)Session["SiteUser"]);
         assScoreService = new AssessmentScoreService(siteUser, db);
         List<StudentScore> studentScores = assScoreService.GetStudentAssessmentScore(studentId, schoolYear, schoolTerm, assessmentType, assessmentDesc, localId, subject);
         StudentScore score = studentScores.FirstOrDefault();
         //StudentExt studentExt = studentService.GetStudentDetail(studentId, schoolYear);
         //PopulateViewData(studentExt);
         // ViewBag.AllowEdit = HelperService.AllowUiEdits(siteUser.RoleDesc, "STUDENT");
         return View(score);
     }
     catch (Exception ex)
     {
         Logging log = new Logging();
         log.LogException(ex);
         return View("GeneralError");
     }
 }
        private void UpdateAssessmentClassScore(AssessmentClassScore assessmentScoreObj)
        {
            using (var context = new dbTIREntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        var data = context.tblAssessmentScores
                                   .Where(x => x.AssessmentScoreId == assessmentScoreObj.AssessmentScoreId)
                                   .FirstOrDefault();

                        if (assessmentScoreObj.Score != EDS.Constants.SystemParameter.ScoreTargetDefaultValue.DefaultValue)
                        {
                            data.Score = assessmentScoreObj.Score;
                        }
                        if (assessmentScoreObj.Target != EDS.Constants.SystemParameter.ScoreTargetDefaultValue.DefaultValue)
                        {
                            data.Projection = assessmentScoreObj.Target;
                        }
                        data.ChangeDatetime = DateTime.UtcNow;
                        context.tblAssessmentScores.Add(data);
                        context.Entry(data).State = EntityState.Modified;
                        context.SaveChanges();
                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                        throw ex;
                    }
                }
            }
        }
        private void AddClassAssessmentScoreScore(AssessmentClassScore assessmentScoreObj, out string result)
        {
            using (var context = new dbTIREntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        //Update existing score
                        if (assessmentScoreObj.AssessmentScoreId != 0)
                        {
                            UpdateAssessmentClassScore(assessmentScoreObj);
                        }
                        // Save new Score
                        else
                        {
                            if (assessmentScoreObj.AssessmentScoreId == 0 && assessmentScoreObj.AssessmentId != 0)
                            {
                                SaveAssessmentClassScore(assessmentScoreObj);
                            }
                        }

                        result = "Records Saved Scuccessfully.";
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                        throw ex;
                    }
                }
            }
        }
Esempio n. 11
0
 public ActionResult Create(WeightingViewModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             db               = new dbTIREntities();
             siteUser         = ((SiteUser)Session["SiteUser"]);
             commonService    = new CommonService(siteUser, db);
             weightingService = new WeightingService(siteUser, db);
             bool weightingAlreadyExist = weightingService.SaveWeightingDetail(model);
             if (!weightingAlreadyExist)
             {
                 ViewBag.UserMessage = "Data Saved Successfully.";
                 model = new WeightingViewModel();
                 FillDropDowns(model);
                 ModelState.Clear();
             }
             else
             {
                 ViewBag.UserMessage = "Data already exists.";
                 FillDropDowns(model);
             }
         }
         catch (Exception ex)
         {
             Logging log = new Logging();
             log.LogException(ex);
             return(View("GeneralError"));
         }
     }
     return(View(model));
 }
Esempio n. 12
0
        private void UpdateUserSchool(dbTIREntities context, tblUserExt newUser)
        {
            try
            {
                if (!String.IsNullOrEmpty(newUser.SelectedSchools))
                {
                    // 2. Delete all schools for this user
                    context.tblUserSchools.Delete(x => x.UserId == newUser.UserId && x.SchoolYearId == newUser.SchoolYearId);

                    // 3. Add schools
                    string[] schoolIds = newUser.SelectedSchools.Split(',');
                    foreach (var schoolId in schoolIds)
                    {
                        context.tblUserSchools.Add(new tblUserSchool()
                        {
                            SchoolId        = Convert.ToInt32(schoolId),
                            UserId          = newUser.UserId,
                            CreatedDatetime = DateTime.Now,
                            ChangedDatetime = DateTime.Now,
                            SchoolYearId    = newUser.SchoolYearId
                        });
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("Error in UpdateUserSchool(). Error: {0}", ex.ToString()));
            }
        }
Esempio n. 13
0
        // 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 ActionResult Edit(
            [Bind(
                 Include =
                     "Subject,LocalId,StudentId,FirstName,LastName,Score,AssessmentType,SchoolTerm,SchoolYear,AssessmentDesc,AssessmentId"
                 )] StudentScore studentScore)
        {
            try
            {
                dbTIREntities          db                = new dbTIREntities();
                SiteUser               siteUser          = ((SiteUser)Session["SiteUser"]);
                AssessmentScoreService assessmentService = new AssessmentScoreService(siteUser, db);
                ViewBag.AllowEdit = HelperService.AllowUiEdits(siteUser.RoleDesc, "STUDENT");

                tblAssessmentScore assscore =
                    db.tblAssessmentScores.Where(
                        k => k.AssessmentId == studentScore.AssessmentId && k.StudentId == studentScore.StudentId)
                    .ToList()
                    .FirstOrDefault();
                assscore.Score = studentScore.Score;

                assessmentService.UpdateStudentScore(assscore);
                return(RedirectToAction("Search", TempData["AssessmentModel"]));
                //  return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                Logging log = new Logging();
                log.LogException(ex);
                return(View("GeneralError"));
            }
        }
 /// <summary>
 /// Pull current year from the database.
 /// TODO: Web.config must not be part of determining current year.
 /// </summary>
 /// <param name="db"></param>
 /// <returns></returns>
 public static string SchoolYearDescription(dbTIREntities db)
 {
     int currentSchoolYear = Convert.ToInt32(ConfigurationManager.AppSettings["SchoolYear"].ToString());
     var schoolYear = db.tblSchoolYears.Where(y => y.SchoolYear == currentSchoolYear)
         .Select(d => d.SchoolYearDesc).ToList();
     return schoolYear[0].ToString();
 }
Esempio n. 16
0
        //
        // GET: /AssessmentClassScore/
        public ActionResult Search(AssessmentClassScoreViewModel model)
        {
            try
            {
                db       = new dbTIREntities();
                siteUser = ((SiteUser)Session["SiteUser"]);
                assessmentClassScoreService = new AssessmentClassScoreService(siteUser, db);

                if (assessmentClassScoreService.IsAssessmentWeightingExists(model))
                {
                    InitializeAssessmentScoreMetadata(model);
                    if (model.ScoresDetails.Count == 0)
                    {
                        ViewBag.Message = "No Record Found.";
                    }
                }
                else
                {
                    ViewBag.Message = "This combination of subject and assessment does not exist in the system for the selected school year.";
                }
                FillDropDowns(model, true);
                return(View("Index", model));
            }
            catch (Exception ex)
            {
                Logging log = new Logging();
                log.LogException(ex);
                return(View("GeneralError"));
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Pull current year from the database.
        /// TODO: Web.config must not be part of determining current year.
        /// </summary>
        /// <param name="db"></param>
        /// <returns></returns>
        public static string SchoolYearDescription(dbTIREntities db)
        {
            int currentSchoolYear = Convert.ToInt32(ConfigurationManager.AppSettings["SchoolYear"].ToString());
            var schoolYear        = db.tblSchoolYears.Where(y => y.SchoolYear == currentSchoolYear)
                                    .Select(d => d.SchoolYearDesc).ToList();

            return(schoolYear[0].ToString());
        }
Esempio n. 18
0
 /// <summary>
 /// Save user profile in Session.
 /// Used when user logs in the site.
 /// </summary>
 /// <param name="aspnetUser"></param>
 /// <param name="db"></param>
 /// <returns></returns>
 public static SiteUser SetSiteUserProfile(ApplicationUser aspnetUser, dbTIREntities db)
 {
     if (HttpContext.Current.Session["SiteUser"] == null)
     {
         var su = GetUserProfile(aspnetUser, db);
         HttpContext.Current.Session["SiteUser"] = su;
     }
     return((SiteUser)HttpContext.Current.Session["SiteUser"]);
 }
 public ActionResult Create()
 {
     db = new dbTIREntities();
     siteUser = ((SiteUser)Session["SiteUser"]);
     commonService = new CommonService(siteUser, db);
     WeightingViewModel model = new WeightingViewModel();
     FillDropDowns(model);
     return View(model);
 }
Esempio n. 20
0
        /// <summary>
        /// Pulls user profile from ASPNet Identity and TIR databases.
        /// </summary>
        /// <param name="aspnetUser"></param>
        /// <param name="db"></param>
        /// <returns></returns>
        public static SiteUser GetUserProfile(ApplicationUser aspnetUser, dbTIREntities db)
        {
            int currentSchoolYear = SchoolYear();
            int schoolYearId      = GetSchoolYearId(currentSchoolYear, new dbTIREntities());

            var edsUserId = (from e in db.tblUsers
                             where e.AspNetUserId == aspnetUser.Id
                             select e.UserId).SingleOrDefault();


            var edsUser = (from user in db.tblUsers
                           join ud in db.tblUserDistricts on user.UserId equals ud.UserId
                           join role in db.tblRoles on ud.RoleId equals role.RoleId
                           where user.AspNetUserId == aspnetUser.Id && ud.SchoolYearId == schoolYearId
                           select new
            {
                FullName = user.FirstName + " " + user.LastName,
                RoleId = role.RoleId,
                RoleDesc = role.RoleDesc
            }).FirstOrDefault();
            SiteUser siteUser = new SiteUser()
            {
                EdsUserId           = edsUserId,
                IdentityUserId      = aspnetUser.Id,
                IdentityUserName    = aspnetUser.UserName,
                UserFullName        = edsUser.FullName,
                Role                = edsUser.RoleId,
                RoleDesc            = edsUser.RoleDesc,
                isAdministrator     = edsUser.RoleDesc.Equals(SiteRole_Administrator, StringComparison.OrdinalIgnoreCase),
                isDataAdministrator = edsUser.RoleDesc.Equals(SiteRole_DataAdministrator, StringComparison.OrdinalIgnoreCase),
                isEdsAdministrator  = edsUser.RoleDesc.Equals(SiteRole_EdsAdministrator, StringComparison.OrdinalIgnoreCase),
                isTeacher           = edsUser.RoleDesc.Equals(SiteRole_Teacher, StringComparison.OrdinalIgnoreCase),

                Districts = (from userDistrict in db.tblUserDistricts
                             join district in db.tblDistricts on userDistrict.DistrictId equals district.DistrictId
                             where userDistrict.UserId == edsUserId && userDistrict.SchoolYearId == schoolYearId
                             select new UserDisctrict()
                {
                    Id = district.DistrictId,
                    Name = district.DistrictDesc
                }).ToList(),

                Schools = (from userSchool in db.tblUserSchools
                           join school in db.tblSchools on userSchool.SchoolId equals school.SchoolId
                           where userSchool.UserId == edsUserId
                           select new UserSchool()
                {
                    Id = userSchool.SchoolId,
                    Name = school.SchoolDesc,
                    DistrictId = school.DistrictId,
                    SchoolYearId = userSchool.SchoolYearId
                }).ToList()
            };

            return(siteUser);
        }
Esempio n. 21
0
        public ActionResult Create()
        {
            db                = new dbTIREntities();
            siteUser          = ((SiteUser)Session["SiteUser"]);
            assessmentService = new AssessmentService(siteUser, db);
            AssessmentViewModel model = new AssessmentViewModel();

            FillDropDowns(model);
            return(View(model));
        }
Esempio n. 22
0
        public ActionResult Create()
        {
            db            = new dbTIREntities();
            siteUser      = ((SiteUser)Session["SiteUser"]);
            commonService = new CommonService(siteUser, db);
            WeightingViewModel model = new WeightingViewModel();

            FillDropDowns(model);
            return(View(model));
        }
Esempio n. 23
0
        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 Index()
 {
     db = new dbTIREntities();
     siteUser = ((SiteUser)Session["SiteUser"]);
     assScoreService = new AssessmentScoreService(siteUser, db);
     commonService = new CommonService(siteUser, db);
     AssessmentScoreViewModel model = new AssessmentScoreViewModel();
     model.DistrictName = siteUser.Districts[0].Name;
     model.DistrictId = siteUser.Districts[0].Id;
     FillDropDowns(model);
     return View(model);
 }
 public ActionResult Search(AssessmentScoreViewModel model)
 {
     db = new dbTIREntities();
     siteUser = ((SiteUser)Session["SiteUser"]);
     assScoreService = new AssessmentScoreService(siteUser, db);
     model.DistrictName = siteUser.Districts[0].Name;
     model.DistrictId = siteUser.Districts[0].Id;
     model.StudentScores = assScoreService.GetAssessmentScoreData(model);
     FillDropDowns(model);
    TempData["AssessmentModel"] = model;
     return View("Index", model);
 }
 public ActionResult Search(AssessmentScoreViewModel model)
 {
     db                  = new dbTIREntities();
     siteUser            = ((SiteUser)Session["SiteUser"]);
     assScoreService     = new AssessmentScoreService(siteUser, db);
     model.DistrictName  = siteUser.Districts[0].Name;
     model.DistrictId    = siteUser.Districts[0].Id;
     model.StudentScores = assScoreService.GetAssessmentScoreData(model);
     FillDropDowns(model);
     TempData["AssessmentModel"] = model;
     return(View("Index", model));
 }
        public ActionResult Index()
        {
            db              = new dbTIREntities();
            siteUser        = ((SiteUser)Session["SiteUser"]);
            assScoreService = new AssessmentScoreService(siteUser, db);
            commonService   = new CommonService(siteUser, db);
            AssessmentScoreViewModel model = new AssessmentScoreViewModel();

            model.DistrictName = siteUser.Districts[0].Name;
            model.DistrictId   = siteUser.Districts[0].Id;
            FillDropDowns(model);
            return(View(model));
        }
 /// <summary>
 /// Used for populating School drop downs. A value of -1 indicates user selected --ALL--.
 /// </summary>
 /// <param name="userId"></param>
 /// <param name="userDistrictId"></param>
 /// <param name="schoolId"></param>
 /// <param name="db"></param>
 /// <returns></returns>
 public static int[] GetUserSchoolsFilter(int userId, int userDistrictId, int schoolId, dbTIREntities db)
 {
     if (schoolId == -1)
     {
         // Get all schools for the district
         return (from school in db.tblSchools
                 where school.DistrictId == userDistrictId
                 select school.SchoolId).ToArray();
     }
     else
     {
         return new int[] { schoolId };
     }
 }
Esempio n. 29
0
        public ActionResult CreateKnowledgeBaseItem(KnowledgeBase model)
        {
            try
            {
                SiteUser                  siteUser            = (SiteUser)Session["SiteUser"];
                ModelServices             modelService        = new ModelServices();
                List <HttpPostedFileBase> httpPostedFileBases = null;
                if (model.Files.ToList()[0] != null)
                {
                    httpPostedFileBases = model.Files.ToList();
                    var allowedFileSize = ConfigurationManager.AppSettings["FileSize"].ToString();
                    if (!DocumentManagementService.ValidateAttachmentSize(httpPostedFileBases))
                    {
                        ModelState.AddModelError("Files", "Attachment Size exceeds allowed limit of " + allowedFileSize + " MB");
                    }
                }

                if (ModelState.IsValid)
                {
                    var db = new dbTIREntities();
                    KnowledgeBaseService kbService = new KnowledgeBaseService(siteUser, db);

                    if (!kbService.IsKnowledgeBaseExists(model.Title))
                    {
                        //TODO: Till nowwe are picking first district Id. Need to refactor code when a user belongs to more than 1 district.
                        model.DistrictId      = siteUser.Districts[0].Id;
                        model.RoleId          = model.RoleId;
                        model.CreatedDateTime = DateTime.Now;
                        model.CreatedUserId   = siteUser.EdsUserId;
                        model.FileDetails     = model.Files.ToList()[0] != null?DocumentManagementService.GetFileDetail(model.Files) : null;

                        kbService.SaveKnowledgeBase(model);
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        ModelState.AddModelError("Title", "Duplicate Title - please choose a unique title.");
                    }
                }
                ViewBag.RoleId = new SelectList(modelService.GetRolesForRole((int)(siteUser.Role)), "RoleId", "RoleDesc");
                return(View());
            }
            catch (Exception ex)
            {
                Logging log = new Logging();
                log.LogException(ex);
                return(View("GeneralError"));
            }
        }
Esempio n. 30
0
        public string UpdateStudents(int classId, List <string> addedStudentIds, List <string> removedStudentIds)
        {
            string result = "Success";

            using (var context = new dbTIREntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        // 1. Delete selected students for this class
                        if (removedStudentIds != null)
                        {
                            foreach (var student in removedStudentIds)
                            {
                                int studentId = Convert.ToInt32(student);
                                context.tblClassStudents.Delete(x => x.ClassId == classId && x.StudentId == studentId);
                            }
                        }

                        if (addedStudentIds != null)
                        {
                            // 2. Add selected students for this class
                            foreach (var student in addedStudentIds)
                            {
                                context.tblClassStudents.Add(new tblClassStudent()
                                {
                                    ClassId        = Convert.ToInt32(classId),
                                    StudentId      = Convert.ToInt32(student),
                                    CreateDatetime = DateTime.Now
                                });
                                context.SaveChanges();
                            }
                        }

                        // 3. Commit changes
                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        // 4. Rollback changes
                        dbContextTransaction.Rollback();
                        result = String.Format("Error: An error occurred in UpdateStudentsInClass() while adding/removing students from this class. Error: {0}", ex.ToString());
                    }
                }
            }
            return(result);
        }
        public string UpdateStudents(int classId, List<string> addedStudentIds, List<string> removedStudentIds)
        {
            string result = "Success";
            using (var context = new dbTIREntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        // 1. Delete selected students for this class
                        if (removedStudentIds != null)
                        {
                            foreach (var student in removedStudentIds)
                            {
                                int studentId = Convert.ToInt32(student);
                                context.tblClassStudents.Delete(x => x.ClassId == classId && x.StudentId == studentId);
                            }
                        }

                        if (addedStudentIds != null)
                        {
                            // 2. Add selected students for this class
                            foreach (var student in addedStudentIds)
                            {
                                context.tblClassStudents.Add(new tblClassStudent()
                                {
                                    ClassId = Convert.ToInt32(classId),
                                    StudentId = Convert.ToInt32(student),
                                    CreateDatetime = DateTime.Now
                                });
                                context.SaveChanges();
                            }
                        }

                        // 3. Commit changes
                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        // 4. Rollback changes
                        dbContextTransaction.Rollback();
                        result = String.Format("Error: An error occurred in UpdateStudentsInClass() while adding/removing students from this class. Error: {0}", ex.ToString());
                    }
                }
            }
            return result;
        }
Esempio n. 32
0
 public ActionResult SaveAssessmentClassScore(List <AssessmentClassScore> model)
 {
     try
     {
         db = new dbTIREntities();
         SiteUser su = ((SiteUser)Session["SiteUser"]);
         assessmentClassScoreService = new AssessmentClassScoreService(su, db);
         string result = assessmentClassScoreService.SaveClassAssessmentScore(model);
         return(Json(result, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         Logging log = new Logging();
         log.LogException(ex);
         return(View("GeneralError"));
     }
 }
 public ActionResult SaveAssessmentClassScore(List<AssessmentClassScore> model)
 {
     try
     {
         db = new dbTIREntities();
         SiteUser su = ((SiteUser)Session["SiteUser"]);
         assessmentClassScoreService = new AssessmentClassScoreService(su, db);
         string result = assessmentClassScoreService.SaveClassAssessmentScore(model);
         return Json(result, JsonRequestBehavior.AllowGet);
     }
     catch (Exception ex)
     {
         Logging log = new Logging();
         log.LogException(ex);
         return View("GeneralError");
     }
 }
Esempio n. 34
0
        public static bool IsUserAuthorized(ApplicationUser aspnetUser, dbTIREntities db)
        {
            int  currentSchoolYear = SchoolYear();
            int  schoolYearId      = GetSchoolYearId(currentSchoolYear, new dbTIREntities());
            bool isUserAuthorized  = false;
            var  userInfo          = (from user in db.tblUsers
                                      join ud in db.tblUserDistricts on user.UserId equals ud.UserId
                                      where user.AspNetUserId == aspnetUser.Id && ud.SchoolYearId == schoolYearId
                                      select ud
                                      ).FirstOrDefault();

            if (userInfo != null)
            {
                isUserAuthorized = true;
            }
            return(isUserAuthorized);
        }
Esempio n. 35
0
        public static void UpdateSiteUserProfile(SiteUser su, dbTIREntities db)
        {
            SiteUser siteUser = su;

            siteUser.Schools = (from userSchool in db.tblUserSchools
                                join school in db.tblSchools on userSchool.SchoolId equals school.SchoolId
                                where userSchool.UserId == su.EdsUserId
                                select new UserSchool()
            {
                Id = userSchool.SchoolId,
                Name = school.SchoolDesc,
                DistrictId = school.DistrictId,
                SchoolYearId = userSchool.SchoolYearId
            }).ToList();

            HttpContext.Current.Session["SiteUser"] = siteUser;
        }
Esempio n. 36
0
 public ActionResult KnowledgeBaseDetail(int KnowledgeBaseId)
 {
     try
     {
         var                  db         = new dbTIREntities();
         SiteUser             su         = (SiteUser)Session["SiteUser"];
         KnowledgeBaseService kbService  = new KnowledgeBaseService(su, db);
         int                  DistrictId = su.Districts[0].Id;
         var                  listdata   = kbService.GetKnowledgeBaseDetail(KnowledgeBaseId, DistrictId);
         return(View(listdata));
     }
     catch (Exception ex)
     {
         Logging log = new Logging();
         log.LogException(ex);
         return(View("GeneralError"));
     }
 }
Esempio n. 37
0
        private void InitializeAssessmentScoreMetadata(AssessmentClassScoreViewModel model)
        {
            int decimalPlace = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SiteDecimalPlace"].ToString());

            db = new dbTIREntities();
            SiteUser      su      = ((SiteUser)Session["SiteUser"]);
            ModelServices service = new ModelServices();

            assessmentClassScoreService = new AssessmentClassScoreService(su, db);
            var details = assessmentClassScoreService.GetClassAssessmentScoreData(su.Districts.First().Id, model);

            model.ScoresDetails = details;
            SetDetailReportUrlData(model);
            if (model.ScoresDetails.Count > 0)
            {
                UpdateReportTemplateConfigurations(service, model.ScoresDetails[0].ReportTemplateId);
            }
            // service.IsChildAssessmentsExists(model.AssessmentList);
        }
Esempio n. 38
0
 public ActionResult Index()
 {
     try
     {
         var                  db                 = new dbTIREntities();
         SiteUser             su                 = (SiteUser)Session["SiteUser"];
         KnowledgeBaseService kbService          = new KnowledgeBaseService(su, db);
         List <KnowledgeBase> KnowledgeBaseItems = new List <KnowledgeBase>();
         KnowledgeBaseItems = kbService.GetKnowledgeBase().ToList();
         ViewBag.AllowEdit  = HelperService.AllowUiEdits(su.RoleDesc, "USER");
         return(View(KnowledgeBaseItems));
     }
     catch (Exception ex)
     {
         Logging log = new Logging();
         log.LogException(ex);
         return(View("GeneralError"));
     }
 }
 public ActionResult Index()
 {
     try
     {
         var db = new dbTIREntities();
         SiteUser su = (SiteUser)Session["SiteUser"];
         KnowledgeBaseService kbService = new KnowledgeBaseService(su, db);
         List<KnowledgeBase> KnowledgeBaseItems = new List<KnowledgeBase>();
         KnowledgeBaseItems = kbService.GetKnowledgeBase().ToList();
         ViewBag.AllowEdit = HelperService.AllowUiEdits(su.RoleDesc, "USER");
         return View(KnowledgeBaseItems);
     }
     catch (Exception ex)
     {
         Logging log = new Logging();
         log.LogException(ex);
         return View("GeneralError");
     }
 }
        public ActionResult KnowledgeBaseDetail(int KnowledgeBaseId)
        {
            try
            {
                var db = new dbTIREntities();
                SiteUser su = (SiteUser)Session["SiteUser"];
                KnowledgeBaseService kbService = new KnowledgeBaseService(su, db);
                int DistrictId = su.Districts[0].Id;
                var listdata = kbService.GetKnowledgeBaseDetail(KnowledgeBaseId, DistrictId);
                return View(listdata);

            }
            catch (Exception ex)
            {
                Logging log = new Logging();
                log.LogException(ex);
                return View("GeneralError");
            }
        }
Esempio n. 41
0
 public ActionResult Announcements(int?page)
 {
     try
     {
         int            pageSize       = Convert.ToInt32(ConfigurationManager.AppSettings["PageSize"]);
         int            pageNumber     = (page ?? 1);
         var            db             = new dbTIREntities();
         SiteUser       su             = (SiteUser)Session["SiteUser"];
         SupportService supportService = new SupportService(su, db);
         var            listData       = (supportService.GetAnnouncements()).ToPagedList(pageNumber, pageSize);
         return(View("Announcements", listData));
     }
     catch (Exception ex)
     {
         Logging log = new Logging();
         log.LogException(ex);
         return(View("GeneralError"));
     }
 }
        public ActionResult Announcements(int? page)
        {
            try
            {
                int pageSize = Convert.ToInt32(ConfigurationManager.AppSettings["PageSize"]);
                int pageNumber = (page ?? 1);
                var db = new dbTIREntities();
                SiteUser su = (SiteUser)Session["SiteUser"];
                SupportService supportService = new SupportService(su, db);   
                var listData = (supportService.GetAnnouncements()).ToPagedList(pageNumber, pageSize);
                return View("Announcements", listData);
            }
            catch (Exception ex)
            {
                Logging log = new Logging();
                log.LogException(ex);
                return View("GeneralError");
            }

        }
        public ActionResult GetAnnouncements()
        {
            try
            {
                var db = new dbTIREntities();
                SiteUser su = (SiteUser)Session["SiteUser"];
                SupportService supportService = new SupportService(su, db);

                return PartialView("_AnnouncementPartial", new SiteModels() 
                { 
                    Announcements = supportService.GetAnnouncements().ToList() 
                }); 
            }
            catch (Exception ex)
            {
                Logging log = new Logging();
                log.LogException(ex);
                return View("GeneralError");
            }
        }
        /// <summary>
        /// This function is used to add a new weighting
        /// </summary>
        /// <param name="studentExtend"></param>
        public void CreateWeighting(WeightingViewModel model)
        {
            using (var context = new dbTIREntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        tblAssessmentWeighting tblWeighting = new tblAssessmentWeighting()
                        {
                            AssessmentTypeId = Convert.ToInt32(model.AssessmentTypeId),
                            SubjectId = Convert.ToInt32(model.SubjectId),
                            DistrictId = Convert.ToInt32(model.DistrictId),
                            SchoolYearId = Convert.ToInt32(model.SchoolYearId),
                            CreateDatetime = DateTime.UtcNow
                        };
                        context.tblAssessmentWeightings.Add(tblWeighting);
                        context.SaveChanges();

                        int assessmentWeightingId = tblWeighting.AssessmentWeightingId;
                        tblAssessmentGradeWeighting tblGradeWeighting = new tblAssessmentGradeWeighting()
                        {
                            AssessmentWeightingId = assessmentWeightingId,
                            Grade = Convert.ToInt16(model.Grade),
                            Weighting = (decimal)model.Weighting
                        };
                        context.tblAssessmentGradeWeightings.Add(tblGradeWeighting);
                        context.SaveChanges();

                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                        throw ex;
                    }
                }
            }
        }
 private void InitializeAssessmentScoreMetadata(AssessmentClassScoreViewModel model)
 {
     int decimalPlace = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SiteDecimalPlace"].ToString());
     db = new dbTIREntities();
     SiteUser su = ((SiteUser)Session["SiteUser"]);
     ModelServices service = new ModelServices();
     assessmentClassScoreService = new AssessmentClassScoreService(su, db);
     var details = assessmentClassScoreService.GetClassAssessmentScoreData(su.Districts.First().Id, model);
     model.ScoresDetails = details;
     SetDetailReportUrlData(model);
     if (model.ScoresDetails.Count > 0)
     {
         UpdateReportTemplateConfigurations(service, model.ScoresDetails[0].ReportTemplateId);
     }
     // service.IsChildAssessmentsExists(model.AssessmentList);
 }
 public static void SetUserLoginInfo(SiteUser siteUser, dbTIREntities db)
 {
     var userLoggedInInfo = db.tblUserLoginInfoes.Where(l => l.UserId == siteUser.EdsUserId).FirstOrDefault();
     if (userLoggedInInfo != null)
     {
         userLoggedInInfo.LoginDate = DateTime.Now.ToUniversalTime();
         db.Entry(userLoggedInInfo).State = EntityState.Modified;
     }
     else
     {
         tblUserLoginInfo userLoginInfo = new tblUserLoginInfo()
                                          {
                                              UserId = siteUser.EdsUserId,
                                              LoginDate = DateTime.Now.ToUniversalTime()
                                          };
         db.tblUserLoginInfoes.Add(userLoginInfo);
     }
     db.SaveChanges();
 }
        public static void UpdateSiteUserProfile(SiteUser su, dbTIREntities db)
        {
            SiteUser siteUser = su;
            siteUser.Schools = (from userSchool in db.tblUserSchools
                                join school in db.tblSchools on userSchool.SchoolId equals school.SchoolId
                                where userSchool.UserId == su.EdsUserId
                                select new UserSchool()
                                {
                                    Id = userSchool.SchoolId,
                                    Name = school.SchoolDesc,
                                    DistrictId = school.DistrictId,
                                    SchoolYearId = userSchool.SchoolYearId
                                }).ToList();

            HttpContext.Current.Session["SiteUser"] = siteUser;

        }
 public static bool IsUserAuthorized(ApplicationUser aspnetUser, dbTIREntities db)
 {
     int currentSchoolYear = SchoolYear();
     int schoolYearId = GetSchoolYearId(currentSchoolYear, new dbTIREntities());
     bool isUserAuthorized = false;
     var userInfo = (from user in db.tblUsers
                     join ud in db.tblUserDistricts on user.UserId equals ud.UserId
                     where user.AspNetUserId == aspnetUser.Id && ud.SchoolYearId == schoolYearId
                     select ud
                   ).FirstOrDefault();
     if (userInfo != null)
     {
         isUserAuthorized = true;
     }
     return isUserAuthorized;
 }
 private void FillDropDowns(AssessmentClassScoreViewModel model, bool isPostBack)
 {
     siteUser = ((SiteUser)Session["SiteUser"]);
     db = new dbTIREntities();
     commonService = new CommonService(siteUser, db);
     modelServices = new ModelServices();
     model.DropDown = new DropDownData();
     int schoolYearId = int.Parse(model.SchoolYearId);
     model.DistrictName = siteUser.Districts[0].Name;
     model.DistrictId = siteUser.Districts[0].Id;
     model.Assessment = commonService.GetAssessmentType();
     model.SchoolYears = commonService.GetSchoolYear();
     model.SchoolTerms = commonService.GetSchoolTerm();
     model.Subjects = commonService.GetSubjects();
     int[] userSchools = modelServices.getSchoolsByUserId(siteUser.EdsUserId).ToArray();
     model.DropDown.School = new SchoolDropDown(modelServices.GetSchoolDropDownData(siteUser.EdsUserId, schoolYearId), true, "--SELECT--", "");
     int[] schoolsTeacher = modelServices.getTeachersBySchoolsId(userSchools).ToArray();
     if (isPostBack)
     {
         model.DropDown.Teacher = new TeacherDropDown(modelServices.TeacherDropDownDataBySchoolAndYear(new int[] { int.Parse(model.SchoolId) }, schoolYearId, model.DistrictId), "--SELECT--", "");
         model.DropDown.SchoolClass = new ClassDropDown(modelServices.GetClassesByTeacher(schoolYearId, new[] { int.Parse(model.TeacherId) }), "--SELECT--", "");
     }
     else
     {
         model.DropDown.Teacher = new TeacherDropDown(modelServices.TeacherDropDownDataBySchoolAndYear(userSchools, schoolYearId, model.DistrictId), "--SELECT--", "");
         model.DropDown.SchoolClass = new ClassDropDown(modelServices.GetClassesByTeacher(schoolYearId, schoolsTeacher), "--SELECT--", "");
     }
 }
        public ActionResult CreateKnowledgeBaseItem(KnowledgeBase model)
        {
            try
            {
                SiteUser siteUser = (SiteUser)Session["SiteUser"];
                ModelServices modelService = new ModelServices();
                List<HttpPostedFileBase> httpPostedFileBases = null;
                if (model.Files.ToList()[0] != null)
                {
                    httpPostedFileBases = model.Files.ToList();
                    var allowedFileSize = ConfigurationManager.AppSettings["FileSize"].ToString();
                    if (!DocumentManagementService.ValidateAttachmentSize(httpPostedFileBases))
                    {
                        ModelState.AddModelError("Files", "Attachment Size exceeds allowed limit of " + allowedFileSize + " MB");
                    }
                }

                if (ModelState.IsValid)
                {
                    var db = new dbTIREntities();
                    KnowledgeBaseService kbService = new KnowledgeBaseService(siteUser, db);

                    if (!kbService.IsKnowledgeBaseExists(model.Title))
                    {
                        //TODO: Till nowwe are picking first district Id. Need to refactor code when a user belongs to more than 1 district.
                        model.DistrictId = siteUser.Districts[0].Id;
                        model.RoleId = model.RoleId;
                        model.CreatedDateTime = DateTime.Now;
                        model.CreatedUserId = siteUser.EdsUserId;
                        model.FileDetails = model.Files.ToList()[0] != null ? DocumentManagementService.GetFileDetail(model.Files) : null;
                        kbService.SaveKnowledgeBase(model);
                        return RedirectToAction("Index");
                    }
                    else
                    {
                        ModelState.AddModelError("Title", "Duplicate Title - please choose a unique title.");
                    }
                }
                ViewBag.RoleId = new SelectList(modelService.GetRolesForRole((int)(siteUser.Role)), "RoleId", "RoleDesc");
                return View();
            }
            catch (Exception ex)
            {
                Logging log = new Logging();
                log.LogException(ex);
                return View("GeneralError");
            }
        }
 public static int GetSchoolYearId(int schoolYear, dbTIREntities db)
 {
     return db.tblSchoolYears.Where(x => x.SchoolYear == schoolYear)
                                            .Select(x => x.SchoolYearId).FirstOrDefault();
 }
        /// <summary>
        /// This function is used to Add and Update student
        /// </summary>
        /// <param name="studentExtend"></param>
        public void SaveStudents(StudentExt studentExtend)
        {
            using (var context = new dbTIREntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        tblStudent newtblStudent = new tblStudent()
                        {
                            FirstName = studentExtend.FirstName,
                            MiddleName = studentExtend.MiddleName,
                            LastName = studentExtend.LastName,
                            DistrictId = studentExtend.DistrictId,
                            StateId = studentExtend.StateId,
                            LocalId = studentExtend.LocalId,
                            LineageId = studentExtend.LineageId == -1 ? null : studentExtend.LineageId,
                            RaceId = studentExtend.RaceId == -1 ? null : studentExtend.RaceId,
                            GenderId = studentExtend.GenderId,
                            BirthDate = studentExtend.BirthDate,
                            HomeLanguageId = studentExtend.HomeLanguageId == -1 ? null : studentExtend.HomeLanguageId,
                            NativeLanguageId = studentExtend.NativeLanguageId == -1 ? null : studentExtend.NativeLanguageId,
                            ChangeDatetime = DateTime.Now
                        };
                        if (studentExtend.StudentId == 0)
                        {
                            context.tblStudents.Add(newtblStudent);
                        }
                        else
                        {
                            newtblStudent.StudentId = studentExtend.StudentId;
                            context.tblStudents.Add(newtblStudent);
                            context.Entry(newtblStudent).State = EntityState.Modified;
                        }
                        context.SaveChanges();
                        tblStudentSchoolYear newtblStudentSchoolYear = new tblStudentSchoolYear()
                        {
                            StudentId = newtblStudent.StudentId,
                            SchoolYearId = studentExtend.SchoolYearId,
                            ServingSchoolId = studentExtend.ServingSchoolId,
                            GradeLevel = studentExtend.GradeLevel,
                            StateId = studentExtend.StateId,
                            LocalId = studentExtend.LocalId,
                            LepIndicator = studentExtend.LepIndicator,
                            IepIndicator = studentExtend.IepIndicator,
                            FrlIndicator = studentExtend.FrlIndicator,
                            EnrollmentDate = studentExtend.EnrollmentDate,
                            ChangeDateTIme = DateTime.Now,
                            Hispanic = studentExtend.Hispanic
                        };

                        if (studentExtend.StudentSchoolYearId == 0)
                        {
                            context.tblStudentSchoolYears.Add(newtblStudentSchoolYear);
                        }
                        else
                        {
                            newtblStudentSchoolYear.StudentSchoolYearId = studentExtend.StudentSchoolYearId;
                            context.tblStudentSchoolYears.Add(newtblStudentSchoolYear);
                            context.Entry(newtblStudentSchoolYear).State = EntityState.Modified;
                        }

                        context.SaveChanges();
                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                        throw ex;
                    }
                }
            }

        }
 public StudentService(SiteUser siteUser, dbTIREntities db)
 {
     _db = db;
     _siteUser = siteUser;
 }
 private void SaveAssessment(tblAssessment tblAssessment)
 {
     using (var context = new dbTIREntities())
     {
         using (var dbContextTransaction = context.Database.BeginTransaction())
         {
             try
             {
                 context.tblAssessments.Add(tblAssessment);
                 context.SaveChanges();
                 dbContextTransaction.Commit();
             }
             catch (Exception ex)
             {
                 dbContextTransaction.Rollback();
                 throw ex;
             }
         }
     }
 }
        public ActionResult Create(WeightingViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    db = new dbTIREntities();
                    siteUser = ((SiteUser)Session["SiteUser"]);
                    commonService = new CommonService(siteUser, db);
                    weightingService = new WeightingService(siteUser, db);
                    bool weightingAlreadyExist = weightingService.SaveWeightingDetail(model);
                    if (!weightingAlreadyExist)
                    {
                        ViewBag.UserMessage = "Data Saved Successfully.";
                        model = new WeightingViewModel();
                        FillDropDowns(model);
                        ModelState.Clear();

                    }
                    else
                    {
                        ViewBag.UserMessage = "Data already exists.";
                        FillDropDowns(model);
                    }

                }
                catch (Exception ex)
                {
                    Logging log = new Logging();
                    log.LogException(ex);
                    return View("GeneralError");
                }
            }
            return View(model);
        }
 public AssessmentScoreService(SiteUser siteUser, dbTIREntities db)
 {
     _db = db;
     _siteUser = siteUser;
 }
 public ClassService(SiteUser siteUser, dbTIREntities db)
 {
     _db = db;
     _siteUser = siteUser;
 }
        /// <summary>
        /// DeleteClass() used to delete a class.
        /// </summary>
        /// <param name="classId"></param>
        /// <returns></returns>
        public string DeleteClass(int classId)
        {
            string result = "Success";
            using (var context = new dbTIREntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {

                        context.tblClassStudents.Where(x => x.ClassId == classId).Delete();
                        context.tblClassTeachers.Where(x => x.ClassId == classId).Delete(); ;
                        context.tblClasses.Where(x => x.ClassId == classId).Delete(); ;

                        context.SaveChanges();

                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                        result = String.Format("Error: An error occurred in DeleteClass() while deleting class. Error: {0}", ex.ToString());
                    }
                }
            }
            return result;
        }
 public SupportService(SiteUser siteUser, dbTIREntities db)
 {
     _siteUser = siteUser;
     _db = db;
 }
        public string UpdateTeachers(int classId, List<string> teacherId)
        {
            string result = "Success";

            using (var context = new dbTIREntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        // 1. Delete all teachers for this class
                        context.tblClassTeachers.Delete(x => x.ClassId == classId);

                        // 2. Add all teachers
                        if (teacherId != null)
                        {
                            foreach (var teacher in teacherId)
                            {
                                context.tblClassTeachers.Add(new tblClassTeacher()
                                {
                                    ClassId = Convert.ToInt32(classId),
                                    UserId = Convert.ToInt32(teacher),
                                    CreateDatetime = DateTime.Now
                                });
                                context.SaveChanges();
                            }
                        }

                        // 3. Commit changes
                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        // 4. Rollback changes
                        dbContextTransaction.Rollback();
                        result = String.Format("Error: An error occurred in UpdateTeachersInClass() while adding/removing teachers from this class. Error: {0}", ex.ToString());
                    }
                }
            }
            return result;
        }