Exemple #1
0
 private static void DeleteDistributor()
 {
     try
     {
         int deleteDistributorID;
         Console.WriteLine("Enter DistributorID to Delete:");
         deleteDistributorID = Convert.ToInt32(Console.ReadLine());
         Distributor deleteDistributor = DistributorBL.SearchDistributorBL(deleteDistributorID);
         if (deleteDistributor != null)
         {
             bool distributordeleted = DistributorBL.DeleteDistributorBL(deleteDistributorID);
             if (distributordeleted)
             {
                 Console.WriteLine("Distributor Deleted");
             }
             else
             {
                 Console.WriteLine("Distributor not Deleted ");
             }
         }
         else
         {
             Console.WriteLine("No Distributor Details Available");
         }
     }
     catch (InventoryException ex)
     {
         Console.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);
            }
        }