コード例 #1
0
        public ActionResult DangNhap(FormCollection form)
        {
            string tenDangNhap = form["exampleInputEmail1"].ToString().Trim();
            string matKhau     = form["exampleInputPassword1"];
            string mk          = Convert.ToString(maHoa.MaHoa(matKhau.Trim()));
            bool   kt          = KiemTra_NguoiDung(tenDangNhap);

            Session["kt"] = kt;
            if (kt)
            {
                bool ktGV = modelDefault.KiemTra_GV(tenDangNhap, mk);
                if (ktGV)
                {
                    var model = modelDefault.ThongTin_GV(tenDangNhap.Trim());
                    foreach (var gv in model)
                    {
                        Session["maSo"]    = gv.maSo.ToString();
                        Session["hoTen"]   = gv.hoTen;
                        Session["hinhAnh"] = gv.hinhAnh;
                        Session["matKhau"] = gv.matKhau;
                        Session["mail"]    = gv.mail;
                    }
                    if (Session["mail"] != null)
                    {
                        bool ktMail = m_Mail.KiemTraMail(Session["mail"].ToString());
                        if (ktMail)
                        {
                            bool them = m_Mail.ThemMail(Session["hinhAnh"].ToString(), Session["mail"].ToString(), Session["hoTen"].ToString());
                        }
                        else
                        {
                            bool xoa = m_Mail.XoaMail(Session["mail"].ToString());
                            if (xoa)
                            {
                                bool them = m_Mail.ThemMail(Session["hinhAnh"].ToString(), Session["mail"].ToString(), Session["hoTen"].ToString());
                            }
                        }
                    }

                    return(RedirectToAction("Index", "Admin"));
                }
                else
                {
                    ViewBag.error = "Thông tin không tồn tại";
                }
            }
            else if (kt == false)
            {
                bool ktSV = modelDefault.KiemTra_SV(tenDangNhap, mk);
                if (ktSV)
                {
                    string   ngayHeThong = DateTime.Now.ToString("MM/dd/yyyy");
                    DateTime ngayHienTai = Convert.ToDateTime(ngayHeThong);
                    string   tgianThi    = "";
                    foreach (var l in m_DeThi.DeThi(tenDangNhap))
                    {
                        tgianThi = l.NgayThi.ToString("MM/dd/yyyy");
                    }
                    DateTime ngayThi = Convert.ToDateTime(tgianThi);
                    if (ngayHienTai < ngayThi)
                    {
                        var model = modelDefault.ThongTin_SV(tenDangNhap.Trim());
                        foreach (var gv in model)
                        {
                            Session["maSo"]    = gv.maSo.ToString();
                            Session["hoTen"]   = gv.hoTen;
                            Session["hinhAnh"] = gv.hinhAnh;
                            Session["matKhau"] = gv.matKhau;
                            Session["mail"]    = gv.mail;
                            if (Session["mail"] != null)
                            {
                                bool ktMail = m_Mail.KiemTraMail(Session["mail"].ToString());
                                if (ktMail)
                                {
                                    bool them = m_Mail.ThemMail(Session["hinhAnh"].ToString(), Session["mail"].ToString(), Session["hoTen"].ToString());
                                }
                                else
                                {
                                    bool xoa = m_Mail.XoaMail(Session["mail"].ToString());
                                    if (xoa)
                                    {
                                        bool them = m_Mail.ThemMail(Session["hinhAnh"].ToString(), Session["mail"].ToString(), Session["hoTen"].ToString());
                                    }
                                }
                            }
                        }

                        return(RedirectToAction("Index", "SinhVien"));
                    }
                    else
                    {
                        var model = modelDefault.ThongTin_SV(tenDangNhap.Trim());
                        foreach (var gv in model)
                        {
                            Session["maSo"]    = gv.maSo.ToString();
                            Session["hoTen"]   = gv.hoTen;
                            Session["hinhAnh"] = gv.hinhAnh;
                            Session["matKhau"] = gv.matKhau;
                            Session["mail"]    = gv.mail;
                            if (Session["mail"] != null)
                            {
                                bool ktMail = m_Mail.KiemTraMail(Session["mail"].ToString());
                                if (ktMail)
                                {
                                    bool them = m_Mail.ThemMail(Session["hinhAnh"].ToString(), Session["mail"].ToString(), Session["hoTen"].ToString());
                                }
                                else
                                {
                                    bool xoa = m_Mail.XoaMail(Session["mail"].ToString());
                                    if (xoa)
                                    {
                                        bool them = m_Mail.ThemMail(Session["hinhAnh"].ToString(), Session["mail"].ToString(), Session["hoTen"].ToString());
                                    }
                                }
                            }
                        }


                        return(RedirectToAction("ChoThi", "SinhVien"));
                    }
                }
                else
                {
                    ViewBag.error = "Thông tin không tồn tại";
                }
            }
            else
            {
                ViewBag.error = "Tài khoản hoặc mật khẩu không đúng";
            }
            return(Index());
        }