You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.6 KiB

1 year ago
  1. using GMCabsDriverAssistant.Models;
  2. using SQLite;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace GMCabsDriverAssistant.Services
  8. {
  9. public class SQLiteDatabaseService
  10. {
  11. private readonly SQLiteAsyncConnection _database;
  12. public SQLiteDatabaseService(string dbPath)
  13. {
  14. _database = new SQLiteAsyncConnection(dbPath);
  15. _database.CreateTableAsync<AvailableBooking>();
  16. }
  17. public Task<int> SaveBookingIdsAsync(IEnumerable<string> bookingsId)
  18. {
  19. List<AvailableBooking> availableBookings = new List<AvailableBooking>();
  20. AvailableBooking booking = new AvailableBooking();
  21. foreach (var availableBookingId in bookingsId)
  22. {
  23. try
  24. {
  25. booking.BookingID = availableBookingId;
  26. Console.WriteLine($" Booking Id : {booking.BookingID}");
  27. availableBookings.Add(booking);
  28. }
  29. catch (Exception ex)
  30. {
  31. Console.WriteLine($" Exception Message : {ex.Message}");
  32. }
  33. }
  34. return _database.InsertAllAsync(availableBookings);
  35. }
  36. public Task<List<AvailableBooking>> GetBookingIdsAsync()
  37. {
  38. return _database.Table<AvailableBooking>().ToListAsync();
  39. }
  40. public Task<int> DeleteBookingIdsAsync(AvailableBooking bookingsId)
  41. {
  42. return _database.DeleteAsync(bookingsId);
  43. }
  44. }
  45. }