Exemplo n.º 1
0
        public List<OrderDTO> ReserveRooms(List<int> roomIdsList, DateTime dateFrom, int daysCount = 1)
        {
            IRoomRepository roomsRepo = new RoomRepository(this._connStrBuilder.ConnectionString);
            IOrderRepository ordersRepo = new OrderRepository(this._connStrBuilder.ConnectionString);
            var rooms = new List<Room>();
            var orders = new List<OrderDTO>();

            if (roomIdsList != null)
            {
                rooms = roomsRepo.GetRoomsByIds(roomIdsList);

                foreach (var room in rooms)
                {
                    if (room.roomStatus == (int)RoomStatus.Free)
                    {
                        string hash = this.GenHash();

                        DateTime startDate;
                        if (dateFrom == null || dateFrom < DateTime.Today + TimeSpan.FromDays(1))
                        {
                            startDate = DateTime.Today + TimeSpan.FromDays(1);
                        }
                        else
                        {
                            startDate = dateFrom;
                        }

                        ordersRepo.AddOrder( new Order() {
                            roomId = room.id,
                            orderToken = hash,
                            reservationStart = startDate,
                            reservationDays = daysCount
                        });

                        orders.Add(new OrderDTO() {
                            roomId = room.id,
                            orderToken = hash,
                            reservationStart = startDate,
                            reservationDays = daysCount
                        });
                    }
                }
            }
            return orders;
        }