Example #1
0
        /// <summary>
        /// Updates Retailer
        /// </summary>
        /// <returns></returns>
        public static async Task UpdateRetailerAccount()
        {
            try
            {
                using (IRetailerBL retailerBL = new RetailerBL())
                {
                    //Read Sl.No
                    Retailer retailer = await retailerBL.GetRetailerByEmailBL(CommonData.CurrentUser.Email);

                    Write("Name: ");
                    retailer.RetailerName = ReadLine();
                    Write("Email: ");
                    retailer.Email = ReadLine();

                    //Invoke UpdateRetailerBL method to update
                    bool isUpdated = await retailerBL.UpdateRetailerBL(retailer);

                    if (isUpdated)
                    {
                        WriteLine(" Account Updated");
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogException(ex);
                WriteLine(ex.Message);
            }
        }
        /// <summary>
        /// Updates address
        /// </summary>
        /// <returns></returns>
        public static async Task UpdateAddress()
        {
            try
            {
                using (IAddressBL addressBL = new AddressBL())
                {
                    //Read Sl.No
                    Write("Address #: ");
                    bool isNumberValid = int.TryParse(ReadLine(), out int serial);
                    if (isNumberValid)
                    {
                        serial--;
                        RetailerBL retailerBL = new RetailerBL();
                        Retailer retailer = await retailerBL.GetRetailerByEmailBL(CommonData.CurrentUser.Email);
                        List<Address> addresses = await addressBL.GetAddressByRetailerIDBL(retailer.RetailerID);
                        if (serial <= addresses.Count - 1)
                        {
                            //Read inputs
                            Address address = addresses[serial];
                            Write("Address Line 1: ");
                            address.AddressLine1 = ReadLine();
                            Write("Address Line 2: ");
                            address.AddressLine2 = ReadLine();
                            Write("LandMark: ");
                            address.Landmark = ReadLine();
                            Write("City: ");
                            address.City = ReadLine();
                            Write("State: ");
                            address.State = ReadLine();
                            Write("PinCode: ");
                            address.PinCode = ReadLine();

                            //Invoke UpdateAddressBL method to update
                            bool isUpdated = await addressBL.UpdateAddressBL(address);
                            if (isUpdated)
                            {
                                WriteLine("Address Updated");
                            }
                        }
                        else
                        {
                            WriteLine($"Invalid Address #.\nPlease enter a number between 1 to {addresses.Count}");
                        }
                    }
                    else
                    {
                        WriteLine($"Invalid number.");
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogException(ex);
                WriteLine(ex.Message);
            }

        }
        /// <summary>
        /// Menu for Retailer Address User
        /// </summary>
        /// <returns></returns>
        public static async Task<int> AddressPresentationMenu()
        {
            int choice = -2;
            using (IAddressBL addressBL = new AddressBL())
            {
                do
                {
                    //Get and display list of system users.
                    RetailerBL retailerBL = new RetailerBL();
                    Retailer retailer = await retailerBL.GetRetailerByEmailBL(CommonData.CurrentUser.Email);
                    List<Address> addresses = await addressBL.GetAddressByRetailerIDBL(retailer.RetailerID);
                    WriteLine("\n***************ADDRESS***********\n");
                    WriteLine("Addresses:");
                    if (addresses != null && addresses?.Count > 0)
                    {
                        WriteLine("#\tAddressLine 1\tLandMark\tCity\tState");
                        int serial = 0;
                        foreach (var address in addresses)
                        {
                            serial++;
                            WriteLine($"{serial}\t{address.AddressLine1}\t{address.Landmark}\t{address.City}\t{address.State}");
                        }
                    }

                    //Menu
                    WriteLine("\n1.Add Address");
                    WriteLine("2. Update Existing Address");
                    WriteLine("3. Delete Existing Address");
                    WriteLine("0. Back");
                    WriteLine("-1. Exit");
                    Write("Choice: ");

                    //Accept and check choice
                    bool isValidChoice = int.TryParse(ReadLine(), out choice);
                    if (isValidChoice)
                    {
                        switch (choice)
                        {
                            case 1: await AddAddress(); break;
                            case 2: await UpdateAddress(); break;
                            case 3: await DeleteAddress(); break;
                            case 0: break;
                            case -1: break;
                            default: WriteLine("Invalid Choice"); break;
                        }
                    }
                    else
                    {
                        choice = -2;
                    }
                } while (choice != 0 && choice != -1);
            }
            return choice;
        }
        /// <summary>
        /// Delete Address.
        /// </summary>
        /// <returns></returns>
        public static async Task DeleteAddress()
        {
            try
            {
                using (IAddressBL addressBL = new AddressBL())
                {
                    //Read Sl.No
                    Write("Address #: ");
                    bool isNumberValid = int.TryParse(ReadLine(), out int serial);
                    if (isNumberValid)
                    {
                        serial--;
                        RetailerBL retailerBL = new RetailerBL();
                        Retailer retailer = await retailerBL.GetRetailerByEmailBL(CommonData.CurrentUser.Email);
                        List<Address> addresses = await addressBL.GetAddressByRetailerIDBL(retailer.RetailerID);

                        Write("Are you sure? (Y/N): ");


                        string confirmation = ReadLine();

                        if (confirmation.Equals("Y", StringComparison.OrdinalIgnoreCase))
                        {
                            if (serial <= addresses.Count - 1)
                            { //Invoke DeleteSystemUserBL method to delete
                                Address address = addresses[serial];
                                bool isDeleted = await addressBL.DeleteAddressBL(address.AddressID);
                                if (isDeleted)
                                {
                                    WriteLine("Retailer Address Deleted");
                                }
                            }
                        }
                    }

                }


            }

            catch (Exception ex)
            {
                ExceptionLogger.LogException(ex);
                WriteLine(ex.Message);

            }
        }
        /// <summary>
        /// Adds Address
        /// </summary>
        /// <returns></returns>
        public static async Task AddAddress()
        {
            try
            {
                //Read inputs
                Address address = new Address();
                RetailerBL retailerBL = new RetailerBL();
                Retailer retailer = await retailerBL.GetRetailerByEmailBL(CommonData.CurrentUser.Email);
                address.RetailerID = retailer.RetailerID;
                Write("Address Line 1: ");
                address.AddressLine1 = ReadLine();
                Write("Address Line 2: ");
                address.AddressLine2 = ReadLine();
                Write("LandMark: ");
                address.Landmark = ReadLine();
                Write("City: ");
                address.City = ReadLine();
                Write("State: ");
                address.State = ReadLine();
                Write("PinCode: ");
                address.PinCode = ReadLine();
                //Invoke AddAddressBL method to add
                using (AddressBL addressBL = new AddressBL())
                {
                    bool isAdded = await addressBL.AddAddressBL(address);
                    if (isAdded)
                    {
                        WriteLine("Address Added");
                    }
                    WriteLine("Do you want to serailize:Y/N");

                    string confirmation = ReadLine();

                    if (confirmation.Equals("Y", StringComparison.OrdinalIgnoreCase))
                    {
                        addressBL.Serialize();
                    }
                }
            }
            catch (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;
            }
        }
        public static async Task <int> RetailerProductMenu()
        {
            int choice = -2;

            using (IProductBL productBL = new ProductBL())
            {
                do
                {
                    //Get and display list of Product.
                    RetailerBL retailerBL = new RetailerBL();
                    Retailer   retailer   = await retailerBL.GetRetailerByEmailBL(CommonData.CurrentUser.Email);

                    List <Product> products = await productBL.GetAllProductsBL();

                    WriteLine("\n***************Products***********\n");
                    WriteLine("Product:");
                    if (products != null && products?.Count > 0)
                    {
                        WriteLine("#\tProductName\tPrice\t\tDescription\t");
                        int serial = 0;
                        foreach (var product in products)
                        {
                            serial++;
                            WriteLine($"{serial}\t{product.ProductName}\t{product.ProductPrice}\t{product.ProductDescription}");
                        }
                    }

                    //Menu

                    WriteLine("\n1.Add Product to cart");
                    WriteLine("2. Remove Product from Cart");
                    WriteLine("3. Confirm Order");
                    WriteLine("4.Get Product Details");
                    WriteLine("0. Back");
                    WriteLine("-1. Exit");
                    Write("Choice: ");

                    //Accept and check choice
                    bool isValidChoice = int.TryParse(ReadLine(), out choice);
                    if (isValidChoice)
                    {
                        switch (choice)
                        {
                        case 1: await AddtoCart(); break;

                        case 2: await RemoveFromCart(); break;

                        // case 3: await DeleteCart(); break;
                        case 3: await ConfirmOrder(); break;

                        case 4: await GetProduct(); break;

                        case 0: break;

                        case -1: break;

                        default: WriteLine("Invalid Choice"); break;
                        }
                    }
                    else
                    {
                        choice = -2;
                    }
                } while (choice != 0 && choice != -1);
            }
            return(choice);
        }
        /// <summary>
        /// Confirm Order
        /// </summary>
        /// <returns></returns>
        public static async Task ConfirmOrder()
        {
            try
            {
                IProductBL productBL = new ProductBL();
                Guid       tempOrderID;
                using (IOrderDetailBL orderDetailBL = new OrderDetailBL())
                {
                    RetailerBL retailerBL = new RetailerBL();
                    Retailer   retailer   = await retailerBL.GetRetailerByEmailBL(CommonData.CurrentUser.Email);

                    AddressBL      addressBL = new AddressBL();
                    List <Address> addresses = await addressBL.GetAddressByRetailerIDBL(retailer.RetailerID);

                    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 = await orderDetailBL.AddOrderDetailsBL(orderDetail);
                    }

                    using (IOrderBL orderBL = new OrderBL())
                    {
                        Order order = new Order();
                        order.OrderId       = orderID;
                        order.RetailerID    = retailer.RetailerID;
                        order.TotalQuantity = quantity;
                        order.OrderAmount   = totalamount;
                        bool isAdded = 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);
            }
        }
Example #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;
            }
        }