示例#1
0
 /// <summary>
 /// 删除购物车一条食物
 /// </summary>
 /// <param name="orderfood"></param>
 public void DeleteOrderFood(OrderFood orderfood)
 {
     using (ITransaction tx = Session.BeginTransaction())
     {
         try
         {
             Session.Delete(orderfood);
             Session.Flush();
             tx.Commit();
         }
         catch (HibernateException)
         {
             tx.Rollback();
             throw;
         }
     }
 }
示例#2
0
        /// <summary>
        /// 修改购物车食物数量
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="foodid"></param>
        public void ModifyFoodNum(int userid, int foodid, int foodnum)
        {
            IList<Order> productCarOrder = _order.GetOrderInProductCar(userid);
            int orderid = -1;
            if (productCarOrder.Count > 0)
            {
                orderid = productCarOrder.First().OrderId;
            }
            IList<OrderFood> oflist = _orderfood.GetOrderFoodByOrderIdAndFoodId(orderid, foodid);

            OrderFood orderfood = new OrderFood();
            if (oflist.Count > 0)
            {
                orderfood = oflist.First();
                orderfood.FoodNum = foodnum;
            }
            _orderfood.UpdateOrderFood(orderfood);
        }
示例#3
0
 /// <summary>
 /// 创建订单食物
 /// </summary>
 /// <param name="orderfood"></param>
 /// <returns></returns>
 public int CreateOrderFood(OrderFood orderfood)
 {
     using (ITransaction tx = Session.BeginTransaction())
     {
         try
         {
             int orderfoodid = (int)Session.Save(orderfood);
             Session.Flush();
             tx.Commit();
             return orderfoodid;
         }
         catch (HibernateException)
         {
             tx.Rollback();
             return -1;
             throw;
         }
     }
 }
示例#4
0
        public void GetFoodItemByOrderFoodListTest()
        {
            IList<OrderFood> orderfoodlist = new List<OrderFood>();
            IList<FoodItem> fooditemlist = new List<FoodItem>();

            OrderFood of = new OrderFood
            {
                FoodId = 1,
                OrderId = 2,
                FoodNum = 2
            };
            orderfoodlist.Add(of);
            fooditemlist = _orderControl.GetFoodItemByOrderFoodList(orderfoodlist);
            Assert.AreEqual(fooditemlist.First().FoodName, "鱼香茄子");
        }
示例#5
0
 /// <summary>
 /// 将食物放入购物车中
 /// </summary>
 /// <param name="orderid"></param>
 /// <param name="foodid"></param>
 private void PutInCar(int orderid, int foodid)
 {
     IList<OrderFood> of =  _orderfood.GetOrderFoodByOrderIdAndFoodId(orderid, foodid);
     if (of.Count > 0)
     {
         //已经存在食物,将数量加1
         _orderfood.AddFoodNum(orderid, foodid, 1);
     }
     else
     {
         //购物车中不存在食物,新增一个食物到数据库中
         OrderFood orderfood = new OrderFood
         {
             OrderId = orderid,
             FoodId = foodid,
             FoodNum = 1
         };
         _orderfood.CreateOrderFood(orderfood);
     }
 }