示例#1
0
        public AuditoriumDto Execute(int search)
        {
            var query = _context.Auditoriums.Include(x => x.Seats).AsQueryable();

            var auditoirum = query.FirstOrDefault(a => a.Id == search);

            if (auditoirum == null)
            {
                throw new NotFoundException(search, typeof(Auditorium));
            }

            var response = new AuditoriumDto
            {
                Id              = auditoirum.Id,
                Name            = auditoirum.Name,
                CreatedAt       = auditoirum.CreatedAt,
                AuditoirumSeats = auditoirum.Seats.Select(s => new AuditoirumSeats
                {
                    Id     = s.Id,
                    Number = s.Number
                })
            };

            return(response);
        }
示例#2
0
        public void Execute(AuditoriumDto request)
        {
            _validator.ValidateAndThrow(request);

            var auditorium = new Auditorium
            {
                Name = request.Name
            };

            _context.Auditoriums.Add(auditorium);
            _context.SaveChanges();

            int lastAuditoriumId = _context.Auditoriums.Max(item => item.Id);

            for (var i = 1; i <= 10; i++)
            {
                var seat = new Seat
                {
                    Number       = i,
                    AuditoriumId = lastAuditoriumId
                };

                _context.Seats.Add(seat);
            }

            _context.SaveChanges();
        }
示例#3
0
        private void ImportAuditorium(AuditoriumDto auditoriumDto)
        {
            string cinemaName = auditoriumDto.CinemaName;

            InputDataValidator.ValidateStringMaxLength(cinemaName, Constants.MaxCinemaNameLength);

            string townName = auditoriumDto.CinemaTownName;

            townValidator.CheckTownExisting(townName);

            int townId   = townService.GetTownId(townName);
            int cinemaId = cinemaService.GetCinemaId(cinemaName, townId);

            cinemaValidator.CheckCinemaExisting(cinemaName, townId);

            byte number = auditoriumDto.Number;

            auditoriumValidator.ValidateAuditoriumDoesNotExist(number, cinemaId, cinemaName);

            auditoriumService.AddAuditorium(number, cinemaId);

            Console.WriteLine(string.Format(Constants.ImportSuccessMessages.AuditoriumAddedSuccess, number, cinemaName, townName));
        }
        /// <summary>
        /// Adapt 2 external BCs into 1 (our BC).
        /// </summary>
        /// <param name="auditoriumDto">The topology of an Auditorium coming from the AuditoriumLayout.API</param>
        /// <param name="reservedSeatsDto">The list of already reserved seats coming from the SeatReservations.API</param>
        /// <returns>An instance of <see cref="AuditoriumSeating"/> (i.e. The topology of the Auditorium with seats availability mapped)</returns>
        private static AuditoriumSeating AdaptAuditoriumSeatingDto(AuditoriumDto auditoriumDto, ReservedSeatsDto reservedSeatsDto)
        {
            var rows = new Dictionary <string, Row>();

            foreach (var(rowName, seatDtos) in auditoriumDto.Rows)
            {
                var seats = new List <Seat>();
                foreach (var seatDto in seatDtos)
                {
                    var number        = ExtractSeatNumber(seatDto.Name);
                    var priceCategory = ConvertCategory(seatDto.Category);

                    var isReservationsSeat = reservedSeatsDto.ReservedSeats.Contains(seatDto.Name);
                    var seatAvailability   = isReservationsSeat ? SeatAvailability.Reserved : SeatAvailability.Available;

                    seats.Add(new Seat(rowName, number, priceCategory, seatAvailability));
                }

                rows[rowName] = new Row(rowName, seats);
            }

            return(new AuditoriumSeating(rows));
        }
 public IActionResult Post([FromBody] AuditoriumDto dto,
                           [FromServices] IAuditoriumInsert command)
 {
     _executor.ExecuteCommand(command, dto);
     return(StatusCode(201));
 }