public async Task ProductIDNotMatch()
        {
            //Arrange
            OrderDetailBL orderDetailBL = new OrderDetailBL();
            OrderDetail   orderDetail   = new OrderDetail()
            {
                OrderId = Guid.NewGuid(), ProductID = Guid.NewGuid(), TotalAmount = 10, ProductQuantityOrdered = 10
            };
            bool   isAdded = false;
            Guid   newGuid;
            string errorMessage = null;

            //Act
            try
            {
                (isAdded, newGuid) = await orderDetailBL.AddOrderDetailsBL(orderDetail);
            }
            catch (Exception ex)
            {
                isAdded      = false;
                errorMessage = ex.Message;
            }
            finally
            {
                //Assert
                Assert.IsFalse(isAdded, errorMessage);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            int           id            = Convert.ToInt32(Request.QueryString["id"].ToString());
            OrderDetailBL orderDetailBL = new OrderDetailBL();
            DataTable     dtDetail      = orderDetailBL.GetOrderDetails(id);

            foreach (DataRow dr in dtDetail.Rows)
            {
                totalAmount += Convert.ToInt32(dr["cake_price"]) * Convert.ToInt32(dr["cake_quantity"]);
            }
            total.Text         = "Total: $" + totalAmount;
            details.DataSource = dtDetail;
            details.DataBind();
        }
        public async Task AddValidOrderDetail()
        {
            //Arrange
            OrderDetailBL orderDetailBL = new OrderDetailBL();
            OrderDetail   orderDetail   = new OrderDetail()
            {
                ProductID = Guid.NewGuid(), TotalAmount = 10, ProductQuantityOrdered = 10, ProductPrice = 10
            };
            bool   isAdded = false;
            Guid   newGuid;
            string errorMessage = null;

            //Act
            try
            {
                Customer customer = new Customer()
                {
                    CustomerName = "Arshia", CustomerMobile = "9039607074", Password = "******", Email = "*****@*****.**"
                };
                CustomerBL customerBL = new CustomerBL();
                bool       isAdded2   = false;
                Guid       newGuid2;
                (isAdded2, newGuid2) = await customerBL.AddCustomerBL(customer);

                Order order = new Order()
                {
                    CustomerID = newGuid2, TotalQuantity = 10, OrderAmount = 10
                };
                OrderBL orderBL  = new OrderBL();
                bool    isAdded1 = false;
                Guid    newGuid1;
                (isAdded1, newGuid1) = await orderBL.AddOrderBL(order);

                orderDetail.OrderId = newGuid1;
                (isAdded, newGuid)  = await orderDetailBL.AddOrderDetailsBL(orderDetail);
            }
            catch (Exception ex)
            {
                isAdded      = false;
                errorMessage = ex.Message;
            }
            finally
            {
                //Assert
                Assert.IsTrue(isAdded, errorMessage);
            }
        }
        public static async Task AddReturn()
        {
            Return             onlineReturn  = new Return();
            List <OrderDetail> matchingOrder = new List <OrderDetail>();

            WriteLine("Enter the order number which you want to return");
            double orderToBeReturned = double.Parse(Console.ReadLine());

            WriteLine("Entered Number is: " + orderToBeReturned);
            try
            {
                using (IOrderBL orderBL = new OrderBL())
                {
                    Order order = await orderBL.GetOrderByOrderNumberBL(orderToBeReturned);

                    onlineReturn.OrderID = order.OrderId;
                    using (IOrderDetailBL orderDetailBL = new OrderDetailBL())
                    {
                        matchingOrder = await orderDetailBL.GetOrderDetailsByOrderIDBL(order.OrderId);
                    }
                }

                if (matchingOrder.Count != 0)
                {
                    int orderNo = 0;
                    WriteLine("Products in the order are ");
                    foreach (var orderDetail in matchingOrder)
                    {
                        orderNo++;
                        WriteLine("#\tProductID\t ProductQuantityOrdered\t ProductPrice\t TotalAmount");
                        WriteLine($"{orderNo}\t{orderDetail.ProductID}\t{orderDetail.ProductQuantityOrdered}\t{orderDetail.ProductPrice}\t{orderDetail.TotalAmount}");
                    }
                    WriteLine("Enter The Product Number to be Returned");
                    int ProductToBeReturned = int.Parse(ReadLine());
                    if (ProductToBeReturned <= matchingOrder.Count && ProductToBeReturned > 0)
                    {
                        WriteLine("Enter The Product Serial No. to be Returned");
                        Write("Product  #: ");
                        bool isNumberValid = int.TryParse(ReadLine(), out int serialNo);
                        if (isNumberValid)
                        {
                            serialNo--;
                            if (serialNo <= matchingOrder.Count - 1)
                            {
                                OrderDetail orderDetail = matchingOrder[serialNo];
                                onlineReturn.ProductID = orderDetail.ProductID;
                            }
                        }
                        Console.WriteLine("Enter The Quantity to be Returned");
                        int          QuantityOfReturn = int.Parse(Console.ReadLine());
                        IOrderDetail orderDetail1     = new OrderDetail();
                        onlineReturn.QuantityOfReturn = QuantityOfReturn;

                        foreach (var orderDetail in matchingOrder)
                        {
                            orderDetail1 = matchingOrder.Find(
                                (item) => { return(item.ProductQuantityOrdered == orderDetail.ProductQuantityOrdered); });
                        }

                        if (QuantityOfReturn <= orderDetail1.ProductQuantityOrdered)
                        {
                            WriteLine("Purpose of Return:\n1.  UnsatiSfactoryProduct\n2. WrongProductShipped\n3.  WrongProductOrdered\n4. DefectiveProduct  ");
                            bool isPurposeValid = int.TryParse(ReadLine(), out int purpose);
                            if (isPurposeValid)
                            {
                                if (purpose == 1)
                                {
                                    onlineReturn.Purpose = Helpers.PurposeOfReturn.UnsatiSfactoryProduct;
                                }
                                else if (purpose == 2)
                                {
                                    onlineReturn.Purpose = Helpers.PurposeOfReturn.WrongProductShipped;
                                }
                                else if (purpose == 3)
                                {
                                    onlineReturn.Purpose = Helpers.PurposeOfReturn.WrongProductOrdered;
                                }
                                else if (purpose == 4)
                                {
                                    onlineReturn.Purpose = Helpers.PurposeOfReturn.DefectiveProduct;
                                }
                                else
                                {
                                    WriteLine("Invalid Option Selected ");
                                }

                                Write("Are you sure? (Y/N): ");
                                string confirmation = ReadLine();
                                if (confirmation.Equals("Y", StringComparison.OrdinalIgnoreCase))
                                {
                                    using (IReturnBL onlineReturnBL = new ReturnBL())
                                    {
                                        bool confirmed = await onlineReturnBL.AddReturnBL(onlineReturn);

                                        if (confirmed)
                                        {
                                            matchingOrder[ProductToBeReturned - 1].ProductQuantityOrdered -= QuantityOfReturn;
                                            matchingOrder[ProductToBeReturned - 1].TotalAmount            -= matchingOrder[ProductToBeReturned - 1].ProductPrice * QuantityOfReturn;
                                            WriteLine("Total Return Amount: " + (matchingOrder[ProductToBeReturned - 1].ProductPrice * QuantityOfReturn));
                                            WriteLine("OnlineReturn Confirmed");
                                            WriteLine("OnlineReturnID is" + "  " + onlineReturn.OnlineReturnID);
                                        }
                                        else
                                        {
                                            WriteLine("Data Not Serialized");
                                        }
                                    }
                                }
                                else
                                {
                                    WriteLine(" Not Confirmed");
                                }
                            }
                            else
                            {
                                WriteLine(" Purpose of return not valid");
                            }
                        }
                        else
                        {
                            WriteLine("Invalid QuantityOfReturn");
                        }
                    }
                    else
                    {
                        WriteLine("Wrong Input");
                    }
                }
                else
                {
                    Console.WriteLine("OrderID not Found");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #5
0
        /// <summary>
        /// Confirm Order
        /// </summary>
        /// <returns></returns>
        public static async Task ConfirmOrder()
        {
            try
            {
                IProductBL productBL = new ProductBL();
                Guid       tempOrderID;
                using (IOrderDetailBL orderDetailBL = new OrderDetailBL())
                {
                    CustomerBL CustomerBL = new CustomerBL();
                    Customer   Customer   = await CustomerBL.GetCustomerByEmailBL(CommonData.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();
                        order.OrderId       = orderID;
                        order.CustomerID    = Customer.CustomerID;
                        order.TotalQuantity = quantity;
                        order.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 (System.Exception ex)
            {
                ExceptionLogger.LogException(ex);
                WriteLine(ex.Message);
            }
        }
        public static async void CancelRetailerOrder()
        {
            List <OrderDetail> matchingOrder = new List <OrderDetail>();//list maintains the order details of the order which user wishes to cancel

            try
            {
                using (IRetailerBL retailerBL = new RetailerBL())
                {
                    //gives the current retailer
                    Retailer retailer = await retailerBL.GetRetailerByEmailBL(CommonData.CurrentUser.Email);

                    using (IOrderBL orderDAL = new OrderBL())
                    {
                        //list of orders ordered by the retailer
                        List <Order> RetailerOrderList = await orderDAL.GetOrdersByRetailerID(retailer.RetailerID);

                        Console.WriteLine("Enter the order number which you want to cancel");
                        int orderToBeCancelled = int.Parse(Console.ReadLine());//user input of order which he has to cancel
                        foreach (Order order in RetailerOrderList)
                        {
                            using (IOrderDetailBL orderDetailBL = new OrderDetailBL())
                            {
                                //getting the order details of required order to be cancelled
                                List <OrderDetail> RetailerOrderDetails = await orderDetailBL.GetOrderDetailsByOrderIDBL(order.OrderId);

                                matchingOrder = RetailerOrderDetails.FindAll(
                                    (item) => { return(item.OrderSerial == orderToBeCancelled); }
                                    );
                                break;
                            }
                        }

                        if (matchingOrder.Count != 0)
                        {
                            OrderDetailDAL orderDetaildal = new OrderDetailDAL();
                            //cancel order if order not delivered
                            if (!orderDetaildal.UpdateOrderDeliveredStatusDAL(matchingOrder[0].OrderId))
                            {
                                int serial = 0;
                                Console.WriteLine("Products in the order are ");
                                foreach (OrderDetail orderDetail in matchingOrder)
                                {
                                    //displaying order details with the products ordered
                                    serial++;
                                    Console.WriteLine("#\tProductID \t ProductQuantityOrdered");
                                    Console.WriteLine($"{ serial}\t{ orderDetail.ProductID}\t{ orderDetail.ProductQuantityOrdered}");
                                }
                                Console.WriteLine("Enter The Product to be Cancelled");
                                int y = int.Parse(Console.ReadLine());
                                Console.WriteLine("Enter The Product Quantity to be Cancelled");
                                int quantityToBeCancelled = int.Parse(Console.ReadLine());
                                if (matchingOrder[y - 1].ProductQuantityOrdered >= quantityToBeCancelled)
                                {
                                    //updating order quantity and revenue
                                    matchingOrder[y - 1].ProductQuantityOrdered -= quantityToBeCancelled;
                                    matchingOrder[y - 1].TotalAmount            -= matchingOrder[y - 1].ProductPrice * quantityToBeCancelled;
                                    OrderDetailDAL orderDetailDAL = new OrderDetailDAL();
                                    orderDetailDAL.UpdateOrderDetailsDAL(matchingOrder[y - 1]);

                                    Console.WriteLine("Product Cancelled Succesfully");
                                }
                                else
                                {
                                    Console.WriteLine("PRODUCT QUANTITY EXCEEDED");
                                }
                            }
                            else
                            {
                                Console.WriteLine("Order Can't be cancelled as it is delivered");
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #7
0
        //public static async Task CancelRetailerOrder()
        //{
        //    List<OrderDetail> matchingOrder = new List<OrderDetail>();//list maintains the order details of the order which user wishes to cancel
        //    try
        //    {
        //        using (IRetailerBL retailerBL = new RetailerBL())
        //        {
        //            //gives the current retailer
        //            Retailer retailer = await retailerBL.GetRetailerByEmailBL(CommonData.CurrentUser.Email);
        //            using (IOrderBL orderDAL = new OrderBL())
        //            {
        //                //list of orders ordered by the retailer
        //                List<Order> RetailerOrderList = await orderDAL.GetOrdersByRetailerIDBL(retailer.RetailerID);
        //                Console.WriteLine("Enter the order number which you want to cancel");
        //                int orderToBeCancelled = int.Parse(Console.ReadLine());//user input of order which he has to cancel
        //                foreach (Order order in RetailerOrderList)
        //                {
        //                    using (IOrderDetailBL orderDetailBL = new OrderDetailBL())
        //                    {
        //                        //getting the order details of required order to be cancelled
        //                        List<OrderDetail> RetailerOrderDetails = await orderDetailBL.GetOrderDetailsByOrderIDBL(order.OrderId);
        //                        matchingOrder = RetailerOrderDetails.FindAll(
        //                                   (item) => { return item.OrderSerial == orderToBeCancelled; }
        //                               );
        //                        break;
        //                    }
        //                }

        //                if (matchingOrder.Count != 0)
        //                {
        //                    OrderDetailBL orderDetailBL = new OrderDetailBL();
        //                    //cancel order if order not delivered
        //                    if (!( await orderDetailBL.UpdateOrderDeliveredStatusBL(matchingOrder[0].OrderId)))
        //                    {
        //                        int serial = 0;
        //                        Console.WriteLine("Products in the order are ");
        //                        foreach (OrderDetail orderDetail in matchingOrder)
        //                        {
        //                            //displaying order details with the products ordered
        //                            serial++;
        //                            Console.WriteLine("#\tProductID \t ProductQuantityOrdered");
        //                            Console.WriteLine($"{ serial}\t{ orderDetail.ProductID}\t{ orderDetail.ProductQuantityOrdered}");
        //                        }
        //                        Console.WriteLine("Enter The Product to be Cancelled");
        //                        int ProductToBeCancelled = int.Parse(Console.ReadLine());
        //                        Console.WriteLine("Enter The Product Quantity to be Cancelled");
        //                        int quantityToBeCancelled = int.Parse(Console.ReadLine());
        //                        if (matchingOrder[ProductToBeCancelled - 1].ProductQuantityOrdered >= quantityToBeCancelled)
        //                        {
        //                            //updating order quantity and revenue
        //                            matchingOrder[ProductToBeCancelled - 1].ProductQuantityOrdered -= quantityToBeCancelled;
        //                            matchingOrder[ProductToBeCancelled - 1].TotalAmount -= matchingOrder[ProductToBeCancelled - 1].ProductPrice * quantityToBeCancelled;
        //                            OrderDetailBL orderDetailBL1 = new OrderDetailBL();
        //                            await orderDetailBL1.UpdateOrderDetailsBL(matchingOrder[ProductToBeCancelled - 1]);

        //                            Console.WriteLine("Product Cancelled Succesfully");

        //                        }
        //                        else
        //                        {
        //                            Console.WriteLine("PRODUCT QUANTITY EXCEEDED");
        //                        }
        //                    }
        //                    else
        //                    {
        //                        Console.WriteLine("Order Can't be cancelled as it is delivered");
        //                    }
        //                }
        //            }
        //        }
        //    }
        //    catch (Exception)
        //    {

        //        throw;
        //    }
        //}



        public static async Task CancelRetailerOrder()
        {
            IProductBL         productBL     = new ProductBL();
            List <OrderDetail> matchingOrder = new List <OrderDetail>();//list maintains the order details of the order which user wishes to cancel

            Console.WriteLine("Enter the order number which you want to cancel");
            double orderToBeCancelled = double.Parse(Console.ReadLine());//user input of order which he has to cancel

            Console.WriteLine("Entered Number is: " + orderToBeCancelled);
            try
            {
                using (IOrderBL orderBL = new OrderBL())
                {
                    Order order = await orderBL.GetOrderByOrderNumberBL(orderToBeCancelled);

                    using (IOrderDetailBL orderDetailBL = new OrderDetailBL())
                    {
                        matchingOrder = await orderDetailBL.GetOrderDetailsByOrderIDBL(order.OrderId);

                        int a = matchingOrder.Count();
                        Console.WriteLine(a);
                    }
                }


                if (matchingOrder.Count != 0)
                {
                    OrderDetailBL orderDetailBL = new OrderDetailBL();
                    //cancel order if order not delivered
                    if ((await orderDetailBL.UpdateOrderDeliveredStatusBL(matchingOrder[0].OrderId)))
                    {
                        int serial = 0;

                        Console.WriteLine("Products in the order are ");
                        Console.WriteLine("# \t\t\tProductID \t\t ProductName \t ProductQuantityOrdered");
                        foreach (OrderDetail orderDetail in matchingOrder)
                        {
                            //displaying order details with the products ordered
                            Product product = await productBL.GetProductByProductIDBL(orderDetail.ProductID);

                            serial++;
                            //Console.WriteLine(product.ProductName);
                            Console.WriteLine($"{ serial}\t{ orderDetail.ProductID}\t\t\t{product.ProductName}\t{ orderDetail.ProductQuantityOrdered}");
                        }
                        Console.WriteLine("Enter The Product to be Cancelled");
                        int ProductToBeCancelled = int.Parse(Console.ReadLine());
                        if (ProductToBeCancelled < matchingOrder.Count && ProductToBeCancelled > 0)
                        {
                            Console.WriteLine("Enter The Product Quantity to be Cancelled");
                            int quantityToBeCancelled = int.Parse(Console.ReadLine());
                            if (matchingOrder[ProductToBeCancelled - 1].ProductQuantityOrdered >= quantityToBeCancelled)
                            {
                                //updating order quantity and revenue
                                matchingOrder[ProductToBeCancelled - 1].ProductQuantityOrdered -= quantityToBeCancelled;
                                matchingOrder[ProductToBeCancelled - 1].TotalAmount            -= matchingOrder[ProductToBeCancelled - 1].ProductPrice * quantityToBeCancelled;
                                Console.WriteLine("Total Refund Amount: " + (matchingOrder[ProductToBeCancelled - 1].ProductPrice * quantityToBeCancelled));
                                OrderDetailBL orderDetailBL1 = new OrderDetailBL();
                                await orderDetailBL1.UpdateOrderDetailsBL(matchingOrder[ProductToBeCancelled - 1]);

                                Console.WriteLine("Product Cancelled Succesfully");
                            }
                            else
                            {
                                Console.WriteLine("PRODUCT QUANTITY EXCEEDED");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Wrong Input");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Order Can't be cancelled as it is delivered");
                    }
                }
                else
                {
                    Console.Write("no id found");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public static async Task CancelCustomerOrder()
        {
            IProductBL         productBL     = new ProductBL();
            List <OrderDetail> matchingOrder = new List <OrderDetail>();

            WriteLine("Enter the order number which you want to cancel");
            double orderToBeCancelled = double.Parse(ReadLine());

            WriteLine("Entered Number is: " + orderToBeCancelled);
            try
            {
                using (IOrderBL orderBL = new OrderBL())
                {
                    try
                    {
                        Order order = await orderBL.GetOrderByOrderNumberBL(orderToBeCancelled);

                        using (IOrderDetailBL orderDetailBL = new OrderDetailBL())
                        {
                            matchingOrder = await orderDetailBL.GetOrderDetailsByOrderIDBL(order.OrderId);

                            int a = matchingOrder.Count();
                            WriteLine("No. of Products ordered: " + a);
                        }
                    }
                    catch (Exception)
                    {
                        WriteLine("Invalid OrderId");
                    }
                }
                if (matchingOrder.Count != 0)
                {
                    OrderDetailBL orderDetailBL = new OrderDetailBL();
                    if ((await orderDetailBL.UpdateOrderDeliveredStatusBL(matchingOrder[0].OrderId)))
                    {
                        int serialNo = 0;
                        WriteLine("Products in the order are ");
                        WriteLine("#\t\t ProductID\t\t ProductQuantityOrdered\t\t UnitProductPrice");
                        foreach (OrderDetail orderDetail in matchingOrder)
                        {
                            Product product = await productBL.GetProductByProductIDBL(orderDetail.ProductID);

                            serialNo++;
                            //Console.WriteLine(product.ProductName);
                            WriteLine($"{ serialNo}\t{ orderDetail.ProductID}\t\t{ orderDetail.ProductQuantityOrdered}\t\t{orderDetail.ProductPrice}");
                        }
                        Console.WriteLine("Enter The Product to be Cancelled");
                        int ProductToBeCancelled = int.Parse(Console.ReadLine());
                        if (ProductToBeCancelled <= matchingOrder.Count && ProductToBeCancelled > 0)
                        {
                            Console.WriteLine("Enter The Product Quantity to be Cancelled");
                            int quantityToBeCancelled = int.Parse(Console.ReadLine());
                            if (matchingOrder[ProductToBeCancelled - 1].ProductQuantityOrdered >= quantityToBeCancelled)
                            {
                                matchingOrder[ProductToBeCancelled - 1].ProductQuantityOrdered -= quantityToBeCancelled;
                                matchingOrder[ProductToBeCancelled - 1].TotalAmount            -= matchingOrder[ProductToBeCancelled - 1].ProductPrice * quantityToBeCancelled;
                                Console.WriteLine("Total Refund Amount: " + (matchingOrder[ProductToBeCancelled - 1].ProductPrice * quantityToBeCancelled));
                                OrderDetailBL orderDetailBL1 = new OrderDetailBL();
                                await orderDetailBL1.UpdateOrderDetailsBL(matchingOrder[ProductToBeCancelled - 1]);

                                Console.WriteLine("Product Cancelled Succesfully");
                            }
                            else
                            {
                                Console.WriteLine("PRODUCT QUANTITY EXCEEDED");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Wrong Input");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Order Can't be cancelled as it is delivered");
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #9
0
        public static async Task AddOnlineReturn()
        {
            OrderDetailBL      orderBL       = new OrderDetailBL();
            List <OrderDetail> matchingOrder = new List <OrderDetail>();

            try
            {
                using (IRetailerBL retailerBL = new RetailerBL())
                {
                    Retailer retailer = await retailerBL.GetRetailerByEmailBL(CommonData.CurrentUser.Email);

                    using (IOrderBL orderDAL = new OrderBL())
                    {
                        List <Order> RetailerOrderList = await orderDAL.GetOrdersByRetailerIDBL(retailer.RetailerID);

                        Console.WriteLine("Enter the order number which you want to Return");
                        int x = int.Parse(Console.ReadLine());
                        foreach (Order order in RetailerOrderList)
                        {
                            using (IOrderDetailBL orderDetailBL = new OrderDetailBL())
                            {
                                List <OrderDetail> RetailerOrderDetails = await orderDetailBL.GetOrderDetailsByOrderIDBL(order.OrderId);

                                matchingOrder = RetailerOrderDetails.FindAll(
                                    (item) => { return(item.OrderSerial == x); }
                                    );
                                break;
                            }
                        }
                        if (matchingOrder.Count != 0)
                        {
                            int serial = 0;
                            Console.WriteLine("Products in the order are ");
                            foreach (var orderDetail in matchingOrder)
                            {
                                serial++;
                                Console.WriteLine("#\tProductID \t ProductQuantityOrdered");
                                Console.WriteLine($"{ serial}\t{ orderDetail.ProductID}\t{ orderDetail.ProductQuantityOrdered}");
                            }
                            Console.WriteLine("Enter The ProductID to be Returned");
                            int y = int.Parse(Console.ReadLine());
                            Console.WriteLine("Enter The Quantity to be Returned");
                            IOrderDetail orderDetail1     = new OrderDetail();
                            int          QuantityOfReturn = int.Parse(Console.ReadLine());
                            if (QuantityOfReturn <= orderDetail1.ProductQuantityOrdered)
                            {
                                IOnlineReturn onlineReturn = new OnlineReturn();
                                //  OrderBL order = new OrderBL();
                                WriteLine("Purpose of Return:\n1.  UnsatiSfactoryProduct\n2. WrongProductShipped\n3.  WrongProductOrdered\n4. DefectiveProduct  ");
                                bool isPurposeValid = int.TryParse(ReadLine(), out int purpose);
                                if (isPurposeValid)
                                {
                                    if (purpose == 1)
                                    {
                                        onlineReturn.Purpose = Helpers.PurposeOfReturn.DefectiveProduct;
                                    }
                                    else if (purpose == 2)
                                    {
                                        onlineReturn.Purpose = Helpers.PurposeOfReturn.UnsatiSfactoryProduct;
                                    }
                                    else if (purpose == 3)
                                    {
                                        onlineReturn.Purpose = Helpers.PurposeOfReturn.WrongProductOrdered;
                                    }
                                    else if (purpose == 4)
                                    {
                                        onlineReturn.Purpose = Helpers.PurposeOfReturn.WrongProductShipped;
                                    }
                                    else
                                    {
                                        WriteLine("Invalid Option Selected ");
                                    }

                                    Write("Are you sure? (Y/N): ");
                                    string confirmation = ReadLine();

                                    if (confirmation.Equals("Y", StringComparison.OrdinalIgnoreCase))
                                    {
                                        WriteLine("OnlineReturn Confirmed");
                                    }
                                }
                                else
                                {
                                    WriteLine(" Purpose Of Return is Invalid");
                                }
                                //    matchingOrder[y - 1].ProductQuantityOrdered -= z;
                                //    OrderDetailDAL orderDetailDAL = new OrderDetailDAL();
                                //   orderDetailDAL.UpdateOrderDetailsDAL(matchingOrder[y - 1]);
                                //   Console.WriteLine("Product Cancelled Succesfully");
                            }
                            else
                            {
                                WriteLine("Invalid QuantityOfReturn");
                            }
                        }
                        else
                        {
                            Console.WriteLine("OrderID not Found");
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }