Beispiel #1
0
        public IHttpActionResult PostCinemaHalls(dynamic CinemaHall)
        {
            int    CinemaID            = CinemaHall.CinemaID;
            string Name                = CinemaHall.Name;
            int    NumberOfSeatRows    = CinemaHall.NumberOfSeatRows;
            int    NumberOfSeatColumns = CinemaHall.NumberOfSeatColumns;

            CinemaHalls cinemaHall = new CinemaHalls();

            cinemaHall.CinemaID  = CinemaID;
            cinemaHall.Name      = Name;
            cinemaHall.IsDeleted = false;

            principal.CinemaHalls.Add(cinemaHall);
            principal.SaveChanges();

            Task.Run(() => SeatArrayHandler.InsertSeats(cinemaHall.CinemaHallID, NumberOfSeatRows, NumberOfSeatColumns));
            return(Ok());
        }
Beispiel #2
0
        private void InitLayout()
        {
            Rows  = new List <Row>();
            Seats = new List <Seat>();
            var rowCategories = CreateRowCategories();
            var categoryIds   = rowCategories
                                .Where(c => !c.Name.ToLower().StartsWith("unused"))
                                .Select(c => c.Id)
                                .ToList();

            var cinemaHall = CinemaHalls.Last();

            Rows.Add(new Row
            {
                Id = 1L, CategoryId = rowCategories.First().Id, CinemaHallId = cinemaHall.Id, Number = 10
            });
            Rows.Add(new Row
            {
                Id = 2L, CategoryId = rowCategories.First().Id, CinemaHallId = cinemaHall.Id, Number = 11
            });
            Seats.Add(new Seat {
                Id = 1L, Number = 1, LayoutColumn = 0, LayoutRow = 0, RowId = 1L
            });
            Seats.Add(new Seat {
                Id = 2L, Number = 2, LayoutColumn = 0, LayoutRow = 1, RowId = 1L
            });
            Seats.Add(new Seat {
                Id = 3L, Number = 3, LayoutColumn = 0, LayoutRow = 2, RowId = 1L
            });
            Seats.Add(new Seat
            {
                Id = 4L, Number = 1, LayoutColumn = cinemaHall.SizeColumn - 1, LayoutRow = 0, RowId = 2L
            });
            Seats.Add(new Seat
            {
                Id = 5L, Number = 2, LayoutColumn = cinemaHall.SizeColumn - 1, LayoutRow = 1, RowId = 2L
            });
            Seats.Add(new Seat
            {
                Id = 6L, Number = 3, LayoutColumn = cinemaHall.SizeColumn - 1, LayoutRow = 2, RowId = 2L
            });
            Rows.Add(new Row
            {
                Id = 3L, CategoryId = rowCategories.First().Id, CinemaHallId = CinemaHalls.Last().Id, Number = 12
            });

            cinemaHall = CinemaHalls.First();
            const int sizeRow    = 20;
            const int sizeColumn = 30;

            var corridorIndex1 = (int)(sizeColumn * .25);
            var corridorIndex2 = (int)(sizeColumn * .75);
            var rowFactor      = (double)sizeRow / categoryIds.Count;

            var rowIdOffset = Rows.Count;
            var seatId      = Seats.Count + 1;

            for (var row = 1; row < sizeRow; row += 2)
            {
                var rowNumber = row / 2 + 1;
                Rows.Add(new Row
                {
                    Id           = rowNumber + rowIdOffset,
                    CinemaHallId = cinemaHall.Id,
                    CategoryId   = categoryIds[(int)(row / rowFactor)],
                    Number       = rowNumber
                });

                for (var column = 0; column < sizeColumn; column++)
                {
                    if (column == corridorIndex1 || column == corridorIndex2)
                    {
                        continue;
                    }

                    var seatNumber = column + 1;
                    Seats.Add(new Seat
                    {
                        Id           = seatId++,
                        RowId        = rowNumber + rowIdOffset,
                        Number       = seatNumber,
                        LayoutRow    = row,
                        LayoutColumn = column
                    });
                }
            }
        }