public async Task <IActionResult> LogIn(UserSelect2 user)
        {
            if (ModelState.IsValid)
            {
                var result = await signInManager.PasswordSignInAsync(user.UserName, user.Password, true, false);

                var isInRole = await userManager.IsInRoleAsync(
                    await userManager.FindByNameAsync(
                        user.UserName), "ActiveUser");

                if (result.Succeeded && isInRole)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                if (result.Succeeded && !isInRole)
                {
                    ModelState.AddModelError("", "Jesteś zablokowany!");
                }
                else
                {
                    ModelState.AddModelError("", "Nie można się zalogować!");
                }
            }

            AccountLogIn accountLogIn = new AccountLogIn()
            {
                User = user
            };

            return(View(accountLogIn));
        }
Exemplo n.º 2
0
        public bool InitialAccount(AccountLogIn account)
        {
            try
            {
                OleDbConnection connect = new OleDbConnection();
                connect.ConnectionString = conn;
                connect.Open();

                OleDbCommand cmd = new OleDbCommand();
                cmd.Connection  = connect;
                cmd.CommandText = "Insert INTO Account VALUES (?,?)";

                OleDbParameter para = cmd.Parameters.Add("", OleDbType.VarChar);
                para.Value = account.ID;

                para       = cmd.Parameters.Add("", OleDbType.VarChar);
                para.Value = account.Password;

                cmd.ExecuteNonQuery();

                connect.Close();
                return(true);
            }
            catch { return(false); }
        }
Exemplo n.º 3
0
 public bool LogIn(string ID, string Password)
 {
     try
     {
         DataSetRepo dataSet = new DataSetRepo();
         List_Account = dataSet.GetList_Of_Account();
         InitialLogIn();
         foreach (var account in List_Account)
         {
             if (ID == account.ID && Password == account.Password)
             {
                 if (account.ID.Contains("giaovu"))
                 {
                     isStudent = false;
                 }
                 else
                 {
                     isStudent = true;
                 }
                 login = account;
                 return(true);
             }
         }
         return(false);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 4
0
        public void LoadStudents(string pathFile)
        {
            if (List_Of_Students == null)
            {
                List_Of_Students = new List <Students>();
            }
            if (List_Of_Account == null)
            {
                List_Of_Account = new List <AccountLogIn>();
            }
            try
            {
                StreamReader reader = new StreamReader(pathFile);

                string   ClassID    = reader.ReadLine();
                string[] splitClass = ClassID.Split(',');

                reader.ReadLine();

                string line = "";
                while ((line = reader.ReadLine()) != null)
                {
                    string[] split = line.Split(',');


                    var newStudent = new Students();

                    newStudent.StudentID = split[1];
                    newStudent.FullName  = split[2];
                    newStudent.Gender    = split[3];
                    newStudent.ID        = split[4];

                    newStudent.classID         = new Classes();
                    newStudent.classID.ClassID = splitClass[0];

                    var newAccount = new AccountLogIn();
                    newAccount.ID       = newStudent.StudentID;
                    newAccount.Password = newStudent.ID;

                    List_Of_Students.Add(newStudent);
                    List_Of_Account.Add(newAccount);

                    InitialAccount(newAccount);
                }
                reader.Close();

                //Import To DATABSE
                InitialStudentsToDatabase(splitClass[0]);

                return;
            } catch
            {
                return;
            }
        }
Exemplo n.º 5
0
        public void InitialLogIn()
        {
            AccountLogIn account = new AccountLogIn();

            account.ID       = "giaovu";
            account.Password = "******";
            if (List_Account == null)
            {
                List_Account = new List <AccountLogIn>();
            }

            List_Account.Add(account);
        }
Exemplo n.º 6
0
        public bool changePassword(AccountLogIn account)
        {
            if (List_Of_Account != null)
            {
                foreach (var acc in List_Of_Account)
                {
                    if (acc.ID == account.ID)
                    {
                        acc.Password = account.Password;

                        try
                        {
                            OleDbConnection connect = new OleDbConnection();
                            connect.ConnectionString = conn;
                            connect.Open();

                            OleDbCommand cmd = new OleDbCommand();
                            cmd.Connection  = connect;
                            cmd.CommandText = "Update Account SET Pass = ? WHERE ID = ?";

                            OleDbParameter para = cmd.Parameters.Add("", OleDbType.VarChar);
                            para.Value = account.Password;

                            para       = cmd.Parameters.Add("", OleDbType.VarChar);
                            para.Value = account.ID;

                            cmd.ExecuteNonQuery();

                            connect.Close();
                            return(true);
                        }
                        catch { }
                    }
                }
                return(false);
            }
            return(false);
        }
Exemplo n.º 7
0
        public bool LoadData()
        {
            try
            {
                List_Of_Classes           = new List <Classes>();
                List_Of_Students          = new List <Students>();
                List_Of_Courses           = new List <Courses>();
                List_Of_ClassCourses      = new List <ClassCourse>();
                List_Of_GradeClassCourses = new List <GradeClassCourse>();
                List_Of_Account           = new List <AccountLogIn>();

                OleDbConnection connect = new OleDbConnection();
                connect.ConnectionString = conn;
                connect.Open();

                OleDbCommand cmd = new OleDbCommand();
                cmd.Connection = connect;

                cmd.CommandText = "SELECT * FROM Classes";
                OleDbDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    var Class = new Classes();
                    Class.ClassID = reader.GetString(0);
                    List_Of_Classes.Add(Class);
                }

                reader.Close();

                cmd.CommandText = "SELECT * FROM Students";
                reader          = cmd.ExecuteReader();
                while (reader.Read())
                {
                    var student = new Students();
                    student.StudentID       = reader.GetString(0);
                    student.FullName        = reader.GetString(1);
                    student.Gender          = reader.GetString(2);
                    student.ID              = reader.GetString(3);
                    student.classID         = new Classes();
                    student.classID.ClassID = reader.GetString(4);

                    List_Of_Students.Add(student);
                }

                reader.Close();

                cmd.CommandText = "SELECT * FROM Courses";
                reader          = cmd.ExecuteReader();
                while (reader.Read())
                {
                    var course = new Courses();
                    course.CourseID        = reader.GetString(0);
                    course.CourseName      = reader.GetString(1);
                    course.Room            = reader.GetString(2);
                    course.classID         = new Classes();
                    course.classID.ClassID = reader.GetString(3);

                    List_Of_Courses.Add(course);
                }

                reader.Close();

                cmd.CommandText = "SELECT distinct CourseID FROM ClassCourses";
                reader          = cmd.ExecuteReader();
                while (reader.Read())
                {
                    var    classCourse = new ClassCourse();
                    string temp        = reader.GetString(0);
                    foreach (var course in List_Of_Courses)
                    {
                        if (course.CourseID == temp)
                        {
                            classCourse.course   = course;
                            classCourse.students = new List <Students>();

                            OleDbCommand cmd2 = new OleDbCommand();
                            cmd2.Connection  = connect;
                            cmd2.CommandText = $"SELECT StudentID FROM ClassCourses WHERE CourseID = '{course.CourseID}' ";
                            OleDbDataReader rd = cmd2.ExecuteReader();
                            while (rd.Read())
                            {
                                string StudentID = rd.GetString(0);
                                foreach (var stu in List_Of_Students)
                                {
                                    if (stu.StudentID == StudentID)
                                    {
                                        classCourse.students.Add(stu);
                                    }
                                }
                            }
                            rd.Close();

                            List_Of_ClassCourses.Add(classCourse);
                        }
                    }
                }
                reader.Close();

                cmd.CommandText = "SELECT distinct CourseID FROM GradeCourses";
                reader          = cmd.ExecuteReader();
                while (reader.Read())
                {
                    var gradeClassCourse = new GradeClassCourse();
                    gradeClassCourse.classCourse = new ClassCourse();
                    string temp = reader.GetString(0);
                    foreach (var course in List_Of_Courses)
                    {
                        if (course.CourseID == temp)
                        {
                            gradeClassCourse.classCourse.course = course;
                            gradeClassCourse.listGrade          = new List <Grade>();

                            OleDbCommand cmd2 = new OleDbCommand();
                            cmd2.Connection  = connect;
                            cmd2.CommandText = $"SELECT * FROM GradeCourses WHERE CourseID = '{course.CourseID}' ";
                            OleDbDataReader rd = cmd2.ExecuteReader();
                            while (rd.Read())
                            {
                                Grade newGrade = new Grade();
                                newGrade.StudentID  = rd.GetString(1);
                                newGrade.GradeGK    = rd.GetDouble(2);
                                newGrade.GradeCK    = rd.GetDouble(3);
                                newGrade.GradeE     = rd.GetDouble(4);
                                newGrade.TotalGrade = rd.GetDouble(5);

                                gradeClassCourse.listGrade.Add(newGrade);
                            }
                            rd.Close();

                            List_Of_GradeClassCourses.Add(gradeClassCourse);
                        }
                    }
                }
                reader.Close();

                cmd.CommandText = "SELECT * FROM Account";
                reader          = cmd.ExecuteReader();
                while (reader.Read())
                {
                    var account = new AccountLogIn();
                    account.ID       = reader.GetString(0);
                    account.Password = reader.GetString(1);

                    List_Of_Account.Add(account);
                }
                reader.Close();

                connect.Close();
                return(true);
            }
            catch { return(false); }
        }
Exemplo n.º 8
0
        public bool AddStudent(Students newStudent)
        {
            if (List_Of_Students != null)
            {
                List_Of_Students.Add(newStudent);
                var newAccount = new AccountLogIn();
                newAccount.ID       = newStudent.StudentID;
                newAccount.Password = newStudent.ID;
                if (List_Of_Account == null)
                {
                    List_Of_Account = new List <AccountLogIn>();
                }
                List_Of_Account.Add(newAccount);
                InitialAccount(newAccount);
                try
                {
                    OleDbConnection connect = new OleDbConnection();
                    connect.ConnectionString = conn;
                    connect.Open();

                    OleDbCommand cmd = new OleDbCommand();
                    cmd.Connection  = connect;
                    cmd.CommandText = "INSERT INTO Students VALUES (?,?,?,?,?)";

                    OleDbParameter para = cmd.Parameters.Add("", OleDbType.VarChar);
                    para.Value = newStudent.StudentID;

                    para       = cmd.Parameters.Add("", OleDbType.LongVarChar);
                    para.Value = newStudent.FullName;

                    para       = cmd.Parameters.Add("", OleDbType.VarChar);
                    para.Value = newStudent.Gender;

                    para       = cmd.Parameters.Add("", OleDbType.VarChar);
                    para.Value = newStudent.ID;

                    para       = cmd.Parameters.Add("", OleDbType.VarChar);
                    para.Value = newStudent.classID.ClassID;

                    cmd.ExecuteNonQuery();

                    if (List_Of_ClassCourses != null)
                    {
                        foreach (var classCourse in List_Of_ClassCourses)
                        {
                            if (classCourse.course.classID.ClassID == newStudent.classID.ClassID)
                            {
                                classCourse.students.Add(newStudent);
                            }
                        }
                        foreach (var classCourse in List_Of_ClassCourses)
                        {
                            if (classCourse.course.classID.ClassID == newStudent.classID.ClassID)
                            {
                                cmd.CommandText = "INSERT INTO ClassCourses VALUES (?,?)";

                                para       = cmd.Parameters.Add("", OleDbType.VarChar);
                                para.Value = classCourse.course.CourseID;

                                para       = cmd.Parameters.Add("", OleDbType.VarChar);
                                para.Value = newStudent.StudentID;

                                cmd.ExecuteNonQuery();
                            }
                        }
                    }

                    connect.Close();

                    return(true);
                } catch
                {
                    return(false);
                }
            }
            return(false);
        }