Beispiel #1
0
 public static bool isLogin()
 {
     if ((int)HttpContext.Current.Session["IsLogin"] == 1)
     {
         return(true);
     }
     else if (HttpContext.Current.Request.Cookies["Username"] != null)
     {
         //Không có session - > Kiểm tra cookies
         string userName = HttpContext.Current.Request.Cookies["Username"].Value;
         //Tìm trong CSDL
         using (ModelEntities ctx = new ModelEntities())
         {
             tbl_NguoiSuDungs user = ctx.tbl_NguoiSuDungs.Where(p => String.Compare(p.TenDangNhap, userName) == 0).FirstOrDefault();
             if (user != null)
             {
                 //Tạo lại Sesstion
                 HttpContext.Current.Session["IsLogin"] = 1;
                 HttpContext.Current.Session["CurUser"] = user;
                 return(true);
             }
         }
     }
     return(false);
 }
 public override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     if (CurrentContext.isLogin() == false)
     {
         string controller = filterContext.RouteData.Values["controller"].ToString();
         string action     = filterContext.RouteData.Values["action"].ToString();
         filterContext.Result = new RedirectResult(string.Format(
                                                       "~/Account/Login?retURL=/{0}/{1}", controller, action
                                                       )
                                                   );
         return;
     }
     else
     {
         tbl_NguoiSuDungs temp = CurrentContext.getCurrenUser();
         if (temp.Quyen != 0)
         {
             string controller = filterContext.RouteData.Values["controller"].ToString();
             string action     = filterContext.RouteData.Values["action"].ToString();
             filterContext.Result = new RedirectResult(string.Format(
                                                           "~/Home/Index", controller, action
                                                           )
                                                       );
             return;
         }
     }
     base.OnActionExecuting(filterContext);
 }
Beispiel #3
0
        public ActionResult Register(Poco_DangKy item)
        {
            if (!ModelState.IsValid)
            {
                return(View(3));
            }
            tbl_NguoiSuDungs obj = new tbl_NguoiSuDungs();

            obj.TenDangNhap = item.TenDangNhap;
            using (ModelEntities ctx = new ModelEntities())
            {
                if (ctx.tbl_NguoiSuDungs.Any(p => p.TenDangNhap == item.TenDangNhap))
                {
                    return(View(2));
                }
            }
            obj.MatKhau        = StringUtils.Md5(item.MatKhau);
            obj.GioiTinh       = item.GioiTinh;
            obj.NgaySinh       = DateTime.ParseExact(item.NgaySinh, "dd/MM/yyyy", null);
            obj.DiaChi         = item.DiaChi;
            obj.SoDienThoai    = item.SoDienThoai;
            obj.TenNguoiSuDung = item.HoTen;
            obj.Quyen          = 0;
            obj.DaXoa          = false;
            using (ModelEntities ctx = new ModelEntities())
            {
                ctx.tbl_NguoiSuDungs.Add(obj);
                ctx.SaveChanges();
            }
            return(View(0));
        }
Beispiel #4
0
 public ActionResult Login(Poco_Login item)
 {
     using (ModelEntities ctx = new ModelEntities())
     {
         tbl_NguoiSuDungs usr = ctx.tbl_NguoiSuDungs.Where(p => p.TenDangNhap == item.UserName).FirstOrDefault();
         if (usr == null)
         {
             //Khong ton tai use
             ViewBag.Error = "zzz";
             return(View(item));
         }
         else
         {
             if (String.Compare(StringUtils.Md5(item.Password), usr.MatKhau) != 0)
             {
                 ViewBag.Error = "zzz";
                 return(View(item));
             }
             else
             {
                 Session["IsLogin"] = 1;
                 Session["CurUser"] = usr;
                 if (item.Remeber)
                 {
                     HttpContext.Response.Cookies["Username"].Value   = usr.TenDangNhap;
                     HttpContext.Response.Cookies["Username"].Expires = DateTime.Now.AddDays(7);
                 }
                 return(RedirectToAction("Index", "Home"));
             }
         }
     }
 }
