public void DeleteTheater(int TheaterID)
        {
            TheaterDal dal = new TheaterDal();
            dal.DeleteEntity(TheaterID);

            // Remove the theater from the cache
            rwl.AcquireWriterLock(new TimeSpan(1, 0, 0));
            if (HallCache[TheaterID.ToString()] != null)
                HallCache.Remove(TheaterID.ToString());
            rwl.ReleaseWriterLock();
        }
        /// <summary>
        /// Internal implementation of Find theater
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        private Contracts.Theater InternalFindTheater(string key)
        {
            Contracts.Theater result = null;
            
            // If the theater is in the cache return it from there
            rwl.AcquireReaderLock(new TimeSpan(1, 0, 0));
            if (HallCache[key] != null)
            {
                result = (HallCache[key] as Contracts.Theater);
                rwl.ReleaseReaderLock();
                return result;
            }
            rwl.ReleaseReaderLock();
            //Read the theater info from the DB
            TheaterDal dal = new TheaterDal();
            int id;
           
            // look in the data access according to the id.
            if (int.TryParse(key,out id))
                result = dal.GetEntity(id);

             // look in the data access according to the name
            if (result == null)
                result = dal.GetEntity(key);

            //Write it to the cache
            if (result != null)
            {
                rwl.AcquireWriterLock(new TimeSpan(1, 0, 0));
                HallCache.Add(result.ID.ToString(), result, null, DateTime.Now.AddYears(1),
                   Cache.NoSlidingExpiration, CacheItemPriority.High, null);
                rwl.ReleaseWriterLock();
            }
           
            return result;
        }
 public void UpdateTheater(Contracts.Theater newTheater)
 {
     TheaterDal dal = new TheaterDal();
     
     // Add the theater to the cache
     rwl.AcquireWriterLock(new TimeSpan(1, 0, 0));
     if (HallCache[newTheater.ID.ToString()] != null)
         HallCache.Remove(newTheater.ID.ToString());
     HallCache.Add(newTheater.ID.ToString(), newTheater, null, DateTime.Now.AddYears(1),
      Cache.NoSlidingExpiration, CacheItemPriority.High, null);
     rwl.ReleaseWriterLock();
     
     dal.UpdateEntity(newTheater);
 }
        /// <summary>
        /// Submit a new reservation
        /// </summary>
        /// <param name="reservation"></param>
        /// <returns></returns>
        public Guid CreateResrvation(Contracts.Reservation reservation)
        {
            // Create the event in the database
            ReservationDal reservationDal = new ReservationDal();
            TheaterDal theaterDal = new TheaterDal();

            //1. validate
            foreach (var si in reservation.Seats)
            {
                if ((si.Row < 0) || (si.Seat < 0))
                    throw new ArgumentException(StringsResource.InvalidSeatOrRow);

                //Check that there is no other reservation for the same seats               
                var takenSeats = GetHallState(reservation.EventID);
                foreach (var item in reservation.Seats)
            	{
            		 if (takenSeats.Contains(item))
                         throw new ReservationException(StringsResource.SeatAlreadyTaken);
            	}
               
            }

            //2. Create an ID if needed. 
            if (reservation.ID == Guid.Empty)
                reservation.ID = Guid.NewGuid(); 
            
            //3. Create the reservation
            Guid id = reservationDal.CreateEntity(reservation);

            //4. Add it to the cache.
           rwl.AcquireWriterLock(new TimeSpan(1,0,0));

                if (HallCache[reservation.EventID.ToString()] == null)
                    HallCache.Add(reservation.EventID.ToString(), new List<Contracts.Reservation>() { reservation },
                         null,DateTime.Now.AddDays(30),TimeSpan.FromHours(5),CacheItemPriority.Normal,null);
                 else
                    (HallCache[reservation.EventID.ToString()] as List<Contracts.Reservation>).Add(reservation);
           
            rwl.ReleaseWriterLock();

            return id;
        }