public ActionResult EditMa([Bind(Include = "ID,MaGiamGia,GiaTri,NgayHetHan,SoLuong")] MaGiam magiam)
 {
     if (ModelState.IsValid)
     {
         db.Entry(magiam).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(magiam));
 }
 public ActionResult Edit([Bind(Include = "MaSP,TenSP,DonGia,MoTa,MaLoai,TrangThai,HinhAnh,SoLuong,GioiTinh,NgayChinhSua,NgayTao")] SanPham sanpham)
 {
     if (ModelState.IsValid)
     {
         db.Entry(sanpham).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(sanpham));
 }
 public ActionResult EditTinTuc([Bind(Include = "ID,TenBaiViet,NoiDung,MaLoaiTinTuc,Keyqword,Decription,title,MetaTitle,AnhDaiDien,CapNhat")] TinTuc tintuc
                                )
 {
     if (ModelState.IsValid)
     {
         db.Entry(tintuc).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tintuc));
 }
        public ActionResult ChiTietSanPham(int iMaSP, string iComment, string Ngay, int iRating, DanhGia DG)
        {
            if (Session["Email"] == null)
            {
                return(RedirectToAction("DangNhap", "TaiKhoan"));
            }
            else
            {
                DG.MaKH          = int.Parse(Session["MaKH"].ToString());
                DG.MaSP          = iMaSP;
                DG.cmtDanhGia    = iComment;
                DG.DiemDG        = iRating;
                DG.NgayCmt       = DateTime.Parse(Ngay);
                TempData["MaSP"] = iMaSP;
                db.DanhGias.Add(DG);
                db.SaveChanges();
                List <DanhGia> LDG    = db.DanhGias.Where(n => n.MaSP == iMaSP).ToList();
                double         DGTB   = 0;
                int            DiemDG = 0;
                for (int i = 0; i < LDG.Count(); i++)
                {
                    DiemDG += int.Parse(DG.DiemDG.ToString());
                }
                DGTB = DiemDG / LDG.Count();

                return(RedirectToAction("TrangChu", "Home"));
            }
        }
 public ActionResult Edit([Bind(Include = "SoHD,MaKH,NgayDatHang,NgayGiaoHang,TongTien,TrangThai,TenNguoiNhan,DiaChiNhan,DienThoaiKH,MaHinhThucTT,MaHinhThucGD,EmailNhanHang")] DonHang dh)
 {
     if (ModelState.IsValid)
     {
         db.Entry(dh).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("HoaDon", "ThongKe");
     }
     return View(dh);
 }
示例#6
0
 public ActionResult DangKy(FormCollection frmDK, KhachHang KH)
 {
     KH.HoTenKH  = frmDK["hoten"];
     KH.DiaChiKH = frmDK["diachi"];
     KH.TenDN    = frmDK["tendn"];
     KH.MatKhau  = GetMD5(frmDK["matkhau"]);
     KH.Email    = frmDK["email"];
     db.KhachHangs.Add(KH);
     db.SaveChanges();
     return(Content(@"<script language='javascript' type='text/javascript'>
                  alert('Đăng Ký thành công!');
                  window.location.href='/Home/TrangChu'
                  </script>
               "));
 }
示例#7
0
        public ActionResult GoogleLoginCallback()
        {
            var claimsPrincipal = HttpContext.User.Identity as ClaimsIdentity;

            var loginInfo = SSO.GetLoginInfo(claimsPrincipal);

            if (loginInfo == null)
            {
                return(RedirectToAction("DangNhap"));
            }
            MiniShopEntities db = new MiniShopEntities(); //DbContext
            var user            = db.KhachHangs.FirstOrDefault(x => x.Email == loginInfo.emailaddress);

            if (user == null)
            {
                user = new KhachHang
                {
                    Email    = loginInfo.emailaddress,
                    HoTenKH  = loginInfo.name,
                    DiaChiKH = loginInfo.nameidentifier,
                };
                db.KhachHangs.Add(user);
                db.SaveChanges();
            }
            Session["username"] = loginInfo.name;
            Session["makh"]     = user.MaKH;

            var ident = new ClaimsIdentity(
                new[] {
                // adding following 2 claim just for supporting default antiforgery provider
                new Claim(ClaimTypes.NameIdentifier, user.Email),
                new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "ASP.NET Identity", "http://www.w3.org/2001/XMLSchema#string"),
                new Claim(ClaimTypes.Name, user.HoTenKH),
                new Claim(ClaimTypes.Email, user.Email),
                // optionally you could add roles if any
                new Claim(ClaimTypes.Role, "User")
            },
                CookieAuthenticationDefaults.AuthenticationType);


            HttpContext.GetOwinContext().Authentication.SignIn(
                new AuthenticationProperties {
                IsPersistent = false
            }, ident);
            return(Redirect("~/"));
        }
        public ActionResult GioHang(FormCollection frm, DonHang donhang)
        {
            //Session["NgayGiaoHang"] = DateTime.Parse(DateTime.Now.ToString());
            //Session["NgayNhanHang"] = DateTime.Parse(DateTime.Now.AddDays(+5).ToString("dd-MM-yyyy"));
            int    x        = 0;
            string danggiao = "Đang giao";
            string ngaygiao = "2019/12/1";

            if (Session["Email"] == null && Session["username"] == null)
            {
                return(RedirectToAction("DangNhap", "TaiKhoan"));
            }
            else
            {
                if (Session["username"] != null)
                {
                    x = int.Parse(Session["makh"].ToString());
                }
                else
                {
                    x = int.Parse(Session["MaKH"].ToString());
                }
                var user = db.KhachHangs.FirstOrDefault(n => n.MaKH == x);

                if (user.DiaChiKH == null || user.SoDienThoaiKH == null)
                {
                    user = db.KhachHangs.Find(x);
                    {
                        user.SoDienThoaiKH = frm["dienthoainhanhang"];
                        user.DiaChiKH      = frm["diachinhanhang"];
                    };
                    if (Session["username"] != null)
                    {
                        db.Entry(user);
                        donhang.MaKH        = int.Parse(Session["makh"].ToString());
                        donhang.NgayDatHang = DateTime.Parse(DateTime.Now.ToString());
                        //donhang.NgayGiaoHang = ngaygiao;
                        donhang.TongTien      = decimal.Parse(Session["TongTien"].ToString());
                        donhang.TrangThai     = danggiao;
                        donhang.TenNguoiNhan  = frm["tennguoinhan"];
                        donhang.DienThoaiKH   = frm["dienthoainhanhang"];
                        donhang.DiaChiNhan    = frm["diachinhanhang"];
                        donhang.EmailNhanHang = frm["email"];
                        db.DonHangs.Add(donhang);
                        db.SaveChanges();
                        List <SanPhamGH> listSP = LayGioHang();
                        foreach (var item in listSP)
                        {
                            ChiTietDH ctdh = new ChiTietDH();
                            ctdh.SoDH    = donhang.SoHD;
                            ctdh.MaSP    = item.MaSP;
                            ctdh.SoLuong = item.SoLuongMua;
                            ctdh.DonGia  = (decimal)item.DonGia;
                            db.ChiTietDHs.Add(ctdh);
                            db.SaveChanges();
                        }
                        Session["GioHang"] = null;
                        return(RedirectToAction("ThanhToanThanhCong", "GioHang"));
                    }
                    else
                    {
                        db.Entry(user);
                        donhang.MaKH        = int.Parse(Session["MaKH"].ToString());
                        donhang.NgayDatHang = DateTime.Parse(DateTime.Now.ToString());
                        //donhang.NgayGiaoHang = ngaygiao;
                        donhang.TongTien      = decimal.Parse(Session["TongTien"].ToString());
                        donhang.TrangThai     = danggiao;
                        donhang.TenNguoiNhan  = frm["tennguoinhan"];
                        donhang.DienThoaiKH   = frm["dienthoainhanhang"];
                        donhang.DiaChiNhan    = frm["diachinhanhang"];
                        donhang.EmailNhanHang = frm["email"];
                        db.DonHangs.Add(donhang);
                        db.SaveChanges();
                        List <SanPhamGH> listSP = LayGioHang();
                        foreach (var item in listSP)
                        {
                            ChiTietDH ctdh = new ChiTietDH();
                            ctdh.SoDH    = donhang.SoHD;
                            ctdh.MaSP    = item.MaSP;
                            ctdh.SoLuong = item.SoLuongMua;
                            ctdh.DonGia  = (decimal)item.DonGia;
                            db.ChiTietDHs.Add(ctdh);
                            db.SaveChanges();
                        }

                        Session["GioHang"] = null;
                        return(RedirectToAction("ThanhToanThanhCong", "GioHang"));
                    }
                }
                else
                {
                    if (Session["username"] != null)
                    {
                        donhang.MaKH        = int.Parse(Session["makh"].ToString());
                        donhang.NgayDatHang = DateTime.Parse(DateTime.Now.ToString());
                        //donhang.NgayGiaoHang = DateTime.Parse(DateTime.Now.AddDays(+5).ToString("dd-MM-yyyy"));
                        donhang.TongTien      = decimal.Parse(Session["TongTien"].ToString());
                        donhang.TrangThai     = danggiao;
                        donhang.TenNguoiNhan  = frm["tennguoinhan"];
                        donhang.DienThoaiKH   = frm["dienthoainhanhang"];
                        donhang.DiaChiNhan    = frm["diachinhanhang"];
                        donhang.EmailNhanHang = frm["email"];
                        db.DonHangs.Add(donhang);
                        db.SaveChanges();
                        List <SanPhamGH> listSP = LayGioHang();
                        foreach (var item in listSP)
                        {
                            ChiTietDH ctdh = new ChiTietDH();
                            ctdh.SoDH    = donhang.SoHD;
                            ctdh.MaSP    = item.MaSP;
                            ctdh.SoLuong = item.SoLuongMua;
                            ctdh.DonGia  = (decimal)item.DonGia;
                            db.ChiTietDHs.Add(ctdh);
                            db.SaveChanges();
                        }

                        Session["Madh"] = donhang.SoHD;
                        return(RedirectToAction("ThanhToanThanhCong", "GioHang"));
                    }
                    else
                    {
                        donhang.MaKH        = int.Parse(Session["MaKH"].ToString());
                        donhang.NgayDatHang = DateTime.Parse(DateTime.Now.ToString());
                        //donhang.NgayGiaoHang = DateTime.Parse(DateTime.Now.AddDays(+5).ToString("dd-MM-yyyy"));
                        donhang.TongTien      = decimal.Parse(Session["TongTien"].ToString());
                        donhang.TrangThai     = danggiao;
                        donhang.TenNguoiNhan  = frm["tennguoinhan"];
                        donhang.DienThoaiKH   = frm["dienthoainhanhang"];
                        donhang.DiaChiNhan    = frm["diachinhanhang"];
                        donhang.EmailNhanHang = frm["email"];
                        db.DonHangs.Add(donhang);
                        db.SaveChanges();
                        List <SanPhamGH> listSP = LayGioHang();
                        foreach (var item in listSP)
                        {
                            ChiTietDH ctdh = new ChiTietDH();
                            ctdh.SoDH    = donhang.SoHD;
                            ctdh.MaSP    = item.MaSP;
                            ctdh.SoLuong = item.SoLuongMua;
                            ctdh.DonGia  = (decimal)item.DonGia;
                            db.ChiTietDHs.Add(ctdh);
                            db.SaveChanges();
                        }

                        Session["Madh"] = donhang.SoHD;
                        return(RedirectToAction("ThanhToanThanhCong", "GioHang"));
                    }
                }
            }
        }