Beispiel #5
0
 public ActionResult Index()
 {
     using (ModelEntities ctx = new ModelEntities())
     {
         int userID            = CurrentContext.getCurrenUser().NguoiSuDungID;
         tbl_NguoiSuDungs user = ctx.tbl_NguoiSuDungs.Where(p => p.NguoiSuDungID == userID).FirstOrDefault();
         return(View(user));
     }
 }
Beispiel #6
0
 public ActionResult Edit(tbl_NguoiSuDungs item)
 {
     using (ModelEntities ctx = new ModelEntities())
     {
         tbl_NguoiSuDungs findItem = ctx.tbl_NguoiSuDungs.Where(p => p.NguoiSuDungID == item.NguoiSuDungID).FirstOrDefault();
         if (findItem == null)
         {
             return(RedirectToAction("Index", "Account"));
         }
         findItem.TenNguoiSuDung = item.TenNguoiSuDung;
         findItem.SoDienThoai    = item.SoDienThoai;
         findItem.NgaySinh       = item.NgaySinh;
         findItem.DiaChi         = item.DiaChi;
         findItem.GioiTinh       = item.GioiTinh;
         findItem.MatKhau        = StringUtils.Md5(item.MatKhau);
         ctx.SaveChanges();
         return(RedirectToAction("Index", "Account"));
     }
 }
Beispiel #7
0
        // GET: Admin/Cart/Edit
        public ActionResult Edit(int?id)
        {
            if (!id.HasValue)
            {
                return(RedirectToAction("Index"));
            }
            Poco_DonHang_ChiTiet chiTietDonHang = new Poco_DonHang_ChiTiet();

            using (ModelEntities ctx = new ModelEntities())
            {
                tbl_PhieuOrders phieuOder = ctx.tbl_PhieuOrders.Where(p => p.PhieuOrderID == id).ToList().FirstOrDefault();
                if (phieuOder.DaXoa == true)
                {
                    return(RedirectToAction("Index"));
                }
                chiTietDonHang.ThongTinDonHang              = new Poco_Info_DonHang();
                chiTietDonHang.ThongTinDonHang.MaDonHang    = phieuOder.PhieuOrderID.ToString();
                chiTietDonHang.ThongTinDonHang.NgayLapPhieu = phieuOder.NgayLapPhieu.ToString();
                if (string.IsNullOrEmpty(phieuOder.SoDienThoai))
                {
                    chiTietDonHang.ThongTinDonHang.SoDienThoaiNhanHang = "Không xác định";
                }
                else
                {
                    chiTietDonHang.ThongTinDonHang.SoDienThoaiNhanHang = phieuOder.SoDienThoai;
                }
                if (string.IsNullOrEmpty(phieuOder.DiaChi))
                {
                    chiTietDonHang.ThongTinDonHang.DiaChiGiaoHang = "Không xác định";
                }
                else
                {
                    chiTietDonHang.ThongTinDonHang.DiaChiGiaoHang = phieuOder.DiaChi;
                }
                chiTietDonHang.ThongTinDonHang.TinhTrangGiaoHang  = phieuOder.TinhTrangGiaoHang.Value;
                chiTietDonHang.ThongTinDonHang.TinhTrangThanhToan = phieuOder.TinhTrangThanhToan.Value;
                chiTietDonHang.ThongTinDonHang.TongSoLuong        = phieuOder.TongSoLuong.ToString();
                chiTietDonHang.ThongTinDonHang.TongTien           = phieuOder.TongTien;
                chiTietDonHang.ThongTinDonHang.GioLap             = phieuOder.NgayLapPhieu.ToShortTimeString();
                chiTietDonHang.ThongTinDonHang.DaXoa = phieuOder.DaXoa.Value;

                tbl_NguoiSuDungs user = ctx.tbl_NguoiSuDungs.Where(p => p.NguoiSuDungID == phieuOder.NguoiSuDungID).FirstOrDefault();

                chiTietDonHang.ThongTinKhachHang              = new Poco_Info_KhachHang();
                chiTietDonHang.ThongTinKhachHang.MaKhachHang  = user.NguoiSuDungID.ToString();
                chiTietDonHang.ThongTinKhachHang.TenKhachHang = user.TenNguoiSuDung;

                chiTietDonHang.ChiTietDonHang = new List <Poco_ChiTiet_Order>();
                List <tbl_ChiTietOrders> listOrder = ctx.tbl_ChiTietOrders.Where(p => p.PhieuOrderID == id).ToList();
                foreach (tbl_ChiTietOrders item in listOrder)
                {
                    Poco_ChiTiet_Order itemAdd = new Poco_ChiTiet_Order();
                    var a = ctx.tbl_SanPhams.Where(p => p.SanPhamID == item.SanPhamID).FirstOrDefault();
                    if (a != null)
                    {
                        itemAdd.TenSanPham = a.TenSanPham;
                    }
                    itemAdd.SanPhamID = item.SanPhamID.ToString();
                    itemAdd.DonGia    = item.DonGia;
                    itemAdd.SoLuong   = item.SoLuong;
                    itemAdd.ThanhTien = item.ThanhTien;
                    chiTietDonHang.ChiTietDonHang.Add(itemAdd);
                }
                return(View(chiTietDonHang));
            }
        }
