public ReservationModel MakeReservation(int projectionId, CreateReservationModel model) { return this.ExecuteOperationHandleExceptions(() => { this.ValidateEmail(model.Email); 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 reservedSeatStatus = context.SeatStatus.FirstOrDefault(st => st.Status == "reserved") ?? new SeatStatus() { Status = "reserved" }; List<Seat> reservedSeats = new List<Seat>(); using (TransactionScope tran = new TransactionScope()) { foreach (var seat in model.Seats) { var dbSeat = theProjection.Seats.FirstOrDefault(s => s.Row == seat.Row && s.Column == seat.Column); if (dbSeat == null || dbSeat.Status.Status == "reserved") { throw new InvalidOperationException("Seat is not available"); } dbSeat.Status = reservedSeatStatus; reservedSeats.Add(dbSeat); } tran.Complete(); } var reservation = new Reservation() { ReservedSeats = reservedSeats, UserEmail = model.Email.ToLower(), UserCode = this.GenerateUserCode() }; //context.Reservations.Add(reservation); theProjection.Reservations.Add(reservation); context.SaveChanges(); var reservationModel = Parser.ToReservationModel(reservation); return reservationModel; }); }
private void HandleCreateReservationCommand(object parameter) { var projection = GetDefaultCinemaMovieProjectionsView().CurrentItem as ProjectionModel; var reservation = new CreateReservationModel(); reservation.Email = CreateReservationEmail; // TODO: Get selected seats reservation.Seats = new[] { new SeatModel() { Row = new Random().Next(5), Column = new Random().Next(5) } }; var response = DataPersister.CreateReservationForProjection(projection.Id, reservation); if (response == null) { MessageBox.Show("Error creating reservation!"); return; } MessageBox.Show("User code: " + response.UserCode); }
internal static void MakeReservation(int projectionId, string email, IEnumerable<SeatViewModel> seats) { try { new MailAddress(email); } catch (FormatException ex) { throw new FormatException("Email is invalid", ex); } var reservationModel = new CreateReservationModel() { Email = email, Seats = seats.Select(t => new SeatModel() { Column = t.Column, Row = t.Row }) }; }
private void CreateReservation() { AppCache.Config.IsBusyPool.Add("Select Reservation, please wait"); var createReservation = new CreateReservationModel() { Email = "*****@*****.**", Seats = new List<SeatModel>() { SelectReservation } }; LoadData.Reservation(SelectedProjection.Id, createReservation, result => { var moviesResult = result as ReservationModel; if (SelectedProjection != null && moviesResult != null) { IsShowMessage = true; ReservationToken = moviesResult.UserCode; LoadProjection(); } AppCache.Config.IsBusyPool.TryRemove("Select Reservation, please wait"); }); }
public static ReservationModel CreateReservationForProjection(int projectionId, CreateReservationModel reservation) { if (projectionId <= 0) { return null; } if (reservation == null || string.IsNullOrEmpty(reservation.Email) || reservation.Seats == null || !reservation.Seats.Any()) { return null; } try { var result = HttpRequester.Post<ReservationModel>(BaseServicesUrl + "projections/" + projectionId, reservation); return result; } catch (WebException ex) { if (ex.Message == "The remote server returned an error: (400) Bad Request.") { return null; } throw; } }
public static void Reservation(int projectionId, CreateReservationModel model, Action<object> action) { var bw = new BackgroundWorker(); bw.DoWork += ((se, ea) => { try { var moveisResponse = HttpRequester.Post<ReservationModel>(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); } }); }
internal static string ReserveCall(object seats, string email, int projectionID) { ValidateEmail(email); var seatsCast = seats as IEnumerable<SeatModel>; CreateReservationModel model = new CreateReservationModel() { Seats = seatsCast, Email = email, }; ReservationModel code = HttpRequester.Post<ReservationModel>(BaseServicesUrl + "projections/" + projectionID, model); return code.UserCode; }