Advertisement
Guest User

Untitled

a guest
Feb 13th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.30 KB | None | 0 0
  1. using LaundryBookingApp.Model;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace LaundryBookingApp
  9. {
  10. public class DAL
  11. {
  12. LaundryBookingAppContext db = new LaundryBookingAppContext();
  13.  
  14. public void AddResident(Resident resident)
  15. { try
  16. {
  17. db.Residents.Add(resident);
  18. db.SaveChanges();
  19. } catch (Exception e)
  20. {
  21. Console.WriteLine(e.ToString());
  22. }
  23. }
  24. public void AddLaundryRoom (LaundryRoom laundryroom)
  25. {
  26. try
  27. {
  28. db.LaundryRooms.Add(laundryroom);
  29. db.SaveChanges();
  30. } catch (Exception e)
  31. {
  32. Console.WriteLine(e.ToString());
  33. }
  34. }
  35. public void AddBooking (Booking booking)
  36. {
  37. try
  38. {
  39. db.Bookings.Add(booking);
  40. db.SaveChanges();
  41. } catch (Exception e)
  42. {
  43. Console.WriteLine(e.ToString());
  44. }
  45. }
  46. public void DeleteResident (int residentId)
  47. {
  48. try
  49. {
  50. Resident r = db.Residents.Find(residentId);
  51. db.Residents.Remove(r);
  52. db.SaveChanges();
  53. } catch (Exception e)
  54. {
  55. Console.WriteLine(e.ToString());
  56. }
  57. }
  58. public void DeleteLaundryRoom (int laundryRoomId)
  59. {
  60. try
  61. {
  62. db.LaundryRooms.Remove(db.LaundryRooms.Find(laundryRoomId));
  63. db.SaveChanges();
  64. } catch (Exception e)
  65. {
  66. Console.WriteLine(e.ToString());
  67. }
  68. }
  69. public void DeleteBooking (int bookingId)
  70. {
  71. try
  72. {
  73. Booking b = db.Bookings.Find(bookingId);
  74. db.Bookings.Remove(b);
  75. db.SaveChanges();
  76. } catch (Exception e)
  77. {
  78. Console.WriteLine(e.ToString());
  79. }
  80. }
  81. public void UpdateResident(int residentId, int ssn, string name)
  82. {
  83. try
  84. {
  85. Resident r = db.Residents.Find(residentId);
  86. r.Ssn = ssn;
  87. r.Name = name;
  88. db.SaveChanges();
  89. } catch (Exception e)
  90. {
  91. Console.WriteLine(e.ToString());
  92. }
  93. }
  94. public void UpdateLaundryRoom (int laundryRoomId, string tumbleDryer, string dryingCabinet, string ironingBoard)
  95. {
  96. try
  97. {
  98. LaundryRoom l = db.LaundryRooms.Find(laundryRoomId);
  99. l.TumbleDryer = tumbleDryer;
  100. l.DryingCabinet = dryingCabinet;
  101. l.IroningBoard = ironingBoard;
  102. db.SaveChanges();
  103. } catch (Exception e)
  104. {
  105. Console.WriteLine(e.ToString());
  106. }
  107. }
  108. public void UpdateBooking (int bookingId, int laundryRoomId, DateTime startTime, DateTime endTime)
  109. {
  110. try
  111. {
  112. Booking b = db.Bookings.Find(bookingId);
  113. b.LaundryRoomId = laundryRoomId;
  114. b.StartTime = startTime;
  115. b.EndTime = endTime;
  116. db.SaveChanges();
  117. } catch (Exception e)
  118. {
  119. Console.WriteLine(e.ToString());
  120. }
  121. }
  122. public Resident FindResident (int residentID)
  123. {
  124. try
  125. {
  126. Resident r = db.Residents.Find(residentID);
  127.  
  128. return r;
  129. } catch (Exception e)
  130. {
  131. Console.WriteLine(e.ToString());
  132. } return null;
  133.  
  134. }
  135. public LaundryRoom FindLaundryRoom (int laundryRoomID)
  136. {
  137. try
  138. {
  139. LaundryRoom l = db.LaundryRooms.Find(laundryRoomID);
  140. if (l != null)
  141. {
  142. return l;
  143. }
  144. } catch (Exception e)
  145. {
  146. Console.WriteLine(e.ToString());
  147. }
  148. return null;
  149. }
  150. public Booking FindBooking (int bookingID)
  151. { try
  152. {
  153. Booking b = db.Bookings.Find(bookingID);
  154. if (b != null)
  155. {
  156. return b;
  157. }
  158. } catch (Exception e)
  159. {
  160. Console.WriteLine(e.ToString());
  161. } return null;
  162.  
  163. }
  164. public List<Booking> FindBookings(int residentId)
  165. {
  166. List<Booking> list = new List<Booking>();
  167. list = db.Bookings.ToList();
  168. return list;
  169. }
  170. public List<Resident> FindAllResidents()
  171. {
  172. return db.Residents.ToList();
  173. }
  174. public List <Booking> FindAllBookings ()
  175. {
  176. return db.Bookings.ToList();
  177. }
  178. public List <LaundryRoom> FindAllLaundryRooms ()
  179. {
  180. return db.LaundryRooms.ToList();
  181. }
  182.  
  183.  
  184. }
  185. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement