Esempio n. 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);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Delete Retailer Account.
        /// </summary>
        /// <returns></returns>
        public static async Task DeleteRetailerAccount()
        {
            try
            {
                using (IRetailerBL retailerBL = new RetailerBL())
                {
                    Write("Are you sure? (Y/N): ");
                    Write("Current Password: "******"Y", StringComparison.OrdinalIgnoreCase))
                    {
                        //Invoke DeleteRetailerBL method to delete
                        bool isDeleted = await retailerBL.DeleteRetailerBL(retailer.RetailerID);

                        if (isDeleted)
                        {
                            WriteLine("Retailer Account Deleted");
                        }
                    }
                }
            }



            catch (Exception ex)
            {
                ExceptionLogger.LogException(ex);
                WriteLine(ex.Message);
            }
        }
Esempio n. 3
0
        private static async Task AddRetailer()
        {
            try
            {
                Retailer newRetailer = new Retailer();
                Console.WriteLine("Enter Retailer Name :");
                newRetailer.RetailerName = Console.ReadLine();
                Console.WriteLine("Enter Phone Number :");
                newRetailer.RetailerMobile = Console.ReadLine();
                Console.WriteLine("Enter Retailer's Email");
                newRetailer.Email = Console.ReadLine();
                Console.WriteLine("Enter Retailer's Password");
                newRetailer.Password   = Console.ReadLine();
                newRetailer.RetailerID = default(Guid);
                RetailerBL rb = new RetailerBL();

                bool retailerAdded = await rb.AddRetailerBL(newRetailer);

                if (retailerAdded)
                {
                    Console.WriteLine("Retailer Added");
                    Console.WriteLine("Your User id is " + newRetailer.Email);
                }
                else
                {
                    Console.WriteLine("Retailer Not Added");
                }
            }
            catch (GreatOutdoorException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 4
0
        public async Task AddValidRetailer()
        {
            //Arrange
            RetailerBL retailerBL = new RetailerBL();
            Retailer   retailer   = new Retailer()
            {
                RetailerName = "Scott", RetailerMobile = "9876543210", Password = "******", Email = "*****@*****.**"
            };
            bool   isAdded      = false;
            string errorMessage = null;

            //Act
            try
            {
                isAdded = await retailerBL.AddRetailerBL(retailer);
            }
            catch (Exception ex)
            {
                isAdded      = false;
                errorMessage = ex.Message;
            }
            finally
            {
                //Assert
                Assert.IsTrue(isAdded, errorMessage);
            }
        }
Esempio n. 5
0
        public async Task RetailerMobileCanNotBeNull()
        {
            //Arrange
            RetailerBL retailerBL = new RetailerBL();
            Retailer   retailer   = new Retailer()
            {
                RetailerName = "Smith", RetailerMobile = null, Password = "******", Email = "*****@*****.**"
            };
            bool   isAdded      = false;
            string errorMessage = null;

            //Act
            try
            {
                isAdded = await retailerBL.AddRetailerBL(retailer);
            }
            catch (Exception ex)
            {
                isAdded      = false;
                errorMessage = ex.Message;
            }
            finally
            {
                //Assert
                Assert.IsFalse(isAdded, errorMessage);
            }
        }
Esempio n. 6
0
        public async Task RetailerEmailRegExp()
        {
            //Arrange
            RetailerBL retailerBL = new RetailerBL();
            Retailer   retailer   = new Retailer()
            {
                RetailerName = "John", RetailerMobile = "9877897890", Password = "******", Email = "john"
            };
            bool   isAdded      = false;
            string errorMessage = null;

            //Act
            try
            {
                isAdded = await retailerBL.AddRetailerBL(retailer);
            }
            catch (Exception ex)
            {
                isAdded      = false;
                errorMessage = ex.Message;
            }
            finally
            {
                //Assert
                Assert.IsFalse(isAdded, errorMessage);
            }
        }
        /// <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);
            }

        }
Esempio n. 8
0
        /// <summary>
        /// Menu for Retailer
        /// </summary>
        /// <returns></returns>
        public static async Task <int> RetailerUserMenu()
        {
            int choice = -2;

            using (IRetailerBL retailerBL = new RetailerBL())
            {
                do
                {
                    //Menu
                    WriteLine("\n1. Initiate order");
                    WriteLine("2. Cancel retailer  Order");
                    WriteLine("3. Return OnlineOrder");
                    WriteLine("4. Update Account");
                    WriteLine("5. Change Password");
                    WriteLine("6. Manage Address");
                    WriteLine("7. Delete Account");
                    WriteLine("0. Logout");
                    WriteLine("-1. Exit");
                    Write("Choice: ");

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

                        case 2: await CancelRetailerOrder(); break;

                        case 3: await ReturnOnlineOrder(); break;

                        case 4: await UpdateRetailerAccount(); break;

                        case 5: await ChangeRetailerPassword(); break;

                        case 6: await ManageAddress(); break;

                        case 7: await DeleteRetailerAccount(); break;

                        case 0: break;

                        case -1: break;

                        default: WriteLine("Invalid Choice"); break;
                        }
                    }
                    else
                    {
                        choice = -2;
                    }
                } while (choice != 0 && choice != -1);
            }
            return(choice);
        }
        /// <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;
        }
