コード例 #1
0
        public void AddItemToOrder(int orderId, int itemId, int resId)
        {
            var ordC = new OrderCtrl();
            var db   = new JustFeastDbDataContext();
            var item = db.Items.SingleOrDefault(i => i.id == itemId);

            if (orderId == 0)
            {
                orderId = ordC.GetLastOrderIdentity() + 1;
                var order = new DatabaseAccessLibrary.Order
                {
                    id           = orderId,
                    restaurantId = resId
                };
                db.Orders.InsertOnSubmit(order);
            }
            var exists = db.OrderLineItems.SingleOrDefault(i => i.itemId == itemId && i.orderId == orderId);

            if (exists != null)
            {
                exists.quantity++;
            }
            else if (item != null)
            {
                var oli = new DatabaseAccessLibrary.OrderLineItem
                {
                    orderId  = orderId,
                    itemId   = item.id,
                    quantity = 1
                };
                db.OrderLineItems.InsertOnSubmit(oli);
            }
            db.SubmitChanges();
        }
コード例 #2
0
        public void Get_Last_Identity_Test()
        {
            //Setup
            var ordC = new OrderCtrl();

            //Assert
            Assert.IsTrue(ordC.GetLastOrderIdentity() == 1000005);
        }
コード例 #3
0
        public void Add_Order_To_Database_Test()
        {
            //Setup
            var ordCtrl = new OrderCtrl();
            var ordDb   = new OrderDb();
            var dt      = new DateTime(2018, 11, 08, 12, 22, 33);
            var resDt   = new DateTime(2018, 11, 08, 18, 00, 00);
            var oli     = new List <OrderLineItem>();
            var item    = new ModelLibrary.Item();

            item.Id = 1000000;
            oli.Add(new OrderLineItem(item, 2));

            var order = new Order
            {
                OrderId             = (ordCtrl.GetLastOrderIdentity() + 1).ToString(),
                CustomerId          = "1000000",
                RestaurantId        = "1000000",
                DateTime            = "2018-11-08 12:22:33",
                ReservationDateTime = "2018-11-08 18:00:00",
                ItemsList           = oli,
                NoSeats             = "2",
                Payment             = "200.00",
                Accepted            = false
            };

            //Act
            var oliList = ordCtrl.ConvertOrderLineItemsToDb(order);
            var dbOrder = ordCtrl.ConvertOrder(order);

            for (var i = 0; i < dbOrder.OrderLineItems.Count - 1; i++)
            {
                dbOrder.OrderLineItems.Add(oliList[i]);
            }
            ordDb.AddOrder(dbOrder);

            //Assert
            Assert.IsTrue(ordCtrl.GetLastOrderIdentity() == Convert.ToInt32(order.OrderId));
        }