Example #1
0
 public ActionResult Buy(int? id)
 {
     if (!CurrentUser.IsAuthenticated) return RedirectToAction("LogIn", "Account");
     if (id != null)
     {
         Item item = yikuData.GetItem(id.Value);
         T_Shopping tsh = new T_Shopping();
         if (item != null)
         {
             if (item.PublisherID == yikuData.UserCurrent.UID) return RedirectToAction("Details", "Item", new { ID = id.Value });
             tsh = yikuData.AddShopping(yikuData.UserCurrent, item);
             yikuData.Save();
             return RedirectToAction("Index", "Cart");
         }
     }
     return RedirectToAction("Index", "Item");
 }
 public T_Shopping AddShopping(User user, Item item, int Count, string Cut = null)
 {
     T_Shopping tsh = GetT_Shopping(item, user);
     if (tsh == null)
     {
         tsh = new T_Shopping();
         tsh.UID = user.UID;
         tsh.IID = item.IID;
         tsh.Count = Count;
         tsh.Cut = Cut;
         Add(tsh);
     }
     else
     {
         tsh.Count += Count;
         if (Cut != null)
             tsh.Cut = Cut;
     }
     return tsh;
 }
Example #3
0
 /// <summary>
 /// 用于向 T_Shopping EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
 /// </summary>
 public void AddToT_Shopping(T_Shopping t_Shopping)
 {
     base.AddObject("T_Shopping", t_Shopping);
 }
Example #4
0
 /// <summary>
 /// 创建新的 T_Shopping 对象。
 /// </summary>
 /// <param name="t_Sh_ID">T_Sh_ID 属性的初始值。</param>
 /// <param name="uID">UID 属性的初始值。</param>
 /// <param name="iID">IID 属性的初始值。</param>
 /// <param name="count">Count 属性的初始值。</param>
 public static T_Shopping CreateT_Shopping(global::System.Int32 t_Sh_ID, global::System.Int32 uID, global::System.Int32 iID, global::System.Int32 count)
 {
     T_Shopping t_Shopping = new T_Shopping();
     t_Shopping.T_Sh_ID = t_Sh_ID;
     t_Shopping.UID = uID;
     t_Shopping.IID = iID;
     t_Shopping.Count = count;
     return t_Shopping;
 }
Example #5
0
        public ActionResult Details(int id, FormCollection collection)
        {
            if(!CurrentUser.IsAuthenticated)return RedirectToAction("LogIn", "Account");

            int num = 0;
            if (!string.IsNullOrEmpty(Request.Form["BuyNumber"]))
                try
                {
                    num = Convert.ToInt32(Request.Form["BuyNumber"]);
                }
                catch { return RedirectToAction("Error", "Item", new { Id = id, Errorm = "请输入正确的购买数量" }); }
            else
                return RedirectToAction("Error", "Item", new { Id = id, Errorm = "请输入购买数量" });

            Item item = yikuData.GetItem(id);
            T_Shopping tsh = new T_Shopping();
            if(item != null){
                if (item.PublisherID == yikuData.UserCurrent.UID)
                    return RedirectToAction("Error", "Item", new { Id = id , Errorm = "不能购买自己的商品" });

                tsh = yikuData.AddShopping(yikuData.UserCurrent, item);
                yikuData.Save();
                tsh.Count += (num - 1);
                yikuData.Save();
                return RedirectToAction("Index", "Cart");
            }

            return RedirectToAction("Details", "Item", new { Id = id });
        }