using ResourcesManager.Interfaces;
using ResourcesManager.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ResourcesManager.Repositories
{
    public class ReservationRepository : BaseRepository, IReservationRepository
    {
        public ReservationRepository(ApplicationDbContext context) : base(context) { }

        public bool DeleteReservation(int id)
        {
            var reservation = Context.Reservations.Find(id);
            Context.Reservations.Remove(reservation);
            Save();
            return true;
        }

        public Reservation GetReservationByID(int id)
        {
            return Context.Reservations.Find(id);
        }

        public IEnumerable<Reservation> GetReservations()
        {
            return Context.Reservations;
        }

        public bool InsertReservation(Reservation reservation)
        {
            Context.Reservations.Add(reservation);
            Save();
            return true;
        }

        public bool UpdateReservation(Reservation reservation)
        {
            Context.Entry(reservation).State = EntityState.Modified;
            Save();
            return true;
        }
    }
}
