Beispiel #1
0
        private ReservationExtended ConvertToReservationEx(Reservation reservation)
        {
            ReservationExtended resEx = new ReservationExtended
            {
                Id           = reservation.Id,
                Date         = reservation.Date,
                Cancellation = reservation.Cancellation,
                User         = reservation.User,
                Timeslot     = reservation.Timeslot,
                Status       = GetReservationStatus(reservation)
            };

            return(resEx);
        }
        public string Get()
        {
            List <ReservationExtended> listOfReservationExtended = new List <ReservationExtended>();

            using (var db = new SmallHotelDB())
            {
                var users        = db.Users.Select(u => new { u.UserID, u.UserName }).ToArray();
                var rooms        = db.Rooms.Select(r => new { r.RoomID, r.RoomName }).ToArray();
                var reservations = db.Reservations.Select(r => new { r.ReservationID, r.RoomID, r.UserID, r.ReservationStartDate, r.ReservationEndDate });

                var queryUserReservation = users.Join(reservations,
                                                      user => user.UserID,
                                                      reservation => reservation.UserID,
                                                      (u, r) => new { r.ReservationID, u.UserID, u.UserName, r.RoomID, r.ReservationStartDate, r.ReservationEndDate });

                var queryUserReservationRoom = rooms.Join(queryUserReservation,
                                                          room => room.RoomID,
                                                          qur => qur.RoomID,
                                                          (r, ur) => new { ur.ReservationID, r.RoomID, ur.UserID, r.RoomName, ur.UserName, ur.ReservationStartDate, ur.ReservationEndDate }
                                                          );

                foreach (var item in queryUserReservationRoom)
                {
                    ReservationExtended re = new ReservationExtended
                    {
                        ReservationID        = item.ReservationID,
                        RoomID               = item.RoomID,
                        UserID               = item.UserID,
                        ReservationStartDate = item.ReservationStartDate,
                        ReservationEndDate   = item.ReservationEndDate,
                        RoomName             = item.RoomName,
                        UserName             = item.UserName
                    };
                    listOfReservationExtended.Add(re);
                }
                return(Newtonsoft.Json.JsonConvert.SerializeObject(listOfReservationExtended));
            }
        }