コード例 #1
0
        public ResponseModel UpdateReservation(UpdateReservationModelDTO dto)
        {
            if (dto == null)
            {
                return new ResponseModel()
                       {
                           Code = ResultActionModelCode.NoData, Message = "No data"
                       }
            }
            ;

            using (var unity = _factory.GetUnitOfWork(UnitOfWorkContext.Default))
            {
                var reservation = unity.GetRepository <Reservation>().AsQueryable()
                                  .FirstOrDefault(x => x.Id == dto.ReservationId);

                if (reservation == null)
                {
                    return new ResponseModel()
                           {
                               Code = ResultActionModelCode.NoEntityFound, Message = "No entity found"
                           }
                }
                ;
                reservation.Phase = dto.Phase;
                unity.SaveChanges();
                return(ResponseModel.OK());
            }
        }
    }
}
コード例 #2
0
        public ResponseModel <List <SearchHotelResponseDTO> > SearchHotels(SearchHotelRequestDTO dto)
        {
            if (dto == null)
            {
                return new ResponseModel <List <SearchHotelResponseDTO> >()
                       {
                           Code = ResultActionModelCode.NoData, Message = "No data"
                       }
            }
            ;
            using (var unity = _factory.GetUnitOfWork(UnitOfWorkContext.ReadOnly))
            {
                var result = unity.GetRepository <Hotel>()
                             .AsQueryable()
                             .Where(x => x.Name == dto.Place || x.Country.Name == dto.Place || x.City == dto.Place)
                             .SelectMany(x => x.Rooms)
                             .Where(x => x.PersonNumbers == dto.PersonsNumber &&
                                    (x.Reservations.All(z => !(z.DateFrom == dto.From && z.DateTo == dto.To || x.Reservations.Count == 0))))
                             .Select(x => new SearchHotelResponseDTO()
                {
                    HotelId   = x.Hotel.Id,
                    City      = x.Hotel.City,
                    Country   = x.Hotel.Country.Name,
                    HotelName = x.Hotel.Name,
                    Price     = x.Price,
                    RoomId    = x.Id
                }).ToList();

                return(ResponseModel <List <SearchHotelResponseDTO> > .OK(result));
            }
        }
    }
コード例 #3
0
        public ResponseModel <HotelDetailsResponseDTO> GetDetails(SearchModelId id)
        {
            if (id == null)
            {
                return new ResponseModel <HotelDetailsResponseDTO>()
                       {
                           Code = ResultActionModelCode.NoData, Message = "No data"
                       }
            }
            ;

            using (var unity = _factory.GetUnitOfWork(UnitOfWorkContext.ReadOnly))
            {
                var room = _factory.GetUnitOfWork(UnitOfWorkContext.ReadOnly)
                           .GetRepository <Room>()
                           .AsQueryable()
                           .FirstOrDefault(x => x.Id == id.RoomId);

                var hotel = room.Hotel;


                HotelDetailsResponseDTO response = new HotelDetailsResponseDTO()
                {
                    Description       = hotel.Description,
                    HotelCity         = hotel.City,
                    HotelContactPhone = hotel.ContactPhone,
                    HotelCountry      = hotel.Country.Name,
                    HotelId           = hotel.Id,
                    HotelName         = hotel.Name,
                    HotelNumber       = hotel.HouseNumber,
                    Room = new RoomDetailsResponseDTO()
                    {
                        AdditionalInfo = room.AdditionalInfo,
                        Price          = room.Price,
                        RoomId         = room.Id,
                    }
                };
                return(ResponseModel <HotelDetailsResponseDTO> .OK(response));
            }
        }
コード例 #4
0
        public ResponseModel <AddReservationResponseDTO> AddReservation(AddReservationRequestDTO dto)
        {
            if (dto == null || dto.User == null)
            {
                return new ResponseModel <AddReservationResponseDTO>()
                       {
                           Code = ResultActionModelCode.NoData, Message = "No data"
                       }
            }
            ;

            using (var unity = _factory.GetUnitOfWork(UnitOfWorkContext.Default))
            {
                var room = unity.GetRepository <Room>().AsQueryable()
                           .FirstOrDefault(x => x.Id == dto.RoomId);

                if (room == null)
                {
                    return new ResponseModel <AddReservationResponseDTO>()
                           {
                               Code = ResultActionModelCode.NoEntityFound, Message = "No enetity found"
                           }
                }
                ;
                var user = unity.GetRepository <User>().AsQueryable()
                           .FirstOrDefault(x => x.FirstName == dto.User.FirstName && x.LastName == dto.User.LastName);
                if (user == null)
                {
                    user = new User()
                    {
                        FirstName = dto.User.FirstName,
                        LastName  = dto.User.LastName
                    };

                    unity.GetRepository <User>().Add(user);
                    unity.SaveChanges();
                }
                var reservation = new Reservation()
                {
                    DateFrom = dto.From,
                    DateTo   = dto.To,
                    Phase    = ReservationPhase.InsertedInformation,
                    Room     = room,
                    Type     = ReservationType.Normal,
                    User     = user
                };
                unity.GetRepository <Reservation>()
                .Add(reservation);
                unity.SaveChanges();
                AddReservationResponseDTO result = new AddReservationResponseDTO()
                {
                    ReservationId = reservation.Id,
                    Room          = new RoomDetailsResponseDTO()
                    {
                        RoomId = room.Id,
                        Price  = room.Price,
                    },
                    User = new UserDetailsModelDTO()
                    {
                        FirstName = user.FirstName,
                        LastName  = user.LastName,
                    }
                };

                return(ResponseModel <AddReservationResponseDTO> .OK(result));
            }
        }