コード例 #1
0
ファイル: CartController.cs プロジェクト: SheeranX/Umusic
        /// <summary>
        /// 插入购物车
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public int CartId(string username)
        {
            tb_cart      cart  = new tb_cart();
            SqlParameter uname = new SqlParameter("@username", username);
            int          id    = (from u in musicDB.tb_user
                                  where u.UserName == username
                                  select u.UserId).Single();

            return(id);
        }
コード例 #2
0
        public ActionResult Login(string login_username, string login_password)
        {
            // string url = Request.RawUrl;
            int count = (from user in musicDB.tb_user
                         where (user.UserName == login_username && user.password == login_password) ||
                         (user.phone == login_username && user.password == login_password) ||
                         (user.email == login_username && user.password == login_password)
                         select user
                         ).Count();

            if (count > 0)
            {
                Session["username"] = (from u in musicDB.tb_user
                                       where u.UserName == login_username || u.phone == login_username || u.email == login_username
                                       select u.UserName).Single();
                string username = Session["username"].ToString();
                //regist a shop car when uer login in
                int userid = (from u in musicDB.tb_user
                              where u.UserName == username
                              select u.UserId).Single();
                int countuser = (from c in musicDB.tb_cart
                                 where c.userId == userid
                                 select c.cartId).Count();
                if (countuser > 0)
                {
                    if (Session["url"] == null || Session["url"] == "")
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                    return(Redirect(Session["url"].ToString()));
                }
                // return RedirectToAction("Index", "Home");

                else
                {
                    tb_cart cart = new tb_cart();
                    cart.userId = (from u in musicDB.tb_user
                                   where u.UserName == username
                                   select u.UserId).Single();
                    musicDB.tb_cart.Add(cart);
                    musicDB.SaveChanges();
                    return(RedirectToAction("Index", "Home"));
                }
            }

            else
            {
                ViewBag.warning = "";
                return(View());
            }
        }