public bool AddReservation(Reservation reservation)
        {
            try
            {
                Reservation.Add(reservation);

                SaveChanges();

                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool RemoveReservation(Reservation reservation)
        {
            try
            {
                Reservation.Remove(reservation);

                SaveChanges();

                return true;
            }
            catch
            {
                return false;
            }
        }
        public ActionResult RemoveReservation(ReservationForChange reservForRemote)
        {
            int rId = int.Parse(reservForRemote.reservation);

            IQueryable<Reservation> reservations = db.Reservation.Where(r => r.ReservationId.Equals(rId));

            Reservation reserv = new Reservation();

            foreach (Reservation r in reservations)
            {
                reserv = r;
            }

            db.RemoveReservation(reserv);

            ReservationManager reservManager = new ReservationManager(reserv.StartDate);

            if (reservForRemote.view == 0)
            {
                ViewBag.id = "td";

                ViewBag.Auditoriums = db.Auditorium;
            }
            else if (reservForRemote.view == 1)
            {
                IQueryable<Auditorium> auditorium = db.Auditorium.Where(auditor => auditor.AuditoriumId.Equals(reserv.TargetAuditorium));

                foreach (Auditorium a in auditorium)
                {
                    reservManager.Table = new List<List<TD>>();

                    reservManager.Table = reservManager.GetDayRoomReservation(reserv.StartDate, a.AuditoriumName);

                    ViewBag.id = "td-day";

                    ViewBag.Room = a.AuditoriumName;

                    ViewBag.Date = reserv.StartDate;

                    ViewBag.Auditoriums = db.Auditorium.Where(auditor => auditor.AuditoriumName.Equals(a.AuditoriumName));
                }

            }
            else if (reservForRemote.view == 2)
            {
                IQueryable<Auditorium> auditorium = db.Auditorium.Where(auditor => auditor.AuditoriumId.Equals(reserv.TargetAuditorium));

                foreach (Auditorium a in auditorium)
                {
                    reservManager.Table = new List<List<TD>>();

                    reservManager.Table = reservManager.GetWeekReservation(reserv.StartDate, a.AuditoriumName);

                    ViewBag.id = "td";

                    ViewBag.week = reservManager.GetDays(reserv.StartDate);
                }
            }

            return PartialView("Table", reservManager);
        }
        public ActionResult AddReservation(NewResevation newReservation)
        {
            Reservation reservation = new Reservation();

            string email = Session["UserEmail"].ToString();

            reservation.CreatedBy = db.User.Where(u => u.Email.Equals(email)).First().UserId;

            reservation.StartDate = new DateTime(newReservation.year, newReservation.month, newReservation.day, newReservation.hour, 0, 0);

            if (newReservation.finish_hour == 0)
            {
                reservation.FinishDate = new DateTime(newReservation.year, newReservation.month, newReservation.day, newReservation.hour + 1, 0, 0);
            }
            else
            {
                if (newReservation.view == 1)
                {
                    reservation.FinishDate = new DateTime(newReservation.year, newReservation.month, newReservation.day, newReservation.finish_hour, 0, 0);
                }
                else
                {
                    reservation.FinishDate =
                        GetLastDayWeek(new DateTime(newReservation.year, newReservation.month, newReservation.day,
                            newReservation.finish_hour, 0, 0));
                }
            }

            reservation.Type = newReservation.type;

            reservation.Purpose = newReservation.purpose;

            if (newReservation.auditorium == 0)
            {
                reservation.TargetAuditorium = db.Auditorium.Where(a => a.AuditoriumName.Equals(newReservation.auditorium_name)).First().AuditoriumId;

                newReservation.auditorium = reservation.TargetAuditorium;
            }
            else
            {
                reservation.TargetAuditorium = newReservation.auditorium;
            }

            db.AddReservation(reservation);

            ReservationManager reservManager = new ReservationManager(reservation.StartDate);

            if (newReservation.view == 0)
            {
                ViewBag.id = "td";

                ViewBag.Auditoriums = db.Auditorium;
            }
            else if (newReservation.view == 1)
            {
                IQueryable<Auditorium> auditorium = db.Auditorium.Where(auditor => auditor.AuditoriumId.Equals(newReservation.auditorium));

                foreach (Auditorium a in auditorium)
                {
                    reservManager.Table = new List<List<TD>>();

                    ViewBag.Room = a.AuditoriumName;

                    ViewBag.Date = reservation.StartDate;

                    reservManager.Table = reservManager.GetDayRoomReservation(reservation.StartDate, a.AuditoriumName);

                    ViewBag.Auditoriums = db.Auditorium.Where(auditor => auditor.AuditoriumName.Equals(a.AuditoriumName));

                    ViewBag.id = "td-day";
                }
            }
            else if (newReservation.view == 2)
            {
                IQueryable<Auditorium> auditorium = db.Auditorium.Where(auditor => auditor.AuditoriumId.Equals(newReservation.auditorium));

                foreach (Auditorium a in auditorium)
                {
                    reservManager.Table = new List<List<TD>>();

                    ViewBag.id = "td";

                    ViewBag.week = reservManager.GetDays(reservation.StartDate);

                    reservManager.Table = reservManager.GetWeekReservation(reservation.StartDate, a.AuditoriumName);
                }
            }

            return PartialView("Table", reservManager);
        }
        private TD ConvertToTD(Reservation reservation)
        {
            TD td = new TD();

            td.User = reservation.User;

            td.ReservationId = reservation.ReservationId;

            td.Auditorium = reservation.Auditorium;

            td.CreatedBy = reservation.CreatedBy;

            td.FinishDate = reservation.FinishDate;

            td.StartDate = reservation.StartDate;

            td.TargetAuditorium = reservation.TargetAuditorium;

            td.Type = reservation.Type;

            td.Purpose = reservation.Purpose;

            return td;
        }