Esempio n. 10
0
        /// <summary>
        /// views retailers profile
        /// </summary>
        /// <returns></returns>
        public static async Task ViewRetailersProfile()
        {
            RetailerBL      retailerBL = new RetailerBL();
            List <Retailer> retailers  = await retailerBL.GetAllRetailersBL();

            WriteLine("#\tRetailer Name\t Retialer Email\tRetailer Phone no.");
            int serial = 0;

            foreach (var retailer in retailers)
            {
                serial++;
                WriteLine($"{serial}\t{retailer.RetailerName}\t{retailer.Email}\t{retailer.RetailerMobile}");
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Updates Retailer's Password.
        /// </summary>
        /// <returns></returns>
        public static async Task ChangeRetailerPassword()
        {
            try
            {
                using (IRetailerBL retailerBL = new RetailerBL())
                {
                    //Read Current Password
                    Write("Current Password: "******"New Password: "******"Confirm Password: "******"Retailer Password Updated");
                            }
                        }
                        else
                        {
                            WriteLine($"New Password and Confirm Password doesn't match");
                        }
                    }
                    else
                    {
                        WriteLine($"Current Password doesn't match.");
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogException(ex);
                WriteLine(ex.Message);
            }
        }
        /// <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);
            }
        }
Esempio n. 14
0
        /// <summary>
        /// views retailer reports.
        /// </summary>
        /// <returns></returns>
        public static async Task ViewRetailerReports()
        {
            RetailerBL      retailerBL = new RetailerBL();
            List <Retailer> retailers  = await retailerBL.GetAllRetailersBL();

            List <RetailerReport> retailerreports = new List <RetailerReport>();
            RetailerReport        item;

            foreach (var retailer in retailers)
            {
                item = await retailerBL.GetRetailerReportByRetailIDBL(retailer.RetailerID);

                retailerreports.Add(item);
            }
            WriteLine("#\tRetailer Name\t no.of orders placed\t Total amount spent on orders");
            int serial = 0;

            foreach (var report in retailerreports)
            {
                serial++;
                WriteLine($"{serial}\t{report.RetailerName}\t{report.RetailerSalesCount}\t{report.RetailerSalesAmount}");
            }
        }
        /// <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);
            }
        }
        public static async Task UploadOfflineOrder()
        {
            try
            {
                //Read inputs
                OfflineOrder   offlineOrder    = new OfflineOrder();
                OfflineOrderBL offlineOrderBL1 = new OfflineOrderBL();
                offlineOrder.TotalOrderAmount = 10;
                offlineOrder.TotalQuantity    = 10;

                using (IRetailerBL retailerBL = new RetailerBL())
                {
                    int serial = 0;


                    //Get and display list of Retailer.
                    List <Retailer> retailers = await retailerBL.GetAllRetailersBL();

                    WriteLine("Retailers:");
                    if (retailers != null && retailers?.Count > 0)
                    {
                        WriteLine("#\tName\tEmail\tRetailerID\t");

                        foreach (var retailer in retailers)
                        {
                            serial++;
                            WriteLine($"{serial}\t{retailer.RetailerName}\t{retailer.Email}\t{retailer.RetailerID}");
                        }
                    }

                    Write("Select Retailer #: ");
                    bool isNumberValid = int.TryParse(ReadLine(), out serial);
                    if (isNumberValid)
                    {
                        serial--;
                        if (serial <= retailers.Count - 1)
                        {
                            Retailer retailer1 = retailers[serial];

                            offlineOrder.RetailerID = retailer1.RetailerID;
                        }
                        else
                        {
                            WriteLine("INVALID ENTRY");
                        }
                    }
                    SalesPersonBL salespersonBL = new SalesPersonBL();
                    SalesPerson   salesPerson   = await salespersonBL.GetSalesPersonByEmailBL(CommonData.CurrentUser.Email);

                    offlineOrder.SalesPersonID = salesPerson.SalesPersonID;
                }


                using (IProductBL productBL = new ProductBL())
                {
                    int serial1 = 0;

                    //Get and display list of Product.
                    List <Product> products = await productBL.GetAllProductsBL();

                    WriteLine("Select Products from following List");
                    WriteLine("Products:");
                    if (products != null && products?.Count > 0)
                    {
                        WriteLine("#\tProductName\tPrice\t\tDescription\t");

                        foreach (var product in products)
                        {
                            serial1++;
                            WriteLine($"{serial1}\t{product.ProductName}\t{product.ProductPrice}\t{product.ProductColor}\t{product.ProductSize}\t{product.ProductMaterial}");
                        }
                    }
                    //Add Product Details
                    char c;
                    WriteLine("Add product(Y/N):");
                    c = Char.Parse(ReadLine());

                    while ((c == 'Y') || (c == 'y'))
                    {
                        OfflineOrderDetail offlineOrderDetail = new OfflineOrderDetail();
                        offlineOrderDetail.OfflineOrderID = offlineOrder.OfflineOrderID;

                        Write("Select Product #: ");
                        bool isNumberValid1 = int.TryParse(ReadLine(), out serial1);
                        if (isNumberValid1)
                        {
                            serial1--;
                            if (serial1 <= products.Count - 1)
                            {
                                Product product1 = products[serial1];

                                offlineOrderDetail.ProductID   = product1.ProductID;
                                offlineOrderDetail.UnitPrice   = product1.ProductPrice;
                                offlineOrderDetail.ProductName = product1.ProductName;
                                WriteLine("Enter Quantity:");

                                double quantity = Double.Parse(ReadLine());
                                offlineOrderDetail.Quantity   = quantity;
                                offlineOrderDetail.TotalPrice = offlineOrderDetail.UnitPrice * quantity;
                                using (IOfflineOrderDetailBL offlineOrderDetailBL = new OfflineOrderDetailBL())
                                {
                                    bool isAdded = await offlineOrderDetailBL.AddOfflineOrderDetailBL(offlineOrderDetail);

                                    if (isAdded)
                                    {
                                        WriteLine("Offline Order Detail Added");
                                    }
                                }
                            }
                            else
                            {
                                WriteLine("Invalid Serial Number");
                            }
                        }
                        else
                        {
                            WriteLine("Invalid choice");
                        }

                        WriteLine("Add product(Y/N)");
                        c = Char.Parse(ReadLine());
                    }
                    if (!(c == 'y') || (c == 'Y') || (c == 'n') || (c == 'N'))
                    {
                        WriteLine("Invalid Choice");
                    }
                }

                using (IOfflineOrderBL offlineOrderBL = new OfflineOrderBL())
                {
                    bool isAdded;

                    isAdded = await offlineOrderBL.AddOfflineOrderBL(offlineOrder);

                    if (isAdded)
                    {
                        // WriteLine("Offline Order Added");
                    }

                    using (IOfflineOrderDetailBL offlineOrderDetailBL = new OfflineOrderDetailBL())
                    {
                        //Get and display list of offline order details using order ID .
                        List <OfflineOrderDetail> offlineOrderDetails = await offlineOrderDetailBL.GetAllOfflineOrderDetailBL();

                        WriteLine("OfflineOrderDetails:");
                        if (offlineOrderDetails != null && offlineOrderDetails?.Count > 0)
                        {
                            WriteLine("#\tProductName\tUnitPrice\tQuantity\tTotal Price");
                            int serial2 = 0;
                            foreach (var offlineOrderDetail in offlineOrderDetails)
                            {
                                serial2++;
                                WriteLine($"{serial2}\t{offlineOrderDetail.ProductName}\t\t {offlineOrderDetail.UnitPrice}\t\t {offlineOrderDetail.Quantity}\t\t {offlineOrderDetail.TotalPrice}");
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Login (based on Email and Password)
        /// </summary>
        /// <returns></returns>
        static async Task <(UserType, IUser)> ShowLoginScreen()
        {
            //Read inputs
            string email, password;

            WriteLine("=====LOGIN=========");
            Write("Email: ");
            email = ReadLine();
            Write("Password: "******"*");
                }
                else
                {
                    Write("\b");
                }
            }while (key.Key != ConsoleKey.Enter);
            WriteLine("");

            using (IAdminBL adminBL = new AdminBL())
            {
                //Invoke GetAdminByEmailAndPasswordBL for checking email and password of Admin
                Admin admin = await adminBL.GetAdminByEmailAndPasswordBL(email, password);

                if (admin != null)
                {
                    return(UserType.Admin, admin);
                }
            }

            using (ISalesPersonBL SalesPersonBL = new SalesPersonBL())
            {
                //Invoke GetAdminByEmailAndPasswordBL for checking email and password of Admin
                SalesPerson SalesPerson = await SalesPersonBL.GetSalesPersonByEmailAndPasswordBL(email, password);

                if (SalesPerson != null)
                {
                    return(UserType.SalesPerson, SalesPerson);
                }
            }
            using (IRetailerBL RetailerBL = new RetailerBL())
            {
                //Invoke GetAdminByEmailAndPasswordBL for checking email and password of Admin
                Retailer retailer = await RetailerBL.GetRetailerByEmailAndPasswordBL(email, password);

                if (retailer != null)
                {
                    return(UserType.Retailer, retailer);
                }
            }

            WriteLine("Invalid Email or Password. Please try again...");
            return(UserType.Anonymous, null);
        }
        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);
        }
        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;
            }
        }
Esempio n. 20
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;
            }
        }