Ejemplo n.º 1
0
        /// <summary>
        /// Delete Account.
        /// </summary>
        /// <returns></returns>
        public static async Task DeleteAccount()
        {
            try
            {
                using (IAccountBL distributorBL = new AccountBL())
                {
                    //Read Sl.No
                    Write("Account #: ");
                    bool isNumberValid = int.TryParse(ReadLine(), out int serial);
                    if (isNumberValid)
                    {
                        serial--;
                        List <Account> distributors = await distributorBL.GetAllAccountsBL();

                        if (serial <= distributors.Count - 1)
                        {
                            //Confirmation
                            Account distributor = distributors[serial];
                            Write("Are you sure? (Y/N): ");
                            string confirmation = ReadLine();

                            if (confirmation.Equals("Y", StringComparison.OrdinalIgnoreCase))
                            {
                                //Invoke DeleteDistributorBL method to delete
                                bool isDeleted = await distributorBL.DeleteAccountBL(distributor.DistributorID);

                                if (isDeleted)
                                {
                                    WriteLine("Account Deleted");
                                }
                            }
                        }
                        else
                        {
                            WriteLine($"Invalid Account #.\nPlease enter a number between 1 to {distributors.Count}");
                        }
                    }
                    else
                    {
                        WriteLine($"Invalid number.");
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogException(ex);
                WriteLine(ex.Message);
            }
        }