예제 #1
0
        public IActionResult AddOrder(AddOrderDTO dto)
        {
            Passenger passenger = _passengerRepo.GetPassengerBySeat(dto.SeatNumber);

            if (passenger == null)
            {
                return(BadRequest());
            }
            Order order = new Order(passenger, dto.Time);

            foreach (AddOrderlineDTO olDTO in dto.OrderlineDTOs)
            {
                Product product = _productRepo.GetProductById(olDTO.ProductId);
                if (product == null)
                {
                    return(BadRequest());
                }
                Orderline ol = new Orderline(olDTO.Number, product, order);
                ol.CalculateTotalPrice();
                order.AddOrderline(ol);
            }
            order.CalculateTotalPrice();
            try
            {
                _orderRepo.AddOrder(order);
                _orderRepo.SaveChanges();
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }
            return(Ok(dto));
        }
예제 #2
0
        public IActionResult GetPassengerBySeat(string seat)
        {
            Passenger passenger = _passengerRepository.GetPassengerBySeat(seat);

            if (passenger == null)
            {
                return(NotFound());
            }
            return(Ok(new PassengerDTO(passenger)));
        }