示例#1
0
        public void TestAddOrder1()
        {
            OrderBL obl = new OrderBL();
            Orders  or  = new Orders();

            Assert.Null(obl.AddOrder(or));
        }
示例#2
0
        public ActionResult Order(OrderVM oVM)
        {
            OrderBL orderBL = new OrderBL();
            Order   o       = oVM.order;

            o.username   = Session["login"].ToString();
            o.status     = "In Process";
            o.status_lng = orderBL.Status_Lng(o.status);
            if (ModelState.IsValid)
            {
                orderBL.AddOrder(o);
            }
            return(RedirectToAction("MyOrders"));
        }
示例#3
0
        public void TestAddOrder()
        {
            OrderBL      obl = new OrderBL();
            Orders       or  = new Orders();
            Employees    e   = new Employees();
            OrderDetails od  = new OrderDetails();

            or.BooksList       = new List <OrderDetails>();
            or.ID_Order        = 1;
            or.creation_time   = DateTime.Now;
            e.ID_E             = 1;
            or.ID_E            = e;
            od.book.ID_Book    = 1;
            od.book.unit_price = 10000;
            od.quantity        = 1;
            or.BooksList.Add(od);
            Assert.NotNull(obl.AddOrder(or));
        }
        public IActionResult CreateOrder(OrderCreateModel orderCreate)
        {
            orderCreate.PostId    = _post.PostId;
            orderCreate.ProductId = _product.ProductId;
            orderCreate.UserTo    = _userTo.Id;
            orderCreate.UserFrom  = _uow.UserManager.FindByNameAsync(HttpContext.User?.Identity?.Name).Result.Id;
            var product = _uow.ProductRepository.List().Where(p => p.ProductId == _product.ProductId).FirstOrDefault();

            if (orderCreate.ProductCount > product.Count)
            {
                orderCreate.ProductCount = product.Count;
            }
            var validator = new OrderCreateValidator();

            if (validator.Validate(orderCreate).IsValid)
            {
                var orderBL = new OrderBL(_uow, _mapper);
                if (orderBL.AddOrder(orderCreate))
                {
                    return(RedirectToAction("AccountPage", "Account"));
                }
            }
            return(RedirectToAction());
        }
