/// <summary>
        /// Displays list of Distributors.
        /// </summary>
        /// <returns></returns>
        public static async Task ViewDistributors()
        {
            try
            {
                using (IDistributorBL distributorBL = new DistributorBL())
                {
                    //Get and display list of system users.
                    List <Distributor> distributors = await distributorBL.GetAllDistributorsBL();

                    WriteLine("DISTRIBUTORS:");
                    if (distributors != null && distributors?.Count > 0)
                    {
                        WriteLine("#\tName\tMobile\tEmail\tCreated\tModified");
                        int serial = 0;
                        foreach (var distributor in distributors)
                        {
                            serial++;
                            WriteLine($"{serial}\t{distributor.DistributorName}\t{distributor.DistributorMobile}\t{distributor.Email}\t{distributor.CreationDateTime}\t{distributor.LastModifiedDateTime}");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogException(ex);
                WriteLine(ex.Message);
            }
        }
Exemple #2
0
 private static void ListAllDistributors()
 {
     try
     {
         List <Distributor> distributorList = DistributorBL.GetAllDistributorsBL();
         if (distributorList != null)
         {
             Console.WriteLine("******************************************************************************");
             Console.WriteLine("Distributor ID\t\tDistributor Name\t\tPhoneNumber");
             Console.WriteLine("******************************************************************************");
             foreach (Distributor distributor in distributorList)
             {
                 Console.WriteLine("{0}\t\t{1}\t\t{2}", distributor.DistributorID, distributor.DistributorName, distributor.DistributorContactNumber);
             }
             Console.WriteLine("******************************************************************************");
         }
         else
         {
             Console.WriteLine("No Guest Details Available");
         }
     }
     catch (InventoryException ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
        /// <summary>
        /// Updates Distributor.
        /// </summary>
        /// <returns></returns>
        public static async Task UpdateDistributor()
        {
            try
            {
                using (IDistributorBL distributorBL = new DistributorBL())
                {
                    //Read Sl.No
                    Write("Distributor #: ");
                    bool isNumberValid = int.TryParse(ReadLine(), out int serial);
                    if (isNumberValid)
                    {
                        serial--;
                        List <Distributor> distributors = await distributorBL.GetAllDistributorsBL();

                        if (serial <= distributors.Count - 1)
                        {
                            //Read inputs
                            Distributor distributor = distributors[serial];
                            Write("Name: ");
                            distributor.DistributorName = ReadLine();
                            Write("Mobile: ");
                            distributor.DistributorMobile = ReadLine();
                            Write("Email: ");
                            distributor.Email = ReadLine();

                            //Invoke UpdateDistributorBL method to update
                            bool isUpdated = await distributorBL.UpdateDistributorBL(distributor);

                            if (isUpdated)
                            {
                                WriteLine("Distributor Updated");
                            }
                        }
                        else
                        {
                            WriteLine($"Invalid Distributor #.\nPlease enter a number between 1 to {distributors.Count}");
                        }
                    }
                    else
                    {
                        WriteLine($"Invalid number.");
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogException(ex);
                WriteLine(ex.Message);
            }
        }
        /// <summary>
        /// Delete Distributor.
        /// </summary>
        /// <returns></returns>
        public static async Task DeleteDistributor()
        {
            try
            {
                using (IDistributorBL distributorBL = new DistributorBL())
                {
                    //Read Sl.No
                    Write("Distributor #: ");
                    bool isNumberValid = int.TryParse(ReadLine(), out int serial);
                    if (isNumberValid)
                    {
                        serial--;
                        List <Distributor> distributors = await distributorBL.GetAllDistributorsBL();

                        if (serial <= distributors.Count - 1)
                        {
                            //Confirmation
                            Distributor 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.DeleteDistributorBL(distributor.DistributorID);

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