public void ShowOrder() { Console.Clear(); OrderBl orderBL = new OrderBl(); List <Order> listOrder = new List <Order>(); listOrder = orderBL.ShowAllItemOrdered(user.UserId); if (listOrder == null) { Console.ReadKey(); } else { if (listOrder.Count <= 0) { Console.WriteLine("Bạn chưa mua gì"); } else { var table = new ConsoleTable("Mã sách", "Tên sách", "Ngày mua"); foreach (var item in listOrder) { table.AddRow(item.OrderItem.ItemId, item.OrderItem.ItemName, item.OrderDate?.ToString("yyyy-MM-dd")); } table.Write(); } Console.WriteLine("Nhấn phím bất kì để tiếp tục"); Console.ReadKey(); } }
public void MenuCus(User us) { user = us; while (true) { OrderBl orderBl = new OrderBl(); string[] choice = { "Xem thông tin tài khoản", "Xem danh sách sách", $"Xem giỏ hàng ({orderBl.ShowShopingCartByUserId(user.UserId).Count} sp)", "Xem danh sách sách đã mua", "Thoát" }; short choose = Utility.MenuTemplate("Menu", choice); switch (choose) { case 1: ShowInfoCustomer(us); continue; case 2: ShowlistItems(); continue; case 3: ShopingCart(); continue; case 4: ShowOrder(); continue; } break; } }
public static short showListItems(string title, string[] menuItems, List <Item> items, int UserId) { Console.Clear(); Console.Clear(); short choice = -1; var table = new ConsoleTable("Mã sách", "Tên sách", "Giá sách", "Tác giả", "Danh mục"); OrderBl orderBL = new OrderBl(); foreach (Item item in items) { bool bought = false; if (item.ItemId != orderBL.CheckItemPurchase(item.ItemId, UserId)) { bought = true; } table.AddRow(item.ItemId, item.ItemName, bought == true ? FormatCurrency(item.ItemPrice) : "Đã mua", item.ItemAuthor, item.ItemCategory); } table.Write(); if (items.Count <= 0) { Console.WriteLine("Không tìm thấy sách"); } ItemBl itemBL = new ItemBl(); for (int i = 0; i < menuItems.Length; i++) { Console.WriteLine((i + 1) + ". " + menuItems[i]); } Console.WriteLine(row1); try { Console.Write("Chọn: "); choice = Int16.Parse(Console.ReadLine()); } catch (System.Exception) { } if (choice < 0 || choice > menuItems.Length) { do { try { Console.Write("#Bạn nhập sai vui lòng nhập lại: "); choice = Int16.Parse(Console.ReadLine()); } catch (System.Exception) { continue; } } while (choice < 0 || choice > menuItems.Length); } return(choice); }
public IHttpActionResult addOrder([FromBody] OrderDto order) { bool b = OrderBl.addOrder(order); if (b) { return(Ok()); } return(BadRequest()); }
public void CreateOrder(double total) { order.OrderUser = new User(); OrderBl orderBL = new OrderBl(); order.OrderUser = user; if (order.OrderUser.UserBalance < total) { Console.WriteLine("Bạn không đủ tiền vui lòng nạp thêm tiền"); } else { try { if (orderBL.CreateOrder(order, total)) { Console.Clear(); // Console.WriteLine("Mua hàng thành công"); userBL.UpdateStatusShoppingCartById(true, user.UserId); // set userShopping cart to 0 List <Order> shoppingCart = new List <Order>(); shoppingCart = orderBL.ShowOrderUserPaySucess(user.UserId); Console.WriteLine("HÓA ĐƠN"); Console.WriteLine("TÊN KHÁCH HÀNG: {0}", shoppingCart[0].OrderUser.Username); Console.WriteLine("EMAIL KHÁCH HÀNG: {0}", shoppingCart[0].OrderUser.UserEmail); Console.WriteLine("MÃ ĐƠN HÀNG: {0}", shoppingCart[0].OrderId); var table = new ConsoleTable("MÃ SÁCH", "TÊN SÁCH", "GIÁ SÁCH"); foreach (var item in shoppingCart) { table.AddRow(item.OrderItem.ItemId, item.OrderItem.ItemName, FormatCurrency(item.OrderItem.ItemPrice)); } table.AddRow("", "", ""); table.AddRow("TỔNG TIỀN", "", FormatCurrency(total)); table.AddRow("NGÀY MUA", "", shoppingCart[0].OrderDate?.ToString("yyyy-MM-dd")); table.Write(); Console.WriteLine("CÁM ƠN QUÝ KHÁCH"); Console.WriteLine("HẸN GẶP LẠI"); } else { Console.WriteLine("Mua hàng thất bại"); } } catch (System.Exception) { throw; } } Console.WriteLine("Nhấn phím bất kì để tiếp tục"); Console.ReadKey(); }
public IHttpActionResult getOrders() { var identity = (ClaimsIdentity)User.Identity; var userId = identity.FindFirst(ClaimTypes.NameIdentifier)?.Value; List <OrderDto> orders = new List <OrderDto>(); orders = OrderBl.getOrders(Convert.ToInt32(userId)); if (orders != null) { return(Ok(orders)); } return(BadRequest()); }
public void AddToCart(Item item) { OrderBl orderBL = new OrderBl(); order.OrderUser = new User(); order.OrderItem = new Item(); order.ListItems = new List <Item>(); order.OrderUser.UserId = user.UserId; order.OrderItem.ItemId = item.ItemId; // user.UserShoppingCart == false : chưa có order // user.UserShoppingCart == true : order thành công if (userBL.GetUserById(user.UserId).UserShoppingCart) { try { if (orderBL.AddToShoppingcart(order)) { Console.WriteLine("Thêm vào giỏ hàng thành công"); } else { Console.WriteLine("Sản phẩm đã có trong giỏ hàng"); } } catch (System.Exception) { throw; } } else { userBL.UpdateStatusShoppingCartById(false, user.UserId); // set userShopping cart to 1 order.OrderStatus = 0; try { if (orderBL.CreateShoppingCart(order)) { Console.WriteLine("Thêm vào giỏ hàng thành công"); } } catch (System.Exception) { throw; } } Console.WriteLine("Nhấn phím bất kì để tiếp tục"); Console.ReadKey(); }
public void DeleteItemFromSPC(Item item) { OrderBl orderBL = new OrderBl(); if (orderBL.DeleteItemInShoppingCartByIdItem(item.ItemId)) { Console.WriteLine("Xóa khỏi giỏ hàng thành công"); } else { Console.WriteLine("Sản phẩm chưa có trong trỏ hàng"); } Console.WriteLine("Nhấn phím bất kì để tiếp tục"); Console.ReadKey(); }
public async Task ProcessStream(Stream stream) { using (var streamReader = new StreamReader(stream, Encoding.UTF8, true, 1024, true)) { var headers = await streamReader.ReadLineAsync(); // skipping headers while (streamReader.Peek() >= 0) { var values = await streamReader.ReadLineAsync(); var order = new OrderBl(values.Split(',')); await Task.WhenAll(_storages.Select(storage => storage.Save(order.ToEntity())).ToArray()); } } }
public void ShopingCart() { while (true) { Console.Clear(); OrderBl orderBL = new OrderBl(); List <Item> shoppingCart = new List <Item>(); shoppingCart = orderBL.ShowShopingCartByUserId(user.UserId); if (shoppingCart == null) { Console.ReadKey(); break; } double total = 0; if (shoppingCart.Count <= 0) { Console.WriteLine("Chưa có sách"); Console.WriteLine("Nhấn phím bất kì để tiếp tục"); Console.ReadKey(); break; } else { Console.WriteLine($"Bạn có {shoppingCart.Count} quyển sách trong giỏ hàng"); var table = new ConsoleTable("Mã sách", "Tên sách", "Giá sách"); foreach (var item in shoppingCart) { total = total + (double)item.ItemPrice; table.AddRow(item.ItemId, item.ItemName, FormatCurrency(item.ItemPrice)); } table.AddRow("", "", ""); table.AddRow("Tổng tiền", "", FormatCurrency(total)); table.Write(); // Console.WriteLine("Tổng tiền: {0}", FormatCurrency(total)); Console.WriteLine("Số tiền trong tài khoản của bạn: {0}", FormatCurrency(user.UserBalance)); Console.WriteLine(); string[] choice = { "Thanh toán", "Xóa sách khỏi giỏ hàng", "Quay lại" }; short choose = Utility.MenuDetail("Menu", choice); string yorn; switch (choose) { case 1: yorn = Utility.OnlyYN("Bạn có muốn thanh toán?(Y/N) "); if (yorn == "Y") { CreateOrder(total); } continue; case 2: Console.Write("Nhập mã sách muốn xóa: "); // int idItem = Int32.Parse(Console.ReadLine()); int idItem; bool c = Int32.TryParse(Console.ReadLine(), out idItem); if (!c) { Console.WriteLine("Bạn chỉ được nhập số. Nhấn nút bất kì để quay lại"); Console.ReadKey(); continue; } bool y = false; foreach (var item in shoppingCart) { if (item.ItemId == idItem) { y = true; } } if (y) { string yOrN = Utility.OnlyYN("Bạn có thực sụ muốn xóa(Y/N): "); if (yOrN == "Y") { orderBL.DeleteItemInShoppingCartByIdItem(idItem); } } else { Console.WriteLine("Không có sản phẩm này trong giỏ hàng"); Console.WriteLine("Nhấn phím bất kì để tiếp tục"); Console.ReadKey(); } continue; } break; } } }
public void ShowAnItem(int?idItem) { while (true) { Console.Clear(); Console.Clear(); Item item = new Item(); RatingBL ratingBL = new RatingBL(); item = itemBl.GetAnItemById(idItem); List <Rating> ratings = ratingBL.GetAllRating(item.ItemId); int rateStar = 0; if (ratings.Count > 0) { foreach (var rate in ratings) { rateStar += rate.RatingStars; } rateStar /= ratings.Count; } var table = new ConsoleTable("Tên", Convert.ToString(item.ItemName)); table.AddRow("Giá:", FormatCurrency(item.ItemPrice)); table.AddRow("Tác giả:", item.ItemAuthor); table.AddRow("Đánh giá:", ShowStar(rateStar) == " " ? "Chưa có đánh giá" : ShowStar(rateStar)); table.AddRow("Danh mục:", item.ItemCategory); table.AddRow("ISBN:", item.ItemISBN); table.AddRow("Ngày phát hành:", item.ItemPublished); table.AddRow("Nhà xuất bản:", item.ItemPublisher); table.AddRow("Ngôn ngữ:", item.ItemLanguage); table.AddRow("Số trang:", item.ItemPages); table.Write(); Console.WriteLine("Mô tả"); WriteLineWordWrap(item.ItemDescription); Console.WriteLine(); OrderBl orderBL = new OrderBl(); if (item.ItemId != orderBL.CheckItemPurchase(item.ItemId, user.UserId)) { string[] choice = { "Thêm vào giỏ hàng", "Đánh giá sản phẩm", "Xem tất cả đánh giá", "Quay lại" }; short choose = Utility.MenuDetail("Menu", choice); switch (choose) { case 1: AddToCart(item); continue; case 2: RateItem(item); continue; case 3: ShowAllRating(item); continue; case 4: break; } } else { string[] choice = { "Đánh giá sản phẩm", "Xem tất cả đánh giá", "Quay lại" }; short choose = Utility.MenuDetail("Menu", choice); switch (choose) { case 1: RateItem(item); continue; case 2: ShowAllRating(item); continue; case 3: break; } } break; } }
public JsonResult GetOrderList(DataTableRequest dtParam) { var dtResponse = OrderBl.GetOrderList(dtParam); return(Json(dtResponse, JsonRequestBehavior.AllowGet)); }