Exemple #1
0
        public static int UpdateOrder(Orders order, ref List <string> errors)
        {
            if (order == null)
            {
                errors.Add("Order cannot be null");
            }

            if (errors.Count > 0)
            {
                return(-1);
            }

            if (order.order_id <= 0)
            {
                errors.Add("Invalid order id");
            }
            if (order.customer_id < 0)
            {
                errors.Add("Invalid customer id");
            }
            if (order.subtotal < 0)
            {
                errors.Add("Invalid subtotal range");
            }
            if (order.tax_total < 0)
            {
                errors.Add("Invalid taxtotal range");
            }
            if (order.grand_total < 0)
            {
                errors.Add("Invalid grand total range");
            }
            if (order.subtotal + order.tax_total != order.grand_total)
            {
                errors.Add("Invalid amount");
            }
            if (order.condition != 'a' && order.condition != 'd' && order.condition != 's')
            {
                errors.Add("Invalid order condition");
            }


            if (errors.Count > 0)
            {
                return(-1);
            }

            return(DALOrders.UpdateOrder(order, ref errors));
        }
Exemple #2
0
        public void UpdateOrdersTest()
        {
            List <string> errors = new List <string>();

            Orders order = new Orders();

            order.order_id     = 1;
            order.customer_id  = 1;
            order.grand_total  = 0;
            order.tax_total    = 0;
            order.subtotal     = order.grand_total + order.tax_total;
            order.date_created = new DateTime();
            order.condition    = 'a';

            int id = DALOrders.CreateOrder(order, ref errors);

            Assert.AreEqual(0, errors.Count);
            Assert.AreNotEqual(-1, id);

            Orders temp = null;

            temp = DALOrders.ReadOrder(id, ref errors);
            Assert.AreEqual(0, errors.Count);

            Assert.AreEqual(order.subtotal, temp.subtotal);
            Assert.AreEqual(order.customer_id, temp.customer_id);
            Assert.AreEqual(order.grand_total, temp.grand_total);
            Assert.AreEqual(order.tax_total, temp.tax_total);
            Assert.AreEqual(order.condition, temp.condition);

            //update order
            order.order_id  = id;
            order.condition = 's';
            int status = DALOrders.UpdateOrder(order, ref errors);

            temp = DALOrders.ReadOrder(id, ref errors);
            Assert.AreEqual(0, errors.Count);
            Assert.AreEqual(1, status);

            Assert.AreEqual(order.subtotal, temp.subtotal);
            Assert.AreEqual(order.customer_id, temp.customer_id);
            Assert.AreEqual(order.grand_total, temp.grand_total);
            Assert.AreEqual(order.tax_total, temp.tax_total);
            Assert.AreEqual(order.condition, temp.condition);
        }
Exemple #3
0
        public static int UpdateOrderItem(Orders order, Order_item oi, ref List <string> errors)
        {
            if (order == null || oi == null)
            {
                errors.Add("Order cannot be null");
            }
            if (errors.Count > 0)
            {
                return(-1);
            }
            if (order.order_id <= 0 || oi.order_id <= 0)
            {
                errors.Add("Invalid order id");
            }
            if (oi.product_variation_id < 0)
            {
                errors.Add("Invalid product variation id");
            }
            if (oi.tax < 0)
            {
                errors.Add("Invalid tax range");
            }
            if (oi.quantity < 0)
            {
                errors.Add("Invalid quantity");
            }
            if (oi.sale_price < 0)
            {
                errors.Add("Invalid sale price");
            }
            if (oi.condition != 'a' && oi.condition != 'd')
            {
                errors.Add("Invalid order item condition");
            }


            if (errors.Count > 0)
            {
                return(-1);
            }

            return(DALOrders.UpdateOrder(order, ref errors));
        }