Пример #1
0
        internal static void RemoveCommand(string email, string code, int projectionID)
        {
            ValidateEmail(email);
            RejectReservationModel removeModule = new RejectReservationModel()
            {
                Email    = email,
                UserCode = code,
            };

            HttpRequester.Put(BaseServicesUrl + "projections/" + projectionID, removeModule);
        }
Пример #2
0
        public HttpResponseMessage RejectReservation(int projectionId, RejectReservationModel model)
        {
            return(this.ExecuteOperationHandleExceptions(() =>
            {
                var context = new CinemaReserveDbContext();
                var theProjection = context.Projections.FirstOrDefault(pr => pr.Id == projectionId);
                if (theProjection == null)
                {
                    throw new ArgumentNullException("projection is either non-existant or is not available");
                }

                var emailToLower = model.Email.ToLower();
                var userCodeToLower = model.UserCode.ToLower();

                var theReservation = theProjection
                                     .Reservations
                                     .FirstOrDefault(r => r.UserCode == userCodeToLower &&
                                                     r.UserEmail == emailToLower);
                if (theReservation == null)
                {
                    throw new InvalidOperationException("Unauthorized operation");
                }

                var freeSeatStatus = context.SeatStatus.FirstOrDefault(st => st.Status == "free");

                foreach (var seat in theReservation.ReservedSeats)
                {
                    seat.Status = freeSeatStatus;
                    theReservation.ReservedSeats.Remove(seat);
                }
                theProjection.Reservations.Remove(theReservation);
                //context.Reservations.Remove(theReservation);
                context.SaveChanges();
                return this.Request.CreateResponse(HttpStatusCode.NoContent);
            }));
        }