Beispiel #8
0
        public ActionResult Checkout(tbl_NguoiSuDungs itemUser)
        {
            tbl_PhieuOrders ord = new tbl_PhieuOrders
            {
                NgayLapPhieu       = DateTime.Now,
                NguoiSuDungID      = CurrentContext.getCurrenUser().NguoiSuDungID,
                TongSoLuong        = 0,
                TongTien           = 0,
                DiaChi             = null,
                SoDienThoai        = null,
                TinhTrangGiaoHang  = false,
                TinhTrangThanhToan = false,
                DaXoa = false
            };

            using (ModelEntities ctx = new ModelEntities())
            {
                decimal total       = 0;
                int     totalAmount = 0;
                foreach (CartItem item in CurrentContext.Cart().Items)
                {
                    tbl_SanPhams pro = ctx.tbl_SanPhams.Where(p => p.SanPhamID == item.ProID).FirstOrDefault();
                    if (pro != null)
                    {
                        tbl_ChiTietOrders d = new tbl_ChiTietOrders
                        {
                            SanPhamID = item.ProID,
                            SoLuong   = item.Quantity,
                            DonGia    = (decimal)pro.Gia,
                            ThanhTien = (decimal)(item.Quantity * pro.Gia)
                        };
                        pro.SoLanMua += item.Quantity;
                        pro.SoLuong  -= item.Quantity;
                        ctx.SaveChanges();
                        ord.tbl_ChiTietOrders.Add(d);
                        totalAmount += d.SoLuong;
                        total       += d.ThanhTien;
                    }
                }
                ord.TongSoLuong        = totalAmount;
                ord.TongTien           = total;
                ord.TinhTrangGiaoHang  = false;
                ord.TinhTrangThanhToan = false;
                int curID = CurrentContext.getCurrenUser().NguoiSuDungID;
                var user  = ctx.tbl_NguoiSuDungs.Where(p => p.NguoiSuDungID == curID).FirstOrDefault();
                if (itemUser.DiaChi == null)
                {
                    ord.DiaChi = user.DiaChi;
                }
                else
                {
                    ord.DiaChi = itemUser.DiaChi;
                }
                if (itemUser.SoDienThoai == null)
                {
                    ord.SoDienThoai = user.SoDienThoai;
                }
                else
                {
                    ord.SoDienThoai = itemUser.SoDienThoai;
                }

                ctx.tbl_PhieuOrders.Add(ord);
                ctx.SaveChanges();
                CurrentContext.Cart().Items.Clear();
                return(RedirectToAction("Index", "Cart"));
            }
        }