public void QueryByCustomerNameTest()
        {
            Customer customer1 = new Customer(1, "a");
            Customer customer2 = new Customer(2, "b");

            Goods goods1 = new Goods(1, "book1", 1);
            Goods goods2 = new Goods(2, "book2", 2);
            Goods goods3 = new Goods(3, "book3", 3);

            Order order1 = new Order(1, customer1);

            order1.AddDetails(new OrderDetails(goods1, 1));
            order1.AddDetails(new OrderDetails(goods2, 2));

            Order order2 = new Order(2, customer2);

            order2.AddDetails(new OrderDetails(goods1, 1));

            OrderServices orderServices = new OrderServices();

            orderServices.AddOrder(order1);
            orderServices.AddOrder(order2);

            List <Order> expected = new List <Order>();

            expected.Add(order2);

            Assert.IsTrue(orderServices.QueryByCustomerName("b").SequenceEqual(expected));
        }
        public void GetByIdTest()
        {
            Customer      customer      = new Customer();
            Order         order1        = new Order(1, customer);
            Order         order2        = new Order(2, customer);
            Order         order3        = new Order(3, customer);
            OrderServices orderServices = new OrderServices();

            orderServices.AddOrder(order1);
            orderServices.AddOrder(order2);
            orderServices.AddOrder(order3);
            Assert.AreEqual(orderServices.GetById(2), order2);
        }
        public void RemoveOrderTest()
        {
            Customer      customer      = new Customer();
            Order         order1        = new Order(1, customer);
            Order         order2        = new Order(2, customer);
            Order         order3        = new Order(3, customer);
            OrderServices orderServices = new OrderServices();

            orderServices.AddOrder(order1);
            orderServices.AddOrder(order2);
            orderServices.AddOrder(order3);

            orderServices.RemoveOrder(1);
            Assert.IsNull(orderServices.GetById(1));
        }
Beispiel #4
0
        public void CheckOutItems()
        {
            Cart            cart  = cartServices.GetCartByCustId(customer.Id);
            List <CartItem> items = cartItemServices.GetAllCartItemsByCartId(cart.Id);
            Orders          order = new Orders();
            double          total = 0;

            order.CustomersId = customer.Id;
            order.LocationId  = customer.LocationId;
            DateTime dateOfOrder = order.dateOfOrder = DateTime.Now;

            orderServices.AddOrder(order);
            Orders orderToProcess = orderServices.GetOrderByDate(dateOfOrder);

            Console.WriteLine("You imaginary order has been placed. You will revieve it never. \n");
            foreach (CartItem item in items)
            {
                lineItem lineItem = new lineItem();
                Sticks   stick    = productServices.GetProductByStickId(item.stickId);
                lineItem.orderId  = orderToProcess.Id;
                lineItem.stickId  = item.stickId;
                lineItem.price    = stick.Price;
                lineItem.quantity = item.quantity;
                total            += (stick.Price * item.quantity);
                lineItemServices.AddLineItem(lineItem);
                cartItemServices.DeleteCartItem(item);
                Inventory inventory = inventoryServices.GetItemByLocIdStickId(customer.LocationId, stick.Id);
                inventory.quantity -= item.quantity;
            }
            order.TotalPrice = total;
            orderServices.UpdateOrder(orderToProcess);
            Console.WriteLine($"\nYour total was: ${order.TotalPrice}");
        }
        public void UpdateTest()
        {
            Order         order         = new Order();
            OrderServices orderServices = new OrderServices();

            orderServices.AddOrder(order);
            Assert.IsTrue(orderServices.orderList.Contains(order));
        }
Beispiel #6
0
 public IActionResult AddOrder(Order order)
 {
     try
     {
         _orderServices.AddOrder(order);
         return(CreatedAtAction("AddOrder", order));
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
Beispiel #7
0
        public void AddNewOrderToDB(object parameter)
        {
            var tokens        = (object[])parameter;
            var CustomerName  = tokens[0].ToString();
            var CustomerPhone = tokens[1].ToString();

            if (CustomerName == "" || CustomerPhone == "")
            {
                MessageBox.Show("Số điện và tên khách hàng không được trống");
            }
            else
            {
                var date = DateTime.Now.ToString("dd-MM-yyyy");
                Order.Date          = date;
                Order.CustomerName  = CustomerName;
                Order.CustomerPhone = CustomerPhone;
                OrderServices.AddOrder(Order);
                MessageBox.Show("Đã thêm đơn hàng mới");
            }
        }
Beispiel #8
0
        public IActionResult Order(IFormCollection collection)
        {
            var id      = HttpContext.Session.GetInt32("GadgetId");
            var userId  = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var address = collection["Address"].ToString();
            var phone   = collection["PhoneNumber"].ToString();

            if (id != null)
            {
                _orderServices.AddOrder(
                    new OrderModel
                {
                    GadgetId    = (int)id,
                    UserId      = userId,
                    Address     = address,
                    PhoneNumber = phone
                });
            }

            return(RedirectToAction("GadgetList", "Store"));
        }
Beispiel #9
0
        private void SaveOrder(OrderViewModel model)
        {
            string response = "";

            response = orderServices.AddOrder(model);
            if (response == "Success")
            {
                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "showAlert('Success','Order is booked.')", true);
                EmptyCart();
                // GenerateMsgForEmail(model);

                Thread email = new Thread(delegate()
                {
                    SendEmail(model);
                });
                email.IsBackground = true;
                email.Start();
            }
            else
            {
                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "showAlert('Error!','" + response + "')", true);
            }
        }