示例#5
0
        public static void Order(Customer c)
        {
            string          choice1 = "";
            OrderBL         orderbl = new OrderBL();
            Orders          o       = new Orders();
            List <Items>    lito    = new List <Items>();
            CategoryBL      cbl     = new CategoryBL();
            List <Category> lc      = new List <Category>();

            lc = cbl.GetCategory();
            Console.WriteLine("___________________________________________");
            Console.WriteLine("|----------- Danh Mục Sản Phẩm -----------|");
            Console.WriteLine("|-----------------------------------------|");
            foreach (var item in lc)
            {
                Console.WriteLine("|" + item.CategoryID + " | " + item.CategoryName);
            }
            int choice;

            do
            {
                Console.Write("-chọn: ");

                choice = Convert.ToInt32(Console.ReadLine());
            } while ((choice < 1) || (choice > lc.Count));
            Item_BL      ibl = new Item_BL();
            List <Items> lit = new List <Items>();

            lit = ibl.getItemByCategoryId(choice);
            while (true)
            {
                Console.Clear();
                Console.WriteLine("___________________________________________________________________________________________________________");
                Console.WriteLine("|========================================== Sản Phẩm ======================================================|");
                Console.WriteLine("|__________________________________________________________________________________________________________|");
                Console.WriteLine("|ID  |                 Tên Sản Phẩm                        |        Giá Sản Phẩm      |    Số Lượng        |");
                foreach (var item in lit)
                {
                    Console.WriteLine("|{0,-3} | {1,-51} | {2,21} VND| {3,-14} ", item.ItemId, item.ItemName, item.ItemPrice, item.ItemAmount);
                    Console.WriteLine("|----------------------------------------------------------------------------------------------------------|");
                }
                Console.Write("1.Chọn ID sản phẩm bạn muốn mua :");


                int product;


                Items io = null;
                while (true)
                {
                    product = Validate.InputInt(Console.ReadLine());
                    int count = 0;
                    foreach (var iteml in lit)
                    {
                        if (product == iteml.ItemId)
                        {
                            count++;
                        }
                    }
                    if (count == 0)
                    {
                        Console.Write("Không có sản phẩm này trong danh mục bạn chọn , mời nhập lại: ");
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
                io = ibl.getItemById(product);
                int quantity;
                Console.Write(" Nhập số lượng: ");
                while (true)
                {
                    quantity = Validate.InputInt(Console.ReadLine());
                    if (quantity <= io.ItemAmount)
                    {
                        break;
                    }
                    Console.Write("Số lượng không đúng, mời nhập lại: ");
                }

                io.ItemAmount = quantity;
                int dem   = 0;
                int index = 0;
                foreach (var item in lito)
                {
                    if (item.ItemId == product)
                    {
                        dem++;
                        break;
                    }
                    index++;
                }
                if (io.ItemAmount != 0 && dem == 0)
                {
                    lito.Add(io);
                }
                else if (dem > 0)
                {
                    lito[index].ItemAmount += quantity;
                }
                while (true)
                {
                    Console.WriteLine("Bạn có muốn tiếp tục thêm sản phẩm không? (C/K) ");
                    choice1 = Console.ReadLine().ToUpper();
                    switch (choice1)
                    {
                    case "C":
                        Console.Clear();
                        break;

                    case "K":
                        Console.Clear();
                        break;

                    default:
                        continue;
                    }
                    break;
                }
                if (choice1 == "C")
                {
                    Console.Clear();

                    continue;
                }
                else if (choice1 == "K")
                {
                    Console.Clear();

                    break;
                }
            }
            // listitem = lito;
            Console.WriteLine("____________________________________________________________________________________________________");
            Console.WriteLine("|-----------------------------------------Đơn Hàng--------------------------------------------------|");
            Console.WriteLine("| Tên Sản Phẩm                                   |   Số Lượng   | Giá Sản Phẩm      |  Thành Tiền   |");
            Console.WriteLine("----------------------------------------------------------------------------------------------------");
            decimal totalprice = 0;

            // Console.WriteLine(o.listItems.Count);
            foreach (var item in lito)
            {
                decimal a = 0;
                a           = item.ItemPrice * item.ItemAmount;
                totalprice += a;

                Console.WriteLine("|{0,-48}|{1,-14}|{2,15} VND|{3,11} VND|", item.ItemName, item.ItemAmount, pricevalid(item.ItemPrice), a);
            }
            Console.WriteLine("_____________________________________________________________________________________________________");
            Console.WriteLine("Tổng tiền:                                                                              {0} VND", pricevalid(totalprice));

            while (true)
            {
                Console.Write("Bạn có muốn thanh toán đơn hàng? (C/K)?");
                choice1 = Console.ReadLine().ToUpper();
                switch (choice1)
                {
                case "C":

                    break;

                case "K":
                    Console.Clear();
                    return;

                default:
                    continue;
                }
                break;
            }
            Console.Write("Nhập số tiền khách trả(đồng): ");
            decimal cusmoney;

            while (true)
            {
                try
                {
                    cusmoney = Convert.ToDecimal(Console.ReadLine());
                    if (cusmoney < 0)
                    {
                        Console.Write("Số tiền trả không thể nhỏ hơn 0, mời bạn nhập lại(đồng): ");
                        continue;
                    }
                    else if (cusmoney > 999999999)
                    {
                        Console.Write("Số tiền quá lớn, mời nhập lại(đồng): ");
                        continue;
                    }
                    else if (cusmoney < totalprice)
                    {
                        Console.Write("Số tiền trả không đủ, mời nhập lại(đồng): ");
                        continue;
                    }
                }
                catch (System.Exception)
                {
                    Console.Write("Dữ liệu nhập vào không đúng hoặc số tiền quá lớn, mời bạn nhập lại(đồng): ");
                    continue;
                }
                break;
            }
            if ((cusmoney - totalprice) > 0)
            {
                Console.WriteLine("Tiền trả lại: {0} VND", pricevalid(cusmoney - totalprice));
            }
            Customer_Bl cbl1 = new Customer_Bl();

            o.listItems = lito;
            // Console.WriteLine(o.listItems.ToString());
            o.customer = c;
            o.Status   = 1;
            Console.WriteLine(" Tạo Order " + (orderbl.AddOrder(o) ? "Hoàn tất!" : "Không hoàn tất!") + " Ấn phím bất kì để thoát!");
            // listitem = o.listItems;
            Console.ReadKey();

            Console.Clear();
            // List<Items> newlit = ibl.GetItemsByOrderId();
        }
示例#6
0
        public void Menu012()
        {
            _i = 0;
            if (lb.Count == 0)
            {
                Console.Clear();
                Console.Write("- Chưa tạo đơn hàng ! Bấm phím bất kỳ để quay lại ....");
                Console.ReadKey();
                Menu010();
            }
            Console.Clear();
            decimal a = 0;

            Console.WriteLine("=======================================================================================================");
            Console.WriteLine("                                        CỬA HÀNG SÁCH THẾ GIỚI                                         \n");
            Console.WriteLine("-------------------------------------------------------------------------------------------------------");
            Console.WriteLine("                                             ĐƠN HÀNG SÁCH                                             ");
            Console.WriteLine(" Mã đơn hàng: OD{0}", order.GetOrder() + 1);
            _i = order.GetOrder();
            Console.WriteLine("-------------------------------------------------------------------------------------------------------");
            Console.WriteLine(" Mã sách  | Tên sách                | Tên tác giả              | Đơn giá     | SL   | Thành tiền       ");
            Console.WriteLine(" -------    --------                  -----------                -------       --     ----------       ");
            for (int i = 0; i < lb.Count; i++)
            {
                string idbook   = " MN" + lb[i].ID_Book + new string(' ', 7 - lb[i].ID_Book.ToString().Length);
                string bookname = " " + lb[i].book_title + new string(' ', 24 - lb[i].book_title.Length);
                string author   = " " + lb[i].author + new string(' ', 25 - lb[i].author.Length);
                string dongia   = " " + string.Format("{0:0,0}", lb[i].unit_price) + new string(' ', 9 - string.Format("{0:0,0}", lb[i].unit_price).ToString().Length) + "VNĐ";
                string sl       = " " + o.BooksList[i].quantity + new string(' ', 5 - o.BooksList[i].quantity.ToString().Length);
                string tt       = " " + string.Format("{0:0,0}", o.BooksList[i].quantity * lb[i].unit_price) + new string(' ', 13 - string.Format("{0:0,0}", o.BooksList[i].quantity * lb[i].unit_price).ToString().Length) + "VNĐ";
                Console.WriteLine(idbook + "|" + bookname + "|" + author + "|" + dongia + "|" + sl + "|" + tt + "|");
                a = a + lb[i].unit_price * o.BooksList[i].quantity;
            }
            Console.WriteLine("-------------------------------------------------------------------------------------------------------\n");
            Console.WriteLine("                                                                    Tổng tiền: " + string.Format("{0:0,0}", a) + new string(' ', 20 - string.Format("{0:0,0}", a).ToString().Length) + "VNĐ\n");
            Console.WriteLine("                                                                    -----------------------------------\n");
            for (; ;)
            {
                Console.Write("-Xác nhận thanh toán(C/K): ");
                string chon = Console.ReadLine();
                if (chon == "C" || chon == "c")
                {
                    string price = "";
                    for (; ;)
                    {
                        Console.Write("-Nhập số tiền khách thanh toán: ");
                        price = Console.ReadLine();
                        if (TryParse(price) >= Convert.ToInt32(a))
                        {
                            tt.Tienthanhtoan = Convert.ToDecimal(price);
                            order.AddOrder(o);
                            break;
                        }
                        else
                        {
                            Console.WriteLine("- Số tiền bạn nhập không đúng ! Vui lòng nhập lại !");
                        }
                    }
                    Console.Clear();
                    decimal b = 0;
                    o.creation_time = DateTime.Now;
                    Console.WriteLine("=======================================================================================================");
                    Console.WriteLine("                                          CỬA HÀNG SÁCH TG                                          \n");
                    Console.WriteLine("-------------------------------------------------------------------------------------------------------");
                    Console.WriteLine("                                                                         Ngày bán: " + new string(' ', 20 - string.Format("{0:dd/MM/yyyy hh:mm tt}", o.creation_time).ToString().Length) + string.Format("{0:dd/MM/yyyy hh:mm tt}", o.creation_time));
                    Console.WriteLine("                                       ***HÓA ĐƠN BÁN HÀNG***                                          ");
                    Console.WriteLine("- Mã hóa đơn : BL{0}", _i + 1);
                    Console.WriteLine("- Người bán  : " + e.full_name);
                    Console.WriteLine("-------------------------------------------------------------------------------------------------------");
                    Console.WriteLine(" Mã sách  | Tên sách                | Tên tác giả              | Đơn giá     | SL   | Thành tiền       ");
                    Console.WriteLine(" -------    --------                  -----------                -------       --     ----------       ");
                    for (int i = 0; i < lb.Count; i++)
                    {
                        string idbook   = " MN" + lb[i].ID_Book + new string(' ', 7 - lb[i].ID_Book.ToString().Length);
                        string bookname = " " + lb[i].book_title + new string(' ', 24 - lb[i].book_title.Length);
                        string author   = " " + lb[i].author + new string(' ', 25 - lb[i].author.Length);
                        string dongia   = " " + string.Format("{0:0,0}", lb[i].unit_price) + new string(' ', 9 - string.Format("{0:0,0}", lb[i].unit_price).ToString().Length) + "VNĐ";
                        string sl       = " " + o.BooksList[i].quantity + new string(' ', 5 - o.BooksList[i].quantity.ToString().Length);
                        string tt       = " " + string.Format("{0:0,0}", o.BooksList[i].quantity * lb[i].unit_price) + new string(' ', 13 - string.Format("{0:0,0}", o.BooksList[i].quantity * lb[i].unit_price).ToString().Length) + "VNĐ";
                        Console.WriteLine(idbook + "|" + bookname + "|" + author + "|" + dongia + "|" + sl + "|" + tt + "|");
                        b = b + lb[i].unit_price * o.BooksList[i].quantity;
                    }
                    Console.WriteLine("-------------------------------------------------------------------------------------------------------\n");
                    Console.WriteLine("                                                            + Tổng tiền      : " + string.Format("{0:0,0}", b) + new string(' ', 20 - string.Format("{0:0,0}", b).ToString().Length) + "VNĐ");
                    Console.WriteLine("                                                            + Tiền thanh toán: " + string.Format("{0:0,0}", Convert.ToDecimal(price)) + new string(' ', 20 - string.Format("{0:0,0}", Convert.ToDecimal(price)).ToString().Length) + "VNĐ");
                    Console.WriteLine("                                                            + Hoàn tiền      : " + string.Format("{0:0,0}", Convert.ToDecimal(price) - b) + new string(' ', 20 - string.Format("{0:0,0}", Convert.ToDecimal(price) - b).ToString().Length) + "VNĐ");
                    tt.Hoantien = Convert.ToDecimal(price) - b;
                    Console.WriteLine("---------------------------------------Hẹn gặp lại !!!-------------------------------------------------\n");
                    Console.Write("Bấm phím bất kỳ để quay lại.....");
                    Console.ReadKey();
                    ltt.Add(tt);
                    lb = new List <Books>();
                    o  = new Orders();
                    Menu010();
                    break;
                }
                else if (chon == "K" || chon == "k")
                {
                    lb = new List <Books>();
                    o  = new Orders();
                    Menu010();
                    break;
                }
                else
                {
                    Console.WriteLine("- Ký tự bạn nhập không đúng ! Vui lòng nhập lại !");
                }
            }
        }