private static void DeleteDistributorAddress() { try { int deleteDistributorAddressID; Console.WriteLine("Enter DistributorAddressID to Delete:"); deleteDistributorAddressID = Convert.ToInt32(Console.ReadLine()); DistributorAddress deleteDistributorAddress = DistributorAddressBL.SearchDistributorAddressBL(deleteDistributorAddressID); if (deleteDistributorAddress != null) { bool distributorAddressdeleted = DistributorAddressBL.DeleteDistributorAddressBL(deleteDistributorAddressID); if (distributorAddressdeleted) { Console.WriteLine("Distributor Address Deleted"); } else { Console.WriteLine("Distributor Address not Deleted "); } } else { Console.WriteLine("No Distributor Address Details Available"); } } catch (InventoryException ex) { Console.WriteLine(ex.Message); } }
public static async Task DeleteDistributorAddress() { try { using (IDistributorAddressBL distributorAddressBL = new DistributorAddressBL()) { //Read Sl.No Write("Distributor Address #: "); bool isNumberValid = int.TryParse(ReadLine(), out int serial); if (isNumberValid) { serial--; List <DistributorAddress> distributorsAddress = await distributorAddressBL.GetAllDistributorAddressesBL(); if (serial <= distributorsAddress.Count - 1) { //Confirmation DistributorAddress distributorAddress = distributorsAddress[serial]; Write("Are you sure? (Y/N): "); string confirmation = ReadLine(); if (confirmation.Equals("Y", StringComparison.OrdinalIgnoreCase)) { //Invoke DeleteDistributorAddressBL method to delete bool isDeleted = await distributorAddressBL.DeleteDistributorAddressBL(distributorAddress.DistributorAddressID); if (isDeleted) { WriteLine("Distributor Address Deleted"); } } } else { WriteLine($"Invalid Distributor Address #.\nPlease enter a number between 1 to {distributorsAddress.Count}"); } } else { WriteLine($"Invalid number."); } } } catch (Exception ex) { ExceptionLogger.LogException(ex); WriteLine(ex.Message); } }