Пример #1
0
        public ActionResult GoogleLoginCallback()
        {
            var claimsPrincipal = HttpContext.User.Identity as ClaimsIdentity;

            var loginInfo = SSO.GetLoginInfo(claimsPrincipal);

            if (loginInfo == null)
            {
                return(RedirectToAction("Index"));
            }


            ASM_BookEntities db = new ASM_BookEntities(); //DbContext
            var user            = db.Users.FirstOrDefault(x => x.Email == loginInfo.emailaddress);

            if (user == null)
            {
                user = new User
                {
                    Email    = loginInfo.emailaddress,
                    Password = loginInfo.nameidentifier,
                    UserName = loginInfo.givenname,
                };
                db.Users.Add(user);
                db.SaveChanges();
            }

            Session["makh"] = user.MaKH;

            Session["usename"] = loginInfo.givenname;
            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.UserName),
                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("~/"));
        }
Пример #2
0
        public ActionResult ChiTietBook(int iMaSach, string iName, string iComment, string Ngay, Comment DG)
        {
            DG.BookId  = iMaSach;
            DG.HoTenKH = iName;
            DG.Content = iComment;

            DG.CreatedDate     = DateTime.Parse(Ngay);
            TempData["MaSach"] = iMaSach;
            db.Comments.Add(DG);
            db.SaveChanges();
            List <Comment> LDG = db.Comments.Where(n => n.BookId == iMaSach).ToList();


            return(RedirectToAction("BookSpecialParialView", "Home"));
        }
 public ActionResult Edit([Bind(Include = "BookId,Title,CateId,AuthorId,PubId,Summary,ImgUrl,Price,Quantity,CreatedDate,ModifiedDate,IsActive")] Book sach)
 {
     if (ModelState.IsValid)
     {
         db.Entry(sach).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(sach));
 }
Пример #4
0
        public ActionResult GioHang(FormCollection frm, DONDATHANG donhang)
        {
            if (Session["makh"] == null)
            {
                return(RedirectToAction("Index", "SSO"));
            }
            else
            {
                int x    = int.Parse(Session["makh"].ToString());
                var user = db.Users.FirstOrDefault(n => n.MaKH == x);
                if (user.DiaChi == null || user.DienThoaiKH == null)
                {
                    user = db.Users.Find(x);
                    {
                        user.DienThoaiKH = frm["dienthoainhanhang"];
                        user.DiaChi      = frm["diachinhanhang"];
                    };
                    db.Entry(user);
                    bool am = false;
                    donhang.MaKH   = int.Parse(Session["makh"].ToString());
                    donhang.NgayDH = DateTime.Parse(DateTime.Now.ToString());
                    //donhang.NgayGiaoHang = DateTime.Parse(frm["ngaynhanhang"].ToString());
                    donhang.TriGia        = decimal.Parse(Session["TongTien"].ToString());
                    donhang.TrangThai     = am;
                    donhang.TenNguoiNhan  = frm["tennguoinhan"];
                    donhang.DienThoaiNhan = int.Parse(frm["dienthoainhanhang"]);
                    donhang.DiaChiNhan    = frm["diachinhanhang"];

                    db.DONDATHANGs.Add(donhang);
                    db.SaveChanges();
                    List <SamPhamGH> listSP = LayGioHang();
                    foreach (var item in listSP)
                    {
                        CTDONHANG ctdh = new CTDONHANG();
                        ctdh.SoDH    = donhang.SoHD;
                        ctdh.MaSP    = item.BookId;
                        ctdh.SoLuong = item.SoLuongMua;
                        ctdh.DonGia  = (decimal)item.Price;
                        db.CTDONHANGs.Add(ctdh);
                        db.SaveChanges();
                    }
                    Session["GioHang"] = null;
                    return(RedirectToAction("ThanhToanThanhCong", "GioHang"));
                }
                else
                {
                    bool a = false;
                    donhang.MaKH   = int.Parse(Session["makh"].ToString());
                    donhang.NgayDH = DateTime.Parse(DateTime.Now.ToString());
                    //donhang.NgayGiaoHang = DateTime.Parse(frm["ngaynhanhang"].ToString());
                    donhang.TriGia        = decimal.Parse(Session["TongTien"].ToString());
                    donhang.TrangThai     = a;
                    donhang.TenNguoiNhan  = frm["tennguoinhan"];
                    donhang.DienThoaiNhan = int.Parse(frm["dienthoainhanhang"]);
                    donhang.DiaChiNhan    = frm["diachinhanhang"];
                    db.DONDATHANGs.Add(donhang);
                    db.SaveChanges();
                    List <SamPhamGH> listSP = LayGioHang();
                    foreach (var item in listSP)
                    {
                        CTDONHANG ctdh = new CTDONHANG();
                        ctdh.SoDH    = donhang.SoHD;
                        ctdh.MaSP    = item.BookId;
                        ctdh.SoLuong = item.SoLuongMua;
                        ctdh.DonGia  = (decimal)item.Price;
                        db.CTDONHANGs.Add(ctdh);
                        db.SaveChanges();
                    }
                    Session["Madh"] = donhang.SoHD;
                    return(RedirectToAction("ThanhToanThanhCong", "GioHang"));
                }
            }
        }