//
        // 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 Create()
 {
     db = new dbTIREntities();
     siteUser = ((SiteUser)Session["SiteUser"]);
     commonService = new CommonService(siteUser, db);
     WeightingViewModel model = new WeightingViewModel();
     FillDropDowns(model);
     return View(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);
 }
 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 static ReportFilterViewModel PopulateReportFilterViewModel(FilterParameter filterParameter, ModelServices modelService, SiteUser siteUser)
 {
     string defaultText = "All";
     var reportFilterViewModel = new ReportFilterViewModel();
     reportFilterViewModel.TeacherName = modelService.GetUserNameByUserId(filterParameter.Teacher);
     reportFilterViewModel.ClassName = filterParameter.ClassId != -1 ? modelService.GetClassDesc(filterParameter.ClassId) : defaultText;
     reportFilterViewModel.Race = (filterParameter.Race == -1) ? defaultText : modelService.GetRaceDesc(filterParameter.Race);
     reportFilterViewModel.Gender = (filterParameter.Gender == -1) ? defaultText : modelService.GetGenderDesc(filterParameter.Gender);
     //TODO: till now first record with district name and Id is picked up. Need to refactor if user belongs to multiple district. 
     reportFilterViewModel.DistrictName = siteUser.Districts.First().Name;
     reportFilterViewModel.IsAdmin = HelperService.AllowUiEdits(siteUser.RoleDesc, "REPORT");
     reportFilterViewModel.DisplayAdminFilters = DecideFilterDisplay(filterParameter);
     reportFilterViewModel.FrlIndicator = filterParameter.FrlIndicator;
     reportFilterViewModel.LepIndicator = filterParameter.LEPIndicator;
     reportFilterViewModel.IepIndicator = filterParameter.IEPIndicator;
     reportFilterViewModel.Hispanic = filterParameter.Hispanic;
     reportFilterViewModel.SchoolYear = filterParameter.SchoolYear;
     return reportFilterViewModel;
 }
 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");
     }
 }
 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;
     }
 }
        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 ClassService(SiteUser siteUser, dbTIREntities db)
 {
     _db = db;
     _siteUser = siteUser;
 }
 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 StudentService(SiteUser siteUser, dbTIREntities db)
 {
     _db = db;
     _siteUser = siteUser;
 }
 private void AssignMePercentForAssessment(HeirarchicalScoreData scoreData, ModelServices service, SiteUser su, TIRDetailReportParameter detailReportParameter, ref List<AssessmentMEPerc> AssessmentMePercentages)
 {
     if (scoreData != null)
     {
         detailReportParameter.AssessmentTypeId = scoreData.AssessmentTypeId;
         var mePercentForAssessment = service.GetMEPercentForAssessment(su.Districts.First().Id, scoreData.AssessmentId, detailReportParameter);
         AssessmentMePercentages.Add(mePercentForAssessment);
     }
 }
 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;

        }
        /// <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;
        }
 public SchoolService(SiteUser siteUser, dbTIREntities db)
 {
     _siteUser = siteUser;
     _db = db;
 }
        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 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");
            }
        }
 private void FillDropDowns(WeightingViewModel model)
 {
     siteUser = ((SiteUser)Session["SiteUser"]);
     commonService = new CommonService(siteUser, db);
     model.AssessmentTypes = commonService.GetAssessmentType();
     model.Subjects = commonService.GetSubjects();
     model.SchoolYears = commonService.GetSchoolYear();
     model.Districts = commonService.GetDistrict();
 }
 public AssessmentScoreService(SiteUser siteUser, dbTIREntities db)
 {
     _db = db;
     _siteUser = siteUser;
 }
 public KnowledgeBaseService(SiteUser siteUser, dbTIREntities db)
 {
     _siteUser = siteUser;
     _db = db;
 }
        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);
        }
 private void FillDropDowns(AssessmentScoreViewModel model)
 {
     siteUser = ((SiteUser)Session["SiteUser"]);
     commonService = new CommonService(siteUser, db);
     assScoreService = new AssessmentScoreService(siteUser, db);
     model.AssessmentTypes = commonService.GetAssessmentType();
     model.SchoolYears = commonService.GetSchoolYear();
     model.SchoolTerms = commonService.GetSchoolTerm();
 }
 public SupportService(SiteUser siteUser, dbTIREntities db)
 {
     _siteUser = siteUser;
     _db = db;
 }
 public WeightingService(SiteUser siteUser, dbTIREntities db)
 {
     _db = db;
     _siteUser = siteUser;
 }