Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using LaundryBookingApp.Model;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace LaundryBookingApp
- {
- public class DAL
- {
- LaundryBookingAppContext db = new LaundryBookingAppContext();
- public void AddResident(Resident resident)
- { try
- {
- db.Residents.Add(resident);
- db.SaveChanges();
- } catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- }
- }
- public void AddLaundryRoom (LaundryRoom laundryroom)
- {
- try
- {
- db.LaundryRooms.Add(laundryroom);
- db.SaveChanges();
- } catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- }
- }
- public void AddBooking (Booking booking)
- {
- try
- {
- db.Bookings.Add(booking);
- db.SaveChanges();
- } catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- }
- }
- public void DeleteResident (int residentId)
- {
- try
- {
- Resident r = db.Residents.Find(residentId);
- db.Residents.Remove(r);
- db.SaveChanges();
- } catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- }
- }
- public void DeleteLaundryRoom (int laundryRoomId)
- {
- try
- {
- db.LaundryRooms.Remove(db.LaundryRooms.Find(laundryRoomId));
- db.SaveChanges();
- } catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- }
- }
- public void DeleteBooking (int bookingId)
- {
- try
- {
- Booking b = db.Bookings.Find(bookingId);
- db.Bookings.Remove(b);
- db.SaveChanges();
- } catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- }
- }
- public void UpdateResident(int residentId, int ssn, string name)
- {
- try
- {
- Resident r = db.Residents.Find(residentId);
- r.Ssn = ssn;
- r.Name = name;
- db.SaveChanges();
- } catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- }
- }
- public void UpdateLaundryRoom (int laundryRoomId, string tumbleDryer, string dryingCabinet, string ironingBoard)
- {
- try
- {
- LaundryRoom l = db.LaundryRooms.Find(laundryRoomId);
- l.TumbleDryer = tumbleDryer;
- l.DryingCabinet = dryingCabinet;
- l.IroningBoard = ironingBoard;
- db.SaveChanges();
- } catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- }
- }
- public void UpdateBooking (int bookingId, int laundryRoomId, DateTime startTime, DateTime endTime)
- {
- try
- {
- Booking b = db.Bookings.Find(bookingId);
- b.LaundryRoomId = laundryRoomId;
- b.StartTime = startTime;
- b.EndTime = endTime;
- db.SaveChanges();
- } catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- }
- }
- public Resident FindResident (int residentID)
- {
- try
- {
- Resident r = db.Residents.Find(residentID);
- return r;
- } catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- } return null;
- }
- public LaundryRoom FindLaundryRoom (int laundryRoomID)
- {
- try
- {
- LaundryRoom l = db.LaundryRooms.Find(laundryRoomID);
- if (l != null)
- {
- return l;
- }
- } catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- }
- return null;
- }
- public Booking FindBooking (int bookingID)
- { try
- {
- Booking b = db.Bookings.Find(bookingID);
- if (b != null)
- {
- return b;
- }
- } catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- } return null;
- }
- public List<Booking> FindBookings(int residentId)
- {
- List<Booking> list = new List<Booking>();
- list = db.Bookings.ToList();
- return list;
- }
- public List<Resident> FindAllResidents()
- {
- return db.Residents.ToList();
- }
- public List <Booking> FindAllBookings ()
- {
- return db.Bookings.ToList();
- }
- public List <LaundryRoom> FindAllLaundryRooms ()
- {
- return db.LaundryRooms.ToList();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement