Exemple #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);
        }
        private void HandleRemoveReservationCommand(object parameter)
        {
            var projection = GetDefaultCinemaMovieProjectionsView().CurrentItem as ProjectionModel;

            var reservation = new RejectReservationModel()
            {
                Email = RemoveReservationEmail,
                UserCode = RemoveReservationUserCode
            };

            var success = DataPersister.RemoveReservationForProjection(projection.Id, reservation);

            if (!success)
            {
                MessageBox.Show("Error removing reservation!");
                return;
            }

            MessageBox.Show("Reservation successfully removed!");
        }
        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);
            });
        }
        private void ExecuteProcessCancelReservation(object obj)
        {
            if (!string.IsNullOrEmpty(ReservationCancelToken) && !string.IsNullOrEmpty(UserEmail))
            {
                AppCache.Config.IsBusyPool.Add("Select Reservation, please wait");

                var cancelReservation = new RejectReservationModel()
                {
                    Email = UserEmail,
                    UserCode = ReservationCancelToken
                };
                LoadData.CancelReservation(SelectedProjection.Id, cancelReservation, result =>
                {
                    ExecuteStopCancelReservation(null);
                    ReservationCancelToken = string.Empty;
                    LoadProjection();
                    AppCache.Config.IsBusyPool.TryRemove("Select Reservation, please wait");
                });
            }
        }
        public static bool RemoveReservationForProjection(int projectionId, RejectReservationModel reservation)
        {
            if (projectionId <= 0)
            {
                return false;
            }

            if (reservation == null ||
                string.IsNullOrEmpty(reservation.Email) ||
                string.IsNullOrEmpty(reservation.UserCode))
            {
                return false;
            }

            var result = HttpRequester.Put(BaseServicesUrl + "projections/" + projectionId, reservation);
            return result;
        }
        public static void CancelReservation(int projectionId, RejectReservationModel model, Action<object> action)
        {
            var bw = new BackgroundWorker();
            bw.DoWork += ((se, ea) =>
            {
                try
                {
                    var moveisResponse = HttpRequester.Put(BaseServicesUrl + "projections/" + projectionId, model);
                    ea.Result = moveisResponse;
                }
                catch (Exception ex)
                {
                    ea.Result = "Database Error! Please try again.";
                }

            });
            bw.RunWorkerAsync();
            bw.RunWorkerCompleted += ((se, ea) =>
            {
                if (action != null)
                {
                    action(ea.Result);
                }
            });
        }