Ejemplo n.º 1
0
 public ActionResult Dangnhap(TaiKhoan tk)
 {
     if (ModelState.IsValid)
     {
         MD5HASH md5Hash   = new MD5HASH();
         var     mk        = md5Hash.encrypt(tk.Matkhau);
         var     NguoiDung = db.TaiKhoans.SingleOrDefault(x => x.Email == tk.Email && x.Matkhau == mk);//kiểm tra giá trị nhập vào
         if (NguoiDung != null)
         {
             Session["TaiKhoan"]    = NguoiDung;
             Session["Admin"]       = null;
             Session["Ten"]         = NguoiDung.Ten;
             Session["TenDangNhap"] = NguoiDung.TenDangnhap;
             var            giohang   = db.giohangs.Where(x => x.makhachhang == NguoiDung.makh).ToList <giohang>();
             List <sanpham> dsSanPham = new List <sanpham>();
             foreach (var item in giohang)
             {
                 sanpham sanpham = db.sanphams.Where(x => x.masp == item.masp && x.slsp >= item.soluongdamua && x.trangthai == 1).SingleOrDefault();
                 if (sanpham != null)
                 {
                     sanpham.slsp = item.soluongdamua;
                     dsSanPham.Add(sanpham);
                 }
             }
             if (dsSanPham.Count > 0)
             {
                 Session["giohang"] = dsSanPham;
             }
             return(Redirect("/Home/Index"));
         }
     }
     Session["dangnhapsai"] = true;
     return(Redirect("/Login/Index"));
 }
Ejemplo n.º 2
0
        public ActionResult Dangky(TaiKhoan tk)
        {
            var NguoiDung = db.TaiKhoans.Where(x => x.Email == tk.Email).ToList();

            if (NguoiDung.Count > 0)
            {
                Session["dangkyemail"] = true;
                return(Redirect("/Login/Index"));
            }
            TaiKhoan taikhoanmoi = new TaiKhoan();

            MD5HASH md5Hash = new MD5HASH();
            var     mk      = md5Hash.encrypt(tk.Matkhau);

            taikhoanmoi.Ten       = tk.Ten;
            taikhoanmoi.Ho        = tk.Ho;
            taikhoanmoi.Ngaysinh  = tk.Ngaysinh;
            taikhoanmoi.Sdt       = tk.Sdt;
            taikhoanmoi.Email     = tk.Email;
            taikhoanmoi.Matkhau   = mk;
            taikhoanmoi.Phanquyen = 0;
            db.TaiKhoans.Add(taikhoanmoi);
            db.SaveChanges();
            Session["dangkythanhcong"] = true;
            return(Redirect("/Login/Index"));
        }
Ejemplo n.º 3
0
 public ActionResult Edit([Bind(Include = "makh,TenDangnhap,Ten,Ho,Ngaysinh,Sdt,Email,Matkhau,Phanquyen")] TaiKhoan taiKhoan)
 {
     if (ModelState.IsValid)
     {
         MD5HASH md5Hash = new MD5HASH();
         var     mk      = md5Hash.encrypt(taiKhoan.Matkhau);
         taiKhoan.Matkhau         = mk;
         db.Entry(taiKhoan).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(taiKhoan));
 }
Ejemplo n.º 4
0
 public ActionResult Dangnhap(TaiKhoan tk)
 {
     if (ModelState.IsValid)
     {
         MD5HASH md5Hash = new MD5HASH();
         var     mk      = md5Hash.encrypt(tk.Matkhau);
         var     Admin   = db.TaiKhoans.SingleOrDefault(x => x.Email == tk.Email && x.Matkhau == mk && x.Phanquyen == 1);
         if (Admin != null)
         {
             Session["Admin"]       = Admin.Phanquyen;
             Session["HoTen"]       = Admin.Ten;
             Session["TenDangNhap"] = Admin.TenDangnhap;
             return(Redirect("/admin/Home"));
         }
     }
     Session["dangnhapAdminSai"] = true;
     return(Redirect("/admin/Login/Index"));
 }
Ejemplo n.º 5
0
 private void CreateUser(User user)
 {
     try
     {
         Session.Remove("UserId");
         user.UserName   = txtUsername.Text;
         user.Title      = ddlTitle.SelectedValue;
         user.FirstName  = txtFirstName.Text;
         user.MiddleName = txtMiddleName.Text;
         user.LastName   = txtLastName.Text;
         if (ddlDesignation.SelectedIndex != 0)
         {
             user.Designation = Convert.ToInt32(ddlDesignation.SelectedValue);
         }
         user.Password = UserBAL.Instance.GenerateRandomCode();
         ViewState["DefaultPassword"] = user.Password;
         user.Password = MD5HASH.GetMD5HashCode(ViewState["DefaultPassword"].ToString().Trim());
         //user.DateOfBirth = Convert.ToDateTime(txtDateOfBirth.Text.ToString());
         if (rbtnMale.Checked == true)
         {
             user.Gender = "1";
         }
         else
         {
             user.Gender = "2";
         }
         //user.Gender = ddlGender.SelectedValue;
         user.Role         = ddlRole.SelectedValue;
         user.Address      = txtArea.Text;
         user.PinCode      = txtPincode.Text;
         user.City         = txtCity.Text;
         user.PhoneNumber  = txtPhoneNo.Text;
         user.District     = txtDistrict.Text;
         user.MobileNumber = txtMobileNO.Text;
         user.PhoneNumber  = txtPhoneNo.Text;
         user.State        = ddlState.SelectedValue;
         user.Country      = ddlCountry.SelectedValue;
         user.Email        = txtEmail.Text;
         user.FaxNumber    = txtFaxNo.Text;
         if (chkIsActive.Checked)
         {
             user.IsActive = true;
         }
         else
         {
             user.IsActive = false;
         }
         if (ddlRole.SelectedValue == "6")
         {
             user.TigerReserveId = Convert.ToInt32(ddlTigerReserve.SelectedValue);
         }
         UserBAL.Instance.CreateUser(user);
         //Response.Redirect("~/Admin/Users.aspx");
         SendMail(user.UserName, ViewState["DefaultPassword"].ToString());
         Clear();
     }
     catch (Exception ex)
     {
         //string strError = ex.Message;
         //vmError.Message = strError;
         //FlashMessage.ErrorMessage(vmError.Message);
         LogHandler.LogFatal((ex.InnerException != null ? ex.InnerException.Message : ex.Message), ex, this.GetType());
         Response.RedirectPermanent("~/ErrorPage.aspx", false);
     }
 }