public static async Task RemoveFromCart() { try { ICartProductBL cartProductBL = new CartProductBL(); List <CartProduct> cart = await cartProductBL.GetAllCartProductsBL(); WriteLine("#\tProduct Price\tProduct Quantity \t Total Amount"); int serial = 0; foreach (var cartProduct in cart) { serial++; WriteLine($"{serial}\t{cartProduct.ProductPrice}\t{cartProduct.ProductQuantityOrdered}\t{cartProduct.TotalAmount}"); } Write("Product #: "); bool isNumberValid = int.TryParse(ReadLine(), out int serial1); if (isNumberValid) { serial1--; if (serial1 <= cart.Count - 1) { bool isDeleted = await cartProductBL.DeleteCartProductBL(cart[serial1].CartId); } } } catch (Exception) { throw; } }
public static async Task AddtoCart() { try { IProductBL productBL = new ProductBL(); CartProduct cartProduct = new CartProduct(); Write("Product #: "); bool isNumberValid = int.TryParse(ReadLine(), out int serialNo); if (isNumberValid) { serialNo--; List <Product> products = await productBL.GetAllProductsBL(); if (serialNo <= products.Count - 1) { Product product = products[serialNo]; cartProduct.ProductID = product.ProductID; cartProduct.ProductPrice = product.ProductPrice; Write("Enter Quantity : "); cartProduct.ProductQuantityOrdered = int.Parse(ReadLine()); using (ICartProductBL cartProductBL = new CartProductBL()) { bool isAdded = await cartProductBL.AddCartProductBL(cartProduct); if (isAdded) { WriteLine("Product Added to Cart!"); } } } else { WriteLine($"Invalid Product Serial #.\nPlease enter a number between 1 to {products.Count}"); } } else { WriteLine($"Invalid number."); } } catch (Exception ex) { ExceptionLogger.LogException(ex); WriteLine(ex.Message); } }
public static async Task ConfirmOrder() { try { IProductBL productBL = new ProductBL(); Guid tempOrderID; ICartProductBL cartProductBL = new CartProductBL(); List <CartProduct> cart = await cartProductBL.GetAllCartProductsBL(); using (IOrderDetailBL orderDetailBL = new OrderDetailBL()) { CustomerBL customerBL = new CustomerBL(); Customer customer = await customerBL.GetCustomerByEmailBL(UserData.CurrentUser.Email); AddressBL addressBL = new AddressBL(); List <Address> addresses = await addressBL.GetAddressByCustomerIDBL(customer.CustomerID); double totalamount = 0; int quantity = 0; Guid orderID = Guid.NewGuid(); tempOrderID = orderID; foreach (var cartProduct in cart) { OrderDetail orderDetail = new OrderDetail(); WriteLine("#\tAddressLine 1\tLandMark\tCity"); int serial = 0; foreach (var address in addresses) { serial++; WriteLine($"{serial}\t{address.AddressLine1}\t{address.Landmark}\t{address.City}"); } Write("Address #: "); bool isNumberValid = int.TryParse(ReadLine(), out int serial1); if (isNumberValid) { serial1--; if (serial1 <= addresses.Count - 1) { //Read inputs Address address = addresses[serial1]; orderDetail.AddressId = address.AddressID; } } orderDetail.OrderId = orderID; orderDetail.ProductID = cartProduct.ProductID; orderDetail.ProductPrice = cartProduct.ProductPrice; orderDetail.ProductQuantityOrdered = cartProduct.ProductQuantityOrdered; orderDetail.TotalAmount = (cartProduct.ProductPrice * cartProduct.ProductQuantityOrdered); totalamount += orderDetail.TotalAmount; quantity += orderDetail.ProductQuantityOrdered; bool isAdded; Guid newguid; (isAdded, newguid) = await orderDetailBL.AddOrderDetailsBL(orderDetail); } using (IOrderBL orderBL = new OrderBL()) { Order order = new Order { OrderId = orderID, CustomerID = customer.CustomerID, TotalQuantity = quantity, OrderAmount = totalamount }; bool isAdded; Guid newguid; (isAdded, newguid) = await orderBL.AddOrderBL(order); if (isAdded) { WriteLine("Order Added"); } } } IOrderBL orderBL1 = new OrderBL(); Order order1 = await orderBL1.GetOrderByOrderIDBL(tempOrderID); WriteLine($"Your Order No. {order1.OrderNumber}\t{order1.TotalQuantity}\t{order1.OrderAmount}\t{order1.DateOfOrder}"); WriteLine("Order Details"); IOrderDetailBL orderDetailBL1 = new OrderDetailBL(); List <OrderDetail> orderDetailslist = await orderDetailBL1.GetOrderDetailsByOrderIDBL(tempOrderID); foreach (var item in orderDetailslist) { Product product = await productBL.GetProductByProductIDBL(item.ProductID); WriteLine($"{product.ProductName}\t{item.ProductPrice}\t{item.ProductQuantityOrdered}\t{item.TotalAmount}"); } cart.Clear(); } catch (Exception ex) { ExceptionLogger.LogException(ex); WriteLine(ex.Message); } }