Ejemplo n.º 1
0
 public ActionResult addToBuyCar(int id)
 {
     if (Session["userLogin"] != null)
     {
         string uname = Session["userLogin"].ToString();
         Models.BookShopEntities4 db = new Models.BookShopEntities4();
         Models.bookInfo          bi = db.bookInfo.Where(a => a.bookID == id && a.isDel != "Y").FirstOrDefault();
         if (bi != null)
         {
             Models.buyCar bCar   = db.buyCar.Where(b => b.booksID == id && b.buyUser == uname).FirstOrDefault();
             string        output = "";
             if (bCar == null)
             {
                 Models.buyCar newAdd = new Models.buyCar()
                 {
                     booksID = id,
                     buyNum  = 1,
                     buyUser = Session["userLogin"].ToString()
                 };
                 db.buyCar.Add(newAdd);
                 output = "加入购物车成功";
             }
             else
             {
                 Models.bookInfo binfo = db.bookInfo.Where(b => b.bookID == id).FirstOrDefault();
                 if (binfo.onlyBuy != null && bCar.buyNum >= binfo.onlyBuy)
                 {
                     bCar.buyNum = binfo.onlyBuy.Value;
                     output      = "该商品有限购规则,仅允许购买" + binfo.onlyBuy.Value + "个,已将购物车中该商品数量调整为最大购买数量";
                 }
                 else
                 {
                     bCar.buyNum += 1;
                     output       = "购物车中已存在该商品,商品数量加1";
                 }
             }
             db.SaveChanges();
             return(Content(output));
         }
         else
         {
             return(Content("该商品已经下架或者商品不存在,无法加入购物车"));
         }
     }
     else
     {
         return(Content("尚未登录,无法加入购物车,请先登录"));
     }
 }
Ejemplo n.º 2
0
 public ActionResult OrderProcessing(string toName, string toAddress, string toPhone, string userPay)
 {
     if (Session["userLogin"] != null)
     {
         string uName = Session["userLogin"].ToString();
         Models.BookShopEntities4 db = new Models.BookShopEntities4();
         Models.orderInfo         oi = new Models.orderInfo()
         {
             submitTime = System.DateTime.Now.ToString(),
             toAddress  = toAddress,
             toName     = toName,
             toPhone    = toPhone,
             buyUser    = uName,
             orderState = "等待系统处理",
             payType    = userPay
         };
         db.orderInfo.Add(oi);
         db.SaveChanges();
         var deleteQuery = db.buyCar.Where(e => e.buyUser == uName);
         // var orderId = db.buyCar.Where(e => e.buyUser == uName);
         //Models. bCar = db.buyCar.Where(b => b.booksID == id && b.buyUser == uname).FirstOrDefault();
         foreach (var item in deleteQuery)
         {
             Models.bookInfo     binfo = db.bookInfo.Where(b => b.bookID == item.booksID).FirstOrDefault();
             Models.orderDetails od    = new Models.orderDetails()
             {
                 orderId   = oi.orderId,
                 bookId    = item.booksID,
                 bookPrice = binfo.bookPrice,
                 buyNum    = item.buyNum
             };
             db.orderDetails.Add(od);
             db.buyCar.Remove(item);
         }
         db.SaveChanges();
         Response.Write("<script language='javaScript' type='text/javaScript'>window.onload=function(){layer.alert('订单提交成功',function (){location='/My/MyOrder'});}</script>");
         return(View());
     }
     else
     {
         return(RedirectToAction("otherLogin", "Login", new { m = "My", a = "Settlement" }));
     }
 }
Ejemplo n.º 3
0
 public ActionResult updateCartNum(int sysID, int newNum)
 {
     if (Session["userLogin"] != null)
     {
         string uname = Session["userLogin"].ToString();
         Models.BookShopEntities4 db   = new Models.BookShopEntities4();
         Models.buyCar            bCar = db.buyCar.Where(b => b.sysID == sysID && b.buyUser == uname).FirstOrDefault();
         int             id            = bCar.booksID;
         string          output        = "okay";
         Models.bookInfo binfo         = db.bookInfo.Where(b => b.bookID == id).FirstOrDefault();
         if (binfo.isDel != "Y")
         {
             if (binfo.onlyBuy != null && newNum >= binfo.onlyBuy)
             {
                 bCar.buyNum = binfo.onlyBuy.Value;
                 output      = "该商品有限购规则,仅允许购买" + binfo.onlyBuy.Value + "个,已将购物车中该商品数量调整为最大购买数量";
             }
             else
             {
                 bCar.buyNum = newNum;
                 output      = "okay";
             }
         }
         else
         {
             bCar.buyNum = 0;
             output      = "该商品已经下架或者不存在,数量自动调整为0个";
         }
         db.SaveChanges();
         return(Content(output));
     }
     else
     {
         return(Content("会话已失效,请重新登陆后再操作"));
     }
 }