Beispiel #1
0
        public void ToBookSeats()
        {
            try
            {
                byte[] jsonBookings = new byte[Request.ContentLength];
                Request.InputStream.Read(jsonBookings, 0, jsonBookings.Length);

                var bookings = SerializeBookings(System.Text.Encoding.UTF8.GetString(jsonBookings));

                foreach (var booking in bookings)
                {
                    if (_repository.Bookings.
                        FirstOrDefault(b => b.MovieId == booking.MovieId &&
                                       b.SeatNum == booking.SeatNum &&
                                       b.SeatRow == booking.SeatRow) != null)
                    {
                        WriteJsonResponse(JsonConvert.SerializeObject(new { code = 403, Message = "Seat already booked", Booking = booking }), (int)HttpStatusCode.Forbidden);
                        return;
                    }
                }

                foreach (var booking in bookings)
                {
                    _repository.SaveBooking(booking);
                }

                WriteJsonResponse(JsonConvert.SerializeObject(new { result = "ok", Message = "Seats books" }), (int)HttpStatusCode.OK);
            }
            catch (Exception e)
            {
                WriteJsonResponse(JsonConvert.SerializeObject(new { code = 400, Message = e.Message }), (int)HttpStatusCode.BadRequest);
            }
        }