public ActionResult DanhGia(double MaSV, int?Diem_1_1, int?Diem_1_2, int?Diem_1_3, int?Diem_1_4, int?Diem_2_1, int?Diem_2_2, int?Diem_2_3, int?Diem_3_1, int?Diem_3_2, int?Diem_4_1, int?Diem_4_2, int?Diem_4_3, int?Diem_5_1, int?Diem_5_2, int?Diem_5_3, int?Diem_6_1)
        {
            int a     = int.Parse(Session["NamHoc"].ToString());
            int b     = int.Parse(Session["HocKy"].ToString());
            var diem2 = new DiemRenLuyenLopDao();

            diem2.Update(MaSV, a, b, Diem_1_1, Diem_1_2, Diem_1_3, Diem_1_4, Diem_2_1, Diem_2_2, Diem_2_3, Diem_3_1, Diem_3_2, Diem_4_1, Diem_4_2, Diem_4_3, Diem_5_1, Diem_5_2, Diem_5_3, Diem_6_1);

            var d    = new DiemRenLuyenLopDao();
            var SV   = new SinhVienDao().GetSV(MaSV);
            var diem = new DiemRenLuyenDao();

            ViewBag.DiemSV       = diem.GetByRL(MaSV, a, b);
            ViewBag.DiemSV_Lop   = d.GetByRL(MaSV, a, b);
            ViewBag.DiemTong     = diem.DiemTong(MaSV, a, b);
            ViewBag.DiemTong_Lop = d.DiemTong(MaSV, a, b);
            ModelState.AddModelError("", "Lưu Thành công.");
            var diemRL = new DiemRenLuyenLopDao();

            Session.Add("XS", diemRL.XS(20192020, 1));
            Session.Add("Tot", diemRL.Tot(20192020, 1));
            Session.Add("Kha", diemRL.Kha(20192020, 1));
            Session.Add("TB", diemRL.TB(20192020, 1));
            Session.Add("Yeu", diemRL.Yeu(20192020, 1));
            Session.Add("Kem", diemRL.Kem(20192020, 1));
            return(View(SV));
        }
        public ActionResult ThongKe(string Id_NamHoc, string Id_HocKy)
        {
            var NamHoc = new NamHocDao();

            ViewBag.ListNamHoc = NamHoc.ListAll();
            var HocKy = new HocKiDao();

            ViewBag.ListHocKy = HocKy.ListAll();
            //Thống kê số lượng thành tích sinh viên
            if (Id_NamHoc == null || Id_NamHoc.Equals(""))
            {
                Id_NamHoc = "20192020";
            }
            if (Id_HocKy == null || Id_HocKy.Equals(""))
            {
                Id_HocKy = "1";
            }
            var diemRL = new DiemRenLuyenLopDao();
            int a      = int.Parse(Id_NamHoc);
            int b      = int.Parse(Id_HocKy);

            Session.Add("XS", diemRL.XS(a, b));
            Session.Add("Tot", diemRL.Tot(a, b));
            Session.Add("Kha", diemRL.Kha(a, b));
            Session.Add("TB", diemRL.TB(a, b));
            Session.Add("Yeu", diemRL.Yeu(a, b));
            Session.Add("Kem", diemRL.Kem(a, b));
            Session.Add("Gioi", diemRL.Tot(a, b));

            //Thống kê cơ cấu sinh viên hoàn thành
            var diem = new DiemRenLuyenDao();

            Session.Add("100", diem.TienDo100(a, b));
            Session.Add("80-99", diem.TienDo80_99(a, b));
            Session.Add("50-79", diem.TienDo50_79(a, b));
            Session.Add("0-49", diem.TienDo0_49(a, b));

            return(View());
        }
        public ActionResult Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                var dao    = new UserDao();
                var result = dao.Login(model.UserName, model.PassWord);

                if (result == 1)
                {
                    var user        = dao.GetById(model.UserName);
                    var userSession = new UserLogin();
                    userSession.UserName = user.UserName;
                    userSession.MaSV     = user.MaSV;
                    Session.Add(CommonConstans.USER_SESSION, userSession);
                    Session.Add("MaSV", user.MaSV);


                    Session.Add("NamHoc", "20192020");
                    Session.Add("HocKy", "1");

                    var diemRL = new DiemRenLuyenLopDao();
                    Session.Add("XS", diemRL.XS(20192020, 1));
                    Session.Add("Tot", diemRL.Tot(20192020, 1));
                    Session.Add("Kha", diemRL.Kha(20192020, 1));
                    Session.Add("TB", diemRL.TB(20192020, 1));
                    Session.Add("Yeu", diemRL.Yeu(20192020, 1));
                    Session.Add("Kem", diemRL.Kem(20192020, 1));

                    var diem = new DiemRenLuyenDao();
                    Session.Add("100", diem.TienDo100(20192020, 1));
                    Session.Add("80-99", diem.TienDo80_99(20192020, 1));
                    Session.Add("50-79", diem.TienDo50_79(20192020, 1));
                    Session.Add("0-49", diem.TienDo0_49(20192020, 1));



                    return(RedirectToAction("Index", "Home"));
                }
                else if (result == 2)
                {
                    var user        = dao.GetById(model.UserName);
                    var userSession = new UserLogin();
                    userSession.UserName = user.UserName;
                    userSession.MaSV     = user.MaSV;
                    Session.Add(CommonConstans.USER_SESSION, userSession);
                    Session.Add("MaSV", user.MaSV);
                    Session.Add("NamHoc", "20192020");
                    Session.Add("HocKy", "1");

                    var sv = new SinhVienDao().GetSV(user.MaSV);
                    Session.Add("Anh", sv.Anh);
                    Session.Add("HoTen", sv.HoTen);
                    return(RedirectToAction("Account", "SinhVien"));
                }
                else if (result == 0)
                {
                    ModelState.AddModelError("", "Tài khoản không tồn tại.");
                }
                else
                {
                    ModelState.AddModelError("", "Mật khẩu không đúng.");
                }
            }
            return(View("Index"));
        }
        public ActionResult FacebookCallback(string code)
        {
            var     fb     = new FacebookClient();
            dynamic result = fb.Post("oauth/access_token", new
            {
                client_id     = ConfigurationManager.AppSettings["FbAppId"],
                client_secret = ConfigurationManager.AppSettings["FbAppSecret"],
                redirect_uri  = RedirectUri.AbsoluteUri,
                code          = code
            });


            var accessToken = result.access_token;

            if (!string.IsNullOrEmpty(accessToken))
            {
                fb.AccessToken = accessToken;
                // Get the user's information, like email, first name, middle name etc
                dynamic me = fb.Get("me?fields=first_name,middle_name,last_name,id,email");

                string email1 = me.email;

                var dao = new UserDao();

                var result1 = dao.Login(email1, email1);

                if (result1 == 1)
                {
                    var user1       = dao.GetById(me.email);
                    var userSession = new UserLogin();
                    userSession.UserName = user1.UserName;
                    userSession.MaSV     = user1.MaSV;
                    Session.Add(CommonConstans.USER_SESSION, userSession);
                    Session.Add("MaSV", user1.MaSV);


                    Session.Add("NamHoc", "20192020");
                    Session.Add("HocKy", "1");

                    var diemRL = new DiemRenLuyenLopDao();
                    Session.Add("XS", diemRL.XS(20192020, 1));
                    Session.Add("Tot", diemRL.Tot(20192020, 1));
                    Session.Add("Kha", diemRL.Kha(20192020, 1));
                    Session.Add("TB", diemRL.TB(20192020, 1));
                    Session.Add("Yeu", diemRL.Yeu(20192020, 1));
                    Session.Add("Kem", diemRL.Kem(20192020, 1));

                    var diem = new DiemRenLuyenDao();
                    Session.Add("100", diem.TienDo100(20192020, 1));
                    Session.Add("80-99", diem.TienDo80_99(20192020, 1));
                    Session.Add("50-79", diem.TienDo50_79(20192020, 1));
                    Session.Add("0-49", diem.TienDo0_49(20192020, 1));
                }
                else if (result1 == 2)
                {
                    var user1       = dao.GetById(me.email);
                    var userSession = new UserLogin();
                    userSession.UserName = user1.UserName;
                    userSession.MaSV     = user1.MaSV;
                    Session.Add(CommonConstans.USER_SESSION, userSession);
                    Session.Add("MaSV", user1.MaSV);
                    Session.Add("NamHoc", "20192020");
                    Session.Add("HocKy", "1");

                    var sv = new SinhVienDao().GetSV(user1.MaSV);
                    Session.Add("Anh", sv.Anh);
                    Session.Add("HoTen", sv.HoTen);
                    //return RedirectToAction("DanhGia", "SinhVien");
                    return(Redirect("~/areas/Admin/Controller/SinhVien/DanhGia"));
                }
                else
                {
                    string id         = me.id;
                    string email      = me.email;
                    string firstname  = me.first_name;
                    string middlename = me.middle_name;
                    string lastname   = me.last_name;

                    var user = new User();
                    user.UserName     = email;
                    user.PassWords    = email;
                    user.MaSV         = double.Parse(id);
                    user.LoaiDangNhap = 2;
                    user.xoa          = 0;

                    var userdao = new UserDao();
                    userdao.Insert(user);

                    var SV = new SinhVien();
                    SV.MaSV  = double.Parse(id);
                    SV.HoTen = firstname + " " + middlename + " " + lastname;
                    SV.Email = me.email;
                    SV.Anh   = "/assets/client/image/anhmacdinh.jpg";
                    SV.xoa   = 0;

                    var SVDao = new SinhVienDao();
                    SVDao.Insert(SV);

                    var user1       = dao.GetById(email);
                    var userSession = new UserLogin();
                    userSession.UserName = user1.UserName;
                    userSession.MaSV     = user1.MaSV;
                    Session.Add(CommonConstans.USER_SESSION, userSession);
                    Session.Add("MaSV", user1.MaSV);
                    Session.Add("NamHoc", "20192020");
                    Session.Add("HocKy", "1");

                    var sv = new SinhVienDao().GetSV(user1.MaSV);
                    Session.Add("Anh", sv.Anh);
                    Session.Add("HoTen", sv.HoTen);
                    return(RedirectToAction("DanhGia", "SinhVien"));
                }
            }
            return(Redirect("/"));
        }