Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
52 lines (45 sloc) 1.6 KB
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RoomReservation.Lib.Model;
namespace RoomReservation.Lib.Repositories
{
public class RoomRepository : IRoomRepository
{
private readonly IBookingContext _bookingContext;
public RoomRepository(IBookingContext bookingContext)
{
_bookingContext = bookingContext;
}
public IEnumerable<Room> GetRoomList()
{
return _bookingContext.Rooms.ToList();
}
public IEnumerable<BookingSchedule> GetRoomBookings(int roomId, DateTime date)
{
var startDate = date.Date;
var endDate = startDate.AddDays(1);
return _bookingContext.BookingSchedules
.Where(b => b.RoomId == roomId && b.StartTime >= startDate && b.StartTime < endDate)
.OrderBy(b => b.StartTime)
.ToList();
}
public void BookRoom(BookingSchedule bookingSchedule)
{
var booking = _bookingContext.BookingSchedules.Create();
_bookingContext.BookingSchedules.Add(booking);
_bookingContext.SaveChanges();
}
public void RemoveBooking(int bookingId)
{
var bookingSchedule = new BookingSchedule() { Id = bookingId };
_bookingContext.BookingSchedules.Attach(bookingSchedule);
_bookingContext.BookingSchedules.Remove(bookingSchedule);
_bookingContext.SaveChanges();
}
}
}