Esempio n. 1
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            model.UserName = Server.HtmlEncode(model.UserName);
            model.Password = Server.HtmlEncode(model.Password);
            string name = null;
            //try
            //{
            //    name = Membership.GetUser(model.UserName).ToString();
            //}
            //catch (Exception e)
            //{
            //    // if (string.IsNullOrEmpty(name))
            //    // {
            //    name = "8080";
            //    // }
            //}
            if (ModelState.IsValid)
            {
                bool value = false;
                try
                {
                    value = Membership.GetUser(model.UserName).IsOnline;
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                    return View();
                }

                //A user is considered online if the current date and
                // time minus the UserIsOnlineTimeWindow property value is
                // earlier than the LastActivityDate for the user.
               // if (value && name != "5000001")
                 if (false)
                {

                    //if (DateTime.UtcNow.AddMinutes(-(Membership.UserIsOnlineTimeWindow)) < Membership.GetUser(model.UserName).LastActivityDate)
                    {
                        ModelState.AddModelError("", "You have Logged-In in another System, Log-Out and try again");

                    }

                    //  (DateTime -)
                    // if (User.Identity.IsAu(value == true)
                    // return RedirectToAction("Login", "Account");
                    //  ModelState.AddModelError("", "You have Logged-In in another System, Log-Out and try again");
                }
                else
                {

                    if (Membership.ValidateUser(model.UserName, model.Password))
                    {

                        FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                        if (Url.IsLocalUrl(returnUrl))
                        {
                            string con = System.Configuration.ConfigurationManager.ConnectionStrings["sdDatabase"].ConnectionString;
                            SqlConnection conn = new System.Data.SqlClient.SqlConnection(con);
                            SqlCommand updateCmd = new SqlCommand("UPDATE Users " +
                      "SET LastActivityDate = @LastActivityDate " +
                      "WHERE UserName = @UserName", conn);
                            // TimeZoneInfo.ConvertTimeToUtc(DateTime.Now)  DateTime.UtcNow.AddMinutes(-10);
                            updateCmd.Parameters.Add("@LastActivityDate", SqlDbType.DateTime).Value = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).AddMinutes(-10);
                            updateCmd.Parameters.Add("@UserName", SqlDbType.VarChar, 255).Value = User.Identity.Name;
                            //updateCmd.Parameters.Add("@ApplicationName", SqlDbType.VarChar, 255).Value = m_ApplicationName;
                            conn.Open();
                            updateCmd.ExecuteNonQuery();
                            conn.Close();
                            return Redirect(returnUrl);
                        }
                        else
                        {
                            string con = System.Configuration.ConfigurationManager.ConnectionStrings["sdDatabase"].ConnectionString;
                            SqlConnection conn = new System.Data.SqlClient.SqlConnection(con);
                            SqlCommand updateCmd = new SqlCommand("UPDATE Users " +
                      "SET LastActivityDate = @LastActivityDate " +
                      "WHERE UserName = @UserName", conn);
                            // TimeZoneInfo.ConvertTimeToUtc(DateTime.Now)  DateTime.UtcNow.AddMinutes(-10);
                            updateCmd.Parameters.Add("@LastActivityDate", SqlDbType.DateTime).Value = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).AddMinutes(-10);
                            updateCmd.Parameters.Add("@UserName", SqlDbType.VarChar, 255).Value = User.Identity.Name;
                            //updateCmd.Parameters.Add("@ApplicationName", SqlDbType.VarChar, 255).Value = m_ApplicationName;
                            conn.Open();
                            updateCmd.ExecuteNonQuery();
                            conn.Close();

                            SilverDaleSchools.DAL.UnitOfWork work = new SilverDaleSchools.DAL.UnitOfWork();
                            string UserName = model.UserName;
                            Session["UserName"] = UserName;
                            List<SilverDaleSchools.Model.MyRole> theRole = null;
                            List<SilverDaleSchools.Model.Person> thePerson = null;
                            SilverDaleSchools.Model.Person theRealPerson = null;

                            List<SilverDaleSchools.Model.Staff> theS = null;
                            List<SilverDaleSchools.Model.Student> theStu = null;

                            theS = work.StaffRepository.Get(a => a.UserID == UserName).ToList();
                            theStu = work.StudentRepository.Get(a => a.UserID == UserName).ToList();
                           // SilverDaleSchools.Model.Parent theRealParent = null;
                           // SilverDaleSchools.Model.SecondarySchoolStudent theRealSecondarySchoolStudent = null;
                            SilverDaleSchools.Model.Student theRealPrimarySchoolStudent = null;
                            if (UserName != "")
                            {
                               // int userName = Convert.ToInt32(UserName);
                               //// List<Parent> theP1 = work.ParentRepository.Get(a => a.UserID == userName).ToList();
                               // //Parent theR = theP1[0];
                               // // MembershipUser user = Membership.GetUser(Convert.ToString(UserName), false); ;
                               // // MembershipUserCollection theUser =   Membership.FindUsersByName(UserName);
                               // //MembershipUser k =  theUser[0];
                               // if (theP1.Count() != 0)
                               // //if (user..IsInRole("Parent"))
                               // {
                               //     //  int userName = Convert.ToInt32(UserName); ;
                               //     List<Parent> theP = work.ParentRepository.Get(a => a.UserID == userName).ToList();
                               //     theRealParent = theP[0];
                               //     Session["theRealParent"] = theRealParent;
                               //     theRole = work.MyRoleRepository.Get(a => a.RoleName.Equals(theRealParent.Role)).ToList();

                               //     Session["theRole"] = theRole;
                              //  }
                              //  else
                              //  {
                                  //  int UserNameInt = Convert.ToInt32(UserName);

                                //if ((theRealPerson is SilverDaleSchools.Model.Staff))

                               if( theS.Count > 0)
                                {
                                    List<Staff> theStaff = new List<Staff>();
                                    theStaff = work.StaffRepository.Get(a => a.UserID == UserName).ToList();
                                    theRealPerson = theStaff[0];
                                    Session["theRealPerson"] = theRealPerson;
                                }

                               // if ((theRealPerson is SilverDaleSchools.Model.Student))
                               if (theStu.Count > 0)
                                {
                                    List<Student> theStudent = new List<Student>();
                                    theStudent = work.StudentRepository.Get(a => a.UserID == UserName).ToList();
                                    theRealPerson = theStudent[0];
                                    Session["theRealPerson"] = theRealPerson;
                                }
                                    //thePerson = work.PersonRepository.Get(a => a.UserID == UserName).ToList();
                                    //theRealPerson = thePerson[0];
                                    //Session["theRealPerson"] = theRealPerson;

                                    theRole = work.MyRoleRepository.Get(a => a.RoleName.Equals(theRealPerson.Role)).ToList();

                                    Session["theRole"] = theRole;
                                  //  if (!(theRealPerson is SilverDaleSchools.Model.Staff))
                                    if (theStu.Count > 0)
                                    {
                                      Student theStudent = (Student)  theRealPerson;

                                        theRealPrimarySchoolStudent = work.StudentRepository.GetByID(theStudent.StudentID);

                                        Session["theRealPrimarySchoolStudent"] = work.StudentRepository.GetByID(theStudent.StudentID);
                                    }
                                }
                            //}

                            return RedirectToAction("Index", "Home");

                        }

                    }
                    else
                    {
                        string con = System.Configuration.ConfigurationManager.ConnectionStrings["sdDatabase"].ConnectionString;
                        SqlConnection conn = new System.Data.SqlClient.SqlConnection(con);
                        SqlCommand updateCmd = new SqlCommand("UPDATE Users " +
                  "SET LastActivityDate = @LastActivityDate " +
                  "WHERE UserName = @UserName", conn);
                        // TimeZoneInfo.ConvertTimeToUtc(DateTime.Now)  DateTime.UtcNow.AddMinutes(-10);
                        updateCmd.Parameters.Add("@LastActivityDate", SqlDbType.DateTime).Value = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).AddMinutes(-10);
                        updateCmd.Parameters.Add("@UserName", SqlDbType.VarChar, 255).Value = Membership.GetUser(model.UserName).UserName;
                        //updateCmd.Parameters.Add("@ApplicationName", SqlDbType.VarChar, 255).Value = m_ApplicationName;
                        conn.Open();
                        updateCmd.ExecuteNonQuery();
                        conn.Close();
                        ModelState.AddModelError("", "The user name or password provided is incorrect.");
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Esempio n. 2
0
        public async Task Read(string fileExtension, HttpPostedFileBase theFile)
        {

            try
            {
                UnitOfWork work = new UnitOfWork();

                List<Student> theStudentList = new List<Student>();




                IExcelDataReader excelReader = null;
                if ((fileExtension.EndsWith(".xlsx")))
                {
                    //2. Reading from a OpenXml Excel file (2007 format; *.xlsx)
                    excelReader = ExcelReaderFactory.CreateOpenXmlReader(theFile.InputStream);
                }

                if ((fileExtension.EndsWith(".xls")))
                {

                    //1. Reading from a binary Excel file ('97-2003 format; *.xls)
                    excelReader = ExcelReaderFactory.CreateBinaryReader(theFile.InputStream);
                }
                // ExcelDataReader reader = new ExcelDataReader(ExcelFileUpload.PostedFile.InputStream);

                /// FileStream stream = File.Open(Request.Files[0], FileMode.Open, FileAccess.Read);


                //...

                //...
                //3. DataSet - The result of each spreadsheet will be created in the result.Tables
                DataSet result = excelReader.AsDataSet();
                //  ...
                //4. DataSet - Create column names from first row
                excelReader.IsFirstRowAsColumnNames = true;
                DataSet result2 = excelReader.AsDataSet();

                //5. Data Reader methods
                int counter = 0;
                while (excelReader.Read())
                {

                    if (counter > 0)
                    {

                        Result theNewResult = new Result();

                        try
                        {
                            if (!string.IsNullOrEmpty(excelReader.GetString(0)) && !string.IsNullOrEmpty(excelReader.GetString(1)) && !string.IsNullOrEmpty(excelReader.GetString(2)))
                            {

                                theStudentList.Add(new Student
                                {
                                    //  UserID = theString,
                                    UserID = (excelReader.GetString(0)),
                                    LastName = excelReader.GetString(1),
                                    FirstName = excelReader.GetString(2),
                                    Middle = excelReader.GetString(3),
                                    Sex = excelReader.GetString(4),

                                    PhoneNumber = excelReader.GetString(5),
                                    EmailAddress = excelReader.GetString(6),

                                    Address = excelReader.GetString(7),
                                    ParentName = excelReader.GetString(8),
                                    ParentAddress = excelReader.GetString(9),
                                    ParentPhoneNumber = excelReader.GetString(10),
                                    LGAName = excelReader.GetString(11),
                                    StateName = excelReader.GetString(12),
                                    CountryName = excelReader.GetString(13),
                                    LocalLanguageName = excelReader.GetString(14),
                                    Role = "Student",


                                });
                            }


                        }
                        catch (Exception e)
                        {

                        }




                    }





                    counter = counter + 1;
                }

                foreach (Student s in theStudentList)
                {

                    try
                    {
                        List<Student> theStudent = work.StudentRepository.Get().Where(a => a.UserID == s.UserID).ToList();//(s.UserID).ToList();
                        if (Membership.GetUser(s.UserID.ToString()) == null && theStudent.Count() == 0 && !(string.IsNullOrEmpty(s.UserID)))
                        {
                            work.StudentRepository.Insert(s);
                            if (string.IsNullOrEmpty(s.EmailAddress))
                            {
                                s.EmailAddress = "*****@*****.**";
                            }
                            Membership.CreateUser(s.UserID.ToString(), PaddPassword.Padd(s.LastName), s.EmailAddress);
                            Roles.AddUserToRole(s.UserID.ToString(), s.Role);
                            Tweaker.AdjustTimer(s.UserID.ToString());
                            //  work.StudentRepository.Insert(s);
                            //  work.Save();
                        }
                    }

                    catch(Exception e)
                    {

                    }
                   
                }
                work.Save();

            }

            catch (Exception e)
            {


            }


        }
        public List<string> StructureWieghtAveSecondTerm(Result theResult)
        {
            UnitOfWork work = new UnitOfWork();
            string theTerm = theResult.Term;
            List<Result> secondSemeterResult = new List<Result>();

            //if (theTerm == "3")
            //{
            //  secondSemeterResult =  work.ResultRepository.Get(a => a.Session == theResult.Session && a.Term == "2" && theResult.StudentNo == theResult.StudentNo).ToList();
            //}

            if (theTerm == "2")
            {
                secondSemeterResult = work.ResultRepository.Get(a => a.Session == theResult.Session && a.StudentNo == theResult.StudentNo && a.Class == theResult.Class && a.Term == "1" && theResult.StudentNo == theResult.StudentNo).ToList();
            }

            if (secondSemeterResult.Count == 0)
            {
                if (theResult.EnglishLanguage_Attendance > 0)
                {

                    // StructureWieghtAve
                    theStudentAveweight.Add(theResult.EnglishLanguage_TotalScore.ToString());
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.Mathematics_Attendance > 0)
                {
                    theStudentAveweight.Add(theResult.Mathematics_TotalScore.ToString());
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.Biology_Attendance > 0)
                {
                    theStudentAveweight.Add(theResult.Biology_TotalScore.ToString());
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.Physics_Attendance > 0)
                {
                    theStudentAveweight.Add(theResult.Physics_TotalScore.ToString());
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.Chemistry_Attendance > 0)
                {
                    theStudentAveweight.Add(theResult.Chemistry_TotalScore.ToString());
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.Yoruba_Attendance > 0)
                {
                    theStudentAveweight.Add(theResult.Yoruba_TotalScore.ToString());
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.ChristianReligiousKnowledge_Attendance > 0)
                {
                    theStudentAveweight.Add(theResult.ChristianReligiousKnowledge_TotalScore.ToString());
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.Geography_Attendance > 0)
                {
                    theStudentAveweight.Add(theResult.Geography_TotalScore.ToString());
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.AgriculturalScience_Attendance > 0)
                {
                    theStudentAveweight.Add(theResult.AgriculturalScience_TotalScore.ToString());
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.FoodandNutrition_Attendance > 0)
                {
                    theStudentAveweight.Add(theResult.FoodandNutrition_TotalScore.ToString());
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.Economics_Attendance > 0)
                {
                    theStudentAveweight.Add(theResult.Economics_TotalScore.ToString());
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.French_Attendance > 0)
                {
                    theStudentAveweight.Add(theResult.French_TotalScore.ToString());
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.CivicEducation_Attendance > 0)
                {
                    theStudentAveweight.Add(theResult.CivicEducation_TotalScore.ToString());
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.Computer_Attendance > 0)
                {
                    theStudentAveweight.Add(theResult.Computer_TotalScore.ToString());
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.LiteratureinEnglish_Attendance > 0)
                {
                    theStudentAveweight.Add(theResult.LiteratureinEnglish_TotalScore.ToString());
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.FurtherMathematics_Attendance > 0)
                {
                    theStudentAveweight.Add(theResult.FurtherMathematics_TotalScore.ToString());
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.Commerce_Attendance > 0)
                {
                    theStudentAveweight.Add(theResult.Commerce_TotalScore.ToString());
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.RoyalEnglish_Attendance > 0)
                {
                    theStudentAveweight.Add(theResult.RoyalEnglish_TotalScore.ToString());
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.FinancialAccounting_Attendance > 0)
                {
                    theStudentAveweight.Add(theResult.FinancialAccounting_TotalScore.ToString());
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.Government_Attendance > 0)
                {
                    theStudentAveweight.Add(theResult.Government_TotalScore.ToString());
                }
                else
                {
                    theStudentAveweight.Add("");
                }
                if (theResult.TechnicalDrawing_Attendance > 0)
                {
                    theStudentAveweight.Add(theResult.TechnicalDrawing_TotalScore.ToString());
                }
                else
                {
                    theStudentAveweight.Add("");
                }
                return theStudentAveweight;
            }
            else
            {

                Result thePastResult = secondSemeterResult[0];

                if (theResult.EnglishLanguage_Attendance > 0)
                {

                    // StructureWieghtAve
                    theStudentAveweight.Add((((theResult.EnglishLanguage_TotalScore + thePastResult.EnglishLanguage_TotalScore) / 2).ToString()));
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.Mathematics_Attendance > 0)
                {
                    theStudentAveweight.Add((((theResult.Mathematics_TotalScore + thePastResult.Mathematics_TotalScore) / 2).ToString()));
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.Biology_Attendance > 0)
                {
                    theStudentAveweight.Add((((theResult.Biology_TotalScore + thePastResult.Biology_TotalScore) / 2).ToString()));
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.Physics_Attendance > 0)
                {
                    theStudentAveweight.Add((((theResult.Physics_TotalScore + thePastResult.Physics_TotalScore) / 2).ToString()));
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.Chemistry_Attendance > 0)
                {
                    theStudentAveweight.Add((((theResult.Chemistry_TotalScore + thePastResult.Chemistry_TotalScore) / 2).ToString()));
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.Yoruba_Attendance > 0)
                {
                    theStudentAveweight.Add((((theResult.Yoruba_TotalScore + thePastResult.Yoruba_TotalScore) / 2).ToString()));
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.ChristianReligiousKnowledge_Attendance > 0)
                {
                    theStudentAveweight.Add((((theResult.ChristianReligiousKnowledge_TotalScore + thePastResult.ChristianReligiousKnowledge_TotalScore) / 2).ToString()));
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.Geography_Attendance > 0)
                {
                    theStudentAveweight.Add((((theResult.Geography_TotalScore + thePastResult.Geography_TotalScore) / 2).ToString()));
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.AgriculturalScience_Attendance > 0)
                {
                    theStudentAveweight.Add((((theResult.AgriculturalScience_TotalScore + thePastResult.AgriculturalScience_TotalScore) / 2).ToString()));
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.FoodandNutrition_Attendance > 0)
                {
                    theStudentAveweight.Add((((theResult.FoodandNutrition_TotalScore + thePastResult.FoodandNutrition_TotalScore) / 2).ToString()));
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.Economics_Attendance > 0)
                {
                    theStudentAveweight.Add((((theResult.Economics_TotalScore + thePastResult.Economics_TotalScore) / 2).ToString()));
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.French_Attendance > 0)
                {
                    theStudentAveweight.Add((((theResult.French_TotalScore + thePastResult.French_TotalScore) / 2).ToString()));
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.CivicEducation_Attendance > 0)
                {
                    theStudentAveweight.Add((((theResult.CivicEducation_TotalScore + thePastResult.CivicEducation_TotalScore) / 2).ToString()));
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.Computer_Attendance > 0)
                {
                    theStudentAveweight.Add((((theResult.Computer_TotalScore + thePastResult.Computer_TotalScore) / 2).ToString()));
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.LiteratureinEnglish_Attendance > 0)
                {
                    theStudentAveweight.Add((((theResult.LiteratureinEnglish_TotalScore + thePastResult.LiteratureinEnglish_TotalScore) / 2).ToString()));
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.FurtherMathematics_Attendance > 0)
                {
                    theStudentAveweight.Add((((theResult.FurtherMathematics_TotalScore + thePastResult.FurtherMathematics_TotalScore) / 2).ToString()));
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.Commerce_Attendance > 0)
                {
                    theStudentAveweight.Add((((theResult.Commerce_TotalScore + thePastResult.Commerce_TotalScore) / 2).ToString()));
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.RoyalEnglish_Attendance > 0)
                {
                    theStudentAveweight.Add((((theResult.RoyalEnglish_TotalScore + thePastResult.RoyalEnglish_TotalScore) / 2).ToString()));
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.FinancialAccounting_Attendance > 0)
                {
                    theStudentAveweight.Add((((theResult.FinancialAccounting_TotalScore + thePastResult.FinancialAccounting_TotalScore) / 2).ToString()));
                }
                else
                {
                    theStudentAveweight.Add("");
                }

                if (theResult.Government_Attendance > 0)
                {
                    theStudentAveweight.Add((((theResult.Government_TotalScore + thePastResult.Government_TotalScore) / 2).ToString()));
                }
                else
                {
                    theStudentAveweight.Add("");
                }
                if (theResult.TechnicalDrawing_Attendance > 0)
                {
                    theStudentAveweight.Add((((theResult.TechnicalDrawing_TotalScore + thePastResult.TechnicalDrawing_TotalScore) / 2).ToString()));
                }
                else
                {
                    theStudentAveweight.Add("");
                }
                return theStudentAveweight;
            }
        }
Esempio n. 4
0
        public ActionResult Edit(Staff model)
        {
            try
            {
                // TODO: Add update logic here
                UnitOfWork work2 = new UnitOfWork();
                Staff staff = work2.StaffRepository.GetByID(model.StaffID);
                string[] RoleList = Roles.GetAllRoles();
                //  Roles.RemoveUserFromRoles(model.UserID.ToString(), RoleList);
                foreach (var role in RoleList)
                {
                    if (Roles.IsUserInRole(model.UserID.ToString(), role))
                    {
                        Roles.RemoveUserFromRole(model.UserID.ToString(), role);
                    }
                }
                Roles.AddUserToRole(model.UserID.ToString(), model.Role);
                // work.StaffRepository.Update(model);

                SilverDaleSchools.Models.Tweaker.AdjustTimer(model.UserID.ToString());
                TryUpdateModel(model);
                if (ModelState.IsValid)
                {
                    work.StaffRepository.Update(model);
                    work.Save();
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        //UnitOfWork work = new UnitOfWork();
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            Membership.GetUser(true);
            UnitOfWork work = new UnitOfWork();
            Roles = null;
            string UserName = "";
            int UserNameInt;
            List<Person> thePerson;
            List<Student> theStudent;
            List<Staff> theStaff;
               // List<Parent> theParent;
            Person theRealPerson = new Person();
               // Parent theRealParent = new Parent();
            string theControllerName = "";
            string theActionName = "";
            dynamic controllerName ="";
            dynamic actionName ="";
            List<MyRole> theRole = new List<MyRole>();
            try
            {

                controllerName = httpContext.Request.RequestContext.RouteData.Values["controller"];
                theControllerName = Convert.ToString(controllerName);
                string originalController = Convert.ToString(controllerName);

                //
                UserName = httpContext.User.Identity.Name;
               // UserNameInt = Convert.ToInt32(UserName);

                try
                {
                   theStudent =work.StudentRepository.Get(a => a.UserID == UserName).ToList();
                   theStaff = work.StaffRepository.Get(a => a.UserID == UserName).ToList();

                   if (theStudent.Count > 0)
                   {
                       theRealPerson = theStudent[0];
                   }

                   if (theStaff.Count > 0)
                   {
                       theRealPerson = theStaff[0];
                   }

                   // thePerson = work.PersonRepository.Get(a => a.UserID == UserName).ToList();
                   // theRealPerson = thePerson[0];
                    theControllerName = Convert.ToString(controllerName);
                    actionName = httpContext.Request.RequestContext.RouteData.Values["action"];
                    theActionName = Convert.ToString(actionName);
                    theRole = work.MyRoleRepository.Get(a => a.RoleName.Equals(theRealPerson.Role)).ToList();
                }
                catch
                {
                    //theParent = work.ParentRepository.Get(a => a.UserID == UserNameInt).ToList();
                    //theRealParent = theParent[0];
                    //theControllerName = Convert.ToString(controllerName);
                    //actionName = httpContext.Request.RequestContext.RouteData.Values["action"];
                    //theActionName = Convert.ToString(actionName);
                    //theRole = work.MyRoleRepository.Get(a => a.RoleName.Equals(theRealParent.Role)).ToList();
                }

                if (theControllerName.Contains("Upload"))
                {
                    theControllerName = "UploadLessonNote";
                }

                if (theControllerName.Contains("ReadContent"))
                {
                    theControllerName = "UploadLessonNote";
                }

                if (theControllerName.Contains("Chapter"))
                {
                    theControllerName = "UploadLessonNote";
                }
                // Get this string (roles) from a database or somewhere dynamic using the controllerName and actionName
                //Roles = "Role1,Role2,Role3"; // i.e.  GetRolesFromDatabase(controllerName, actionName);
               // List<MyRole> theRole = work.MyRoleRepository.Get(a => a.RoleName.Equals(theRealPerson.Role)).ToList();

                switch (theControllerName)
                {
                      //  if(theControllerName.Contains("Upload"))

                    case "UploadLessonNote":
                        string[] activities50 = {"-"};
                        if (!(String.IsNullOrEmpty( theRole[0].Material)))
                        {
                          //  activities50.em
                            activities50 = theRole[0].Material.Split('-');
                        }

                        List<string> activityList50 = new List<string>();
                        foreach (var activity in activities50)
                        {
                            if (activity.Equals("List"))//|| activity.Equals("StudentView"))
                            {
                                activityList50.Add("Index");
                            }
                            else
                            {
                                activityList50.Add(activity);
                            }

                        }

                        // activityList.Add(activities);
                        foreach (var activity in activityList50)
                        {
                            //DeleteChapter
                            if (activity == "Delete")
                            {
                                if (actionName == "DeleteChapter")
                                {
                                    Roles = theRole[0].RoleName;
                                    return base.AuthorizeCore(httpContext);
                                }

                            }
                            if (activity == "Edit" || activity == "Index")
                            {
                                if (actionName == "Edit")
                                {
                                    Roles = theRole[0].RoleName;
                                    return base.AuthorizeCore(httpContext);
                                }

                                if (actionName == "Index")
                                {
                                    Roles = theRole[0].RoleName;
                                    return base.AuthorizeCore(httpContext);
                                }
                            }
                            else
                            {
                                if (activity.Equals(actionName))
                                {
                                    Roles = theRole[0].RoleName;
                                    return base.AuthorizeCore(httpContext);
                                }
                            }
                        }

                        //if (!(string.IsNullOrEmpty( originalController)))
                        //{

                        //}
                        break;

                    case "Question":

                        string[] activities39 = theRole[0].OnlineExam.Split('-');
                        List<string> activityList39 = new List<string>();
                        foreach (var activity in activities39)
                        {
                            if (activity.Equals("List"))
                            {
                                activityList39.Add("Index");
                            }
                            else
                            {
                                activityList39.Add(activity);
                            }

                        }

                        // activityList.Add(activities);
                        foreach (var activity in activityList39)
                        {
                            if (activity == "Index")
                            {
                                //if (actionName == "LoadExamCodes")
                                //{
                                //    Roles = theRole[0].RoleName;
                                //    return base.AuthorizeCore(httpContext);
                                //}
                                if (actionName == "Index")
                                {
                                    Roles = theRole[0].RoleName;
                                    return base.AuthorizeCore(httpContext);
                                }
                            }
                            else
                            {
                                if (activity.Equals(actionName))
                                {
                                    Roles = theRole[0].RoleName;
                                    return base.AuthorizeCore(httpContext);
                                }
                            }
                        }

                        break;

                    case "Order":

                        string[] activities38 = theRole[0].StudentStoreItem.Split('-');
                        List<string> activityList38 = new List<string>();
                        foreach (var activity in activities38)
                        {
                            if (activity.Equals("List"))//|| activity.Equals("StudentView"))
                            {
                                activityList38.Add("Index");
                            }
                            else
                            {
                                activityList38.Add(activity);
                            }

                        }

                        // activityList.Add(activities);
                        foreach (var activity in activityList38)
                        {
                            if (activity == "Edit" || activity == "Index")
                            {
                                if (actionName == "Edit")
                                {
                                    Roles = theRole[0].RoleName;
                                    return base.AuthorizeCore(httpContext);
                                }

                                if (actionName == "Index")
                                {
                                    Roles = theRole[0].RoleName;
                                    return base.AuthorizeCore(httpContext);
                                }
                            }
                            else
                            {
                                if (activity.Equals(actionName))
                                {
                                    Roles = theRole[0].RoleName;
                                    return base.AuthorizeCore(httpContext);
                                }
                            }
                        }

                        break;
                    case "StudentStoreItem":

                        string[] activities37 = theRole[0].StudentStoreItem.Split('-');
                        List<string> activityList37 = new List<string>();
                        foreach (var activity in activities37)
                        {
                            if (activity.Equals("List"))//|| activity.Equals("StudentView"))
                            {
                                activityList37.Add("Index");
                            }
                            else
                            {
                                activityList37.Add(activity);
                            }

                        }

                        // activityList.Add(activities);
                        foreach (var activity in activityList37)
                        {
                            if (activity == "Edit" || activity == "Index")
                            {
                                if (actionName == "Edit")
                                {
                                    Roles = theRole[0].RoleName;
                                    return base.AuthorizeCore(httpContext);
                                }

                                if (actionName == "Index")
                                {
                                    Roles = theRole[0].RoleName;
                                    return base.AuthorizeCore(httpContext);
                                }
                            }
                            else
                            {
                                if (activity.Equals(actionName))
                                {
                                    Roles = theRole[0].RoleName;
                                    return base.AuthorizeCore(httpContext);
                                }
                            }
                        }

                        break;
                    case "SchoolFeePayment":

                        string[] activities36 = theRole[0].SchoolFeePayment.Split('-');
                        List<string> activityList36 = new List<string>();
                        foreach (var activity in activities36)
                        {
                            if (activity.Equals("List"))//|| activity.Equals("StudentView"))
                            {
                                activityList36.Add("Index");
                            }
                            else
                            {
                                activityList36.Add(activity);
                            }

                        }

                        // activityList.Add(activities);
                        foreach (var activity in activityList36)
                        {
                            if (activity == "Index")
                            {
                                if (actionName == "ViewFeeForStudent")//
                                {
                                    Roles = theRole[0].RoleName;
                                    return base.AuthorizeCore(httpContext);
                                }
                                if (actionName == "ViewYourFees")//ViewYourFees
                                {
                                    Roles = theRole[0].RoleName;
                                    return base.AuthorizeCore(httpContext);
                                }
                                if (actionName == "Index")
                                {
                                    Roles = theRole[0].RoleName;
                                    return base.AuthorizeCore(httpContext);
                                }
                            }
                            else
                            {
                                if (activity.Equals(actionName))
                                {
                                    Roles = theRole[0].RoleName;
                                    return base.AuthorizeCore(httpContext);
                                }
                            }
                        }

                        break;
                    case "OrderItem":

                        string[] activities35 = theRole[0].OrderItem.Split('-');
                        List<string> activityList35 = new List<string>();
                        foreach (var activity in activities35)
                        {
                            if (activity.Equals("List"))
                            {
                                activityList35.Add("Index");
                            }
                            else
                            {
                                activityList35.Add(activity);
                            }

                        }

                        // activityList.Add(activities);
                        foreach (var activity in activityList35)
                        {
                            if (activity.Equals(actionName))
                            {
                                Roles = theRole[0].RoleName;
                                return base.AuthorizeCore(httpContext);
                            }
                        }

                        break;

                    case "Result":

                        string[] activities40 = theRole[0].Result.Split('-');
                        List<string> activityList40 = new List<string>();
                        foreach (var activity in activities40)
                        {
                            if (activity.Equals("List"))
                            {
                                activityList40.Add("Index");
                            }
                            else
                            {
                                activityList40.Add(activity);
                            }

                        }

                        // activityList.Add(activities);
                        foreach (var activity in activityList40)
                        {
                            if (activity.Equals(actionName))
                            {
                                Roles = theRole[0].RoleName;
                                return base.AuthorizeCore(httpContext);
                            }
                        }

                        break;

                    case "AttendanceStaff":

                        string[] activities34 = theRole[0].Attendance.Split('-');
                        List<string> activityList34 = new List<string>();
                        foreach (var activity in activities34)
                        {
                            if (activity.Equals("List")) //|| activity.Equals("StaffView"))
                            {
                                activityList34.Add("Index");
                              //  activityList34.Add("Index");
                            }
                            //if (activity.Equals("StaffView"))
                            //{
                            //    activityList34.Add("Index");
                            //    //  activityList34.Add("Index");
                            //}
                            else
                            {
                                activityList34.Add(activity);
                            }

                        }

                        // activityList.Add(activities);
                        foreach (var activity in activityList34)
                        {
                            if (activity == "Index")
                            {
                                if (actionName == "StaffView")
                                {
                                    Roles = theRole[0].RoleName;
                                    return base.AuthorizeCore(httpContext);
                                }
                                if (actionName == "Index")
                                {
                                    Roles = theRole[0].RoleName;
                                    return base.AuthorizeCore(httpContext);
                                }
                            }
                            else
                            {
                                if (activity.Equals(actionName))
                                {
                                    Roles = theRole[0].RoleName;
                                    return base.AuthorizeCore(httpContext);
                                }
                            }
                        }

                        break;
                    case "Attendance":

                        string[] activities33 = theRole[0].Attendance.Split('-');
                        List<string> activityList33 = new List<string>();
                        foreach (var activity in activities33)
                        {
                            if (activity.Equals("List") )//|| activity.Equals("StudentView"))
                            {
                                activityList33.Add("Index");
                            }
                            else
                            {
                                activityList33.Add(activity);
                            }

                        }

                        // activityList.Add(activities);
                        foreach (var activity in activityList33)
                        {
                            if (activity == "Index")
                            {
                                if (actionName == "StudentView")
                                {
                                    Roles = theRole[0].RoleName;
                                    return base.AuthorizeCore(httpContext);
                                }
                                if (actionName == "Index")
                                {
                                    Roles = theRole[0].RoleName;
                                    return base.AuthorizeCore(httpContext);
                                }
                            }
                            else
                            {
                                if (activity.Equals(actionName))
                                {
                                    Roles = theRole[0].RoleName;
                                    return base.AuthorizeCore(httpContext);
                                }
                            }
                        }

                        break;
                    case "Post":

                        string[] activities32 = theRole[0].Post.Split('-');
                        List<string> activityList32 = new List<string>();
                        foreach (var activity in activities32)
                        {
                            if (activity.Equals("List"))
                            {
                                activityList32.Add("Index");
                            }
                            else
                            {
                                activityList32.Add(activity);
                            }

                        }

                        // activityList.Add(activities);
                        foreach (var activity in activityList32)
                        {
                            if (activity.Equals(actionName))
                            {
                                Roles = theRole[0].RoleName;
                                return base.AuthorizeCore(httpContext);
                            }
                        }

                        break;
                    case "BulkSMS":

                        string[] activities31 = theRole[0].BulkSMS.Split('-');
                        List<string> activityList31 = new List<string>();
                        foreach (var activity in activities31)
                        {
                            if (activity.Equals("List"))
                            {
                                activityList31.Add("Index");
                            }
                            else
                            {
                                activityList31.Add(activity);
                            }

                        }

                        // activityList.Add(activities);
                        foreach (var activity in activityList31)
                        {
                            if (activity.Equals(actionName))
                            {
                                Roles = theRole[0].RoleName;
                                return base.AuthorizeCore(httpContext);
                            }
                        }

                        break;

                    case "Parent":

                        string[] activities30 = theRole[0].TimeTable.Split('-');
                        List<string> activityList30 = new List<string>();
                        foreach (var activity in activities30)
                        {
                            if (activity.Equals("List"))
                            {
                                activityList30.Add("Index");
                            }
                            else
                            {
                                activityList30.Add(activity);
                            }

                        }

                        // activityList.Add(activities);
                        foreach (var activity in activityList30)
                        {
                            if (activity.Equals(actionName))
                            {
                                Roles = theRole[0].RoleName;
                                return base.AuthorizeCore(httpContext);
                            }
                        }

                        break;

                    case "TimeTable":

                        string[] activities23 = theRole[0].TimeTable.Split('-');
                        List<string> activityList23 = new List<string>();
                        foreach (var activity in activities23)
                        {
                            if (activity.Equals("List"))
                            {
                                activityList23.Add("Index");
                            }
                            else
                            {
                                activityList23.Add(activity);
                            }

                        }

                        // activityList.Add(activities);
                        foreach (var activity in activityList23)
                        {
                            if (activity.Equals(actionName))
                            {
                                Roles = theRole[0].RoleName;
                                return base.AuthorizeCore(httpContext);
                            }
                        }

                        break;

                    case "NewsBoard":

                        string[] activities24 = theRole[0].NewsBoard.Split('-');
                        List<string> activityList24 = new List<string>();
                        foreach (var activity in activities24)
                        {
                            if (activity.Equals("List"))
                            {
                                activityList24.Add("Index");
                            }
                            else
                            {
                                activityList24.Add(activity);
                            }

                        }

                        // activityList.Add(activities);
                        foreach (var activity in activityList24)
                        {
                            if (activity.Equals(actionName))
                            {
                                Roles = theRole[0].RoleName;
                                return base.AuthorizeCore(httpContext);
                            }
                        }

                        break;

                    case "OnlineExam":

                        string[] activities0 = theRole[0].OnlineExam.Split('-');
                        List<string> activityList0 = new List<string>();
                        foreach (var activity in activities0)
                        {
                            if (activity.Equals("List"))
                            {
                                activityList0.Add("Index");
                            }
                            else
                            {
                                activityList0.Add(activity);
                            }

                        }

                        // activityList.Add(activities);
                        foreach (var activity in activityList0)
                        {
                            if (activity == "Index")
                            {
                                if (actionName == "LoadExamCodes")
                                {
                                    Roles = theRole[0].RoleName;
                                    return base.AuthorizeCore(httpContext);
                                }
                                if (actionName == "Index")
                                {
                                    Roles = theRole[0].RoleName;
                                    return base.AuthorizeCore(httpContext);
                                }
                            }
                            else
                            {
                                if (activity.Equals(actionName))
                                {
                                    Roles = theRole[0].RoleName;
                                    return base.AuthorizeCore(httpContext);
                                }
                            }
                        }

                        break;

                    case "PrimarySchoolStudent":

                        string[] activities = theRole[0].Student.Split('-');
                        List<string> activityList = new List<string>();
                        //student fees
                        if (actionName == "Index3")
                        {
                            foreach (var role in theRole)
                            {
                                if (role.StudentFees != null)
                                {
                                    string[] val = role.StudentFees.Split('-');
                                    foreach (var v in val)
                                    {
                                        if (v == "Edit")
                                        {
                                            Roles = theRole[0].RoleName;
                                            return base.AuthorizeCore(httpContext);
                                            //break;
                                        }
                                    }
                                }
                            }
                        }
                        //store list
                        if (actionName == "Index2")
                        {
                            foreach (var role in theRole)
                            {
                                if (role.StudentFees != null)
                                {
                                    string[] val = role.Store.Split('-');
                                    foreach (var v in val)
                                    {
                                        if (v == "Edit")
                                        {
                                            Roles = theRole[0].RoleName;
                                            return base.AuthorizeCore(httpContext);
                                            //break;
                                        }
                                    }
                                }
                            }
                        }
                        foreach (var activity in activities)
                        {
                            if (activity.Equals("List"))
                            {
                                activityList.Add("Index");
                            }
                            else
                            {
                                activityList.Add(activity);
                            }

                        }

                        // activityList.Add(activities);
                        foreach (var activity in activityList)
                        {
                            if (activity.Equals(actionName))
                            {
                                Roles = theRole[0].RoleName;
                                return base.AuthorizeCore(httpContext);
                            }
                        }

                        break;

                    case "Exam":

                        string[] activities1 = theRole[0].Exam.Split('-');
                        List<string> activityList1 = new List<string>();
                        foreach (var activity in activities1)
                        {
                            if (activity.Equals("List"))
                            {
                                activityList1.Add("Index");
                                activityList1.Add("Create");
                            }
                            //if (activity.Equals("Create"))
                            //{
                            //    activityList1.Add("Index");
                            //}
                            else
                            {
                                activityList1.Add(activity);
                            }

                        }
                        //  roles
                        // activityList.Add(activities);
                        foreach (var activity in activityList1)
                        {
                            if (activity.Equals(actionName))
                            {
                                Roles = theRole[0].RoleName;
                                return base.AuthorizeCore(httpContext);
                            }
                        }

                        break;

                    case "Level":

                        string[] activities2 = theRole[0].Level.Split('-');
                        List<string> activityList2 = new List<string>();
                        foreach (var activity in activities2)
                        {
                            if (activity.Equals("List"))
                            {
                                activityList2.Add("Index");
                            }
                            else
                            {
                                activityList2.Add(activity);
                            }

                        }

                        // activityList.Add(activities);
                        foreach (var activity in activityList2)
                        {
                            if (activity.Equals(actionName))
                            {
                                Roles = theRole[0].RoleName;
                                return base.AuthorizeCore(httpContext);
                            }
                        }

                        break;

                    case "PrimarySchoolStaff":

                        string[] activities3 = theRole[0].Staff.Split('-');
                        List<string> activityList3 = new List<string>();
                        foreach (var activity in activities3)
                        {
                            if (activity.Equals("List"))
                            {
                                activityList3.Add("Index");
                            }
                            else
                            {
                                activityList3.Add(activity);
                            }

                        }

                        // activityList.Add(activities);
                        foreach (var activity in activityList3)
                        {
                            if (activity.Equals(actionName))
                            {
                                Roles = theRole[0].RoleName;
                                return base.AuthorizeCore(httpContext);
                            }
                        }

                        break;

                    case "Store":

                        string[] activities4 = theRole[0].Store.Split('-');
                        List<string> activityList4 = new List<string>();
                        foreach (var activity in activities4)
                        {
                            if (activity.Equals("List"))
                            {
                                activityList4.Add("Index");
                            }
                            else
                            {
                                activityList4.Add(activity);
                            }

                        }

                        // activityList.Add(activities);
                        foreach (var activity in activityList4)
                        {
                            if (activity.Equals(actionName))
                            {
                                Roles = theRole[0].RoleName;
                                return base.AuthorizeCore(httpContext);
                            }
                        }

                        break;

                    case "StudentFees":

                        string[] activities5 = theRole[0].StudentFees.Split('-');
                        List<string> activityList5 = new List<string>();
                        foreach (var activity in activities5)
                        {
                            if (activity.Equals("List"))
                            {
                                activityList5.Add("Index");
                            }
                            else
                            {
                                activityList5.Add(activity);
                            }

                        }

                        // activityList.Add(activities);
                        foreach (var activity in activityList5)
                        {
                            if (activity.Equals(actionName))
                            {
                                Roles = theRole[0].RoleName;
                                return base.AuthorizeCore(httpContext);
                            }
                        }

                        break;

                    case "Subject":

                        string[] activities6 = theRole[0].Subject.Split('-');
                        List<string> activityList6 = new List<string>();
                        foreach (var activity in activities6)
                        {
                            if (activity.Equals("List"))
                            {
                                activityList6.Add("Index");
                            }
                            else
                            {
                                activityList6.Add(activity);
                            }

                        }

                        // activityList.Add(activities);
                        foreach (var activity in activityList6)
                        {
                            if (activity.Equals(actionName))
                            {
                                Roles = theRole[0].RoleName;
                                return base.AuthorizeCore(httpContext);
                            }
                        }

                        break;

                    case "SubjectRegistration":

                        string[] activities7 = theRole[0].ClassSubject.Split('-');
                        List<string> activityList7 = new List<string>();
                        foreach (var activity in activities7)
                        {
                            if (activity.Equals("List"))
                            {
                                activityList7.Add("Index");
                            }
                            else
                            {
                                activityList7.Add(activity);
                            }

                        }

                        // activityList.Add(activities);
                        foreach (var activity in activityList7)
                        {
                            if (activity.Equals(actionName))
                            {
                                Roles = theRole[0].RoleName;
                                return base.AuthorizeCore(httpContext);
                            }
                        }

                        break;

                    case "SecondarySchoolStudent":

                        string[] activities8 = theRole[0].SecondarySchoolStudent.Split('-');
                        List<string> activityList8 = new List<string>();
                        foreach (var activity in activities8)
                        {
                            if (activity.Equals("List"))
                            {
                                activityList8.Add("Index");
                            }
                            else
                            {
                                activityList8.Add(activity);
                            }

                        }

                        // activityList.Add(activities);
                        foreach (var activity in activityList8)
                        {
                            if (activity.Equals(actionName))
                            {
                                Roles = theRole[0].RoleName;
                                return base.AuthorizeCore(httpContext);
                            }
                        }

                        break;
                }

                //work.MyRoleRepository.Get()

                Roles = "SuperAdmin"; // i.e.  GetRolesFromDatabase(controllerName, actionName);

                return base.AuthorizeCore(httpContext);
            }
            catch (Exception e)
            {

                Roles = "SuperAdmin"; // i.e.  GetRolesFromDatabase(controllerName, actionName);

                return base.AuthorizeCore(httpContext);
            }
        }