private ReservationBM GetReservationInfo(Reservation reservation) { ReservationBM reservationBM = new ReservationBM(); reservationBM.ID = reservation.ID; reservationBM.GuestID = (int)reservation.GuestID; reservationBM.ApartmanID = reservation.ApartmanID; //SingUpDate za rezervaciju: //DatesModel singUpDate = context.DatesModels.Where(x => x.ID == reservation.DatesModelID).FirstOrDefault(); reservationBM.SingUpDate = reservation.SingUpDate; //ovde puca, proveri ovo kako treba reservationBM.NumberOfNights = reservation.NumberOfNights; reservationBM.TotalPrice = reservation.TotalPrice; reservationBM.Stauts = reservation.Stauts.ToString(); reservationBM.GuestUserName = reservation.Guest.UserName; reservationBM.HostUserName = reservation.Apartman.Host.UserName; reservationBM.ApartmentStreat = reservation.Apartman.Location.Adress.Streat; reservationBM.ApartmentStreatNumber = reservation.Apartman.Location.Adress.StreatNumber; reservationBM.ApartmentSettlement = reservation.Apartman.Location.Adress.Settlement; reservationBM.ApartmentZipCode = reservation.Apartman.Location.Adress.ZipCode; return(reservationBM); }
public IHttpActionResult GetReservationRequests(int hostId, Helper.Enums.ReservationStatus status) { if (CheckRole("Host")) { return(StatusCode(HttpStatusCode.Unauthorized)); } List <ReservationBM> reservationInfo = new List <ReservationBM>(); List <Apartman> apps = context.Apartmans.Where(x => x.HostID == hostId && x.Deleted != true).ToList(); if (apps != null) { foreach (var apartment in apps) { if (apartment.Reservations != null) { foreach (var reservation in apartment.Reservations.Where(x => x.Stauts == status)) { ReservationBM reservationBM = GetReservationInfo(reservation); reservationInfo.Add(reservationBM); } } } } return(Ok(reservationInfo)); }
public IHttpActionResult GetSearchHostReservations(int hostId, string username, string status) { if (CheckRole("Host")) { return(StatusCode(HttpStatusCode.Unauthorized)); } List <ReservationBM> reservationInfo = new List <ReservationBM>(); List <Apartman> apps = context.Apartmans.Where(x => x.HostID == hostId && x.Deleted != true).ToList(); ICollection <Reservation> reservations = null; ICollection <Reservation> finalReservations = new HashSet <Reservation>(); //reservation logic: if (apps != null) { foreach (Apartman apartment in apps) { reservations = apartment.Reservations.ToList(); if (username != "" && username != "null" && username != null && reservations != null && reservations.Count > 0) { User user = context.Users.Where(x => x.UserName == username && x.Blocked == false).FirstOrDefault(); if (user != null) { reservations = user.Reservations.ToList(); } else { reservations = null; } } if (status != "" && status != "null" && status != null && reservations != null && reservations.Count > 0) { reservations = reservations.Where(x => x.Stauts.ToString() == status && x.Deleted == false).ToList(); } if (reservations != null && reservations.Count > 0) { foreach (Reservation res in reservations) //smesta u finalReservations jer host moze imati vise apartmana i za svaki apartman moze imati vise reservacija { finalReservations.Add(res); } } } } //-------------------------------------- if (finalReservations != null && finalReservations.Count > 0) { foreach (Reservation res in finalReservations) { ReservationBM reservationBM = GetReservationInfo(res); reservationInfo.Add(reservationBM); } } return(Ok(reservationInfo)); }
public IHttpActionResult GetReservation(int reservationID) { if (CheckRole("Guest")) { return(StatusCode(HttpStatusCode.Unauthorized)); } ReservationBM reservationInfo = new ReservationBM(); Reservation ress = context.Reservations.Where(x => x.ID == reservationID && x.Deleted != true).FirstOrDefault(); if (ress != null) { reservationInfo = GetReservationInfo(ress); } return(Ok(reservationInfo)); }
public IHttpActionResult GetAllReservations() { if (CheckRole("Admin")) { return(StatusCode(HttpStatusCode.Unauthorized)); } List <ReservationBM> reservationInfo = new List <ReservationBM>(); ICollection <Reservation> reservations = context.Reservations.Where(x => x.Deleted == false).ToList(); foreach (var reservation in reservations) { ReservationBM reservationBM = GetReservationInfo(reservation); reservationInfo.Add(reservationBM); } return(Ok(reservationInfo)); }
public IHttpActionResult GetSearchReservations(string username, string status) { if (CheckRole("Admin")) { return(StatusCode(HttpStatusCode.Unauthorized)); } List <ReservationBM> reservationInfo = new List <ReservationBM>(); ICollection <Reservation> reservations = context.Reservations.Where(x => x.Deleted == false).ToList(); //reservation logic: if (reservations != null) { if (username != "" && username != "null" && username != null && reservations != null && reservations.Count > 0) { User user = context.Users.Where(x => x.UserName == username && x.Blocked == false).FirstOrDefault(); if (user != null) { reservations = user.Reservations.Where(x => x.Deleted == false).ToList(); } else { reservations = null; } } if (status != "" && status != "null" && status != null && reservations != null && reservations.Count > 0) { reservations = reservations.Where(x => x.Stauts.ToString() == status && x.Deleted == false).ToList(); } } //-------------------------------------- if (reservations != null && reservations.Count > 0) { foreach (Reservation res in reservations) { ReservationBM reservationBM = GetReservationInfo(res); reservationInfo.Add(reservationBM); } } return(Ok(reservationInfo)); }
public IHttpActionResult GetGuestCommentReservations(int guestId) { if (CheckRole("Guest")) { return(StatusCode(HttpStatusCode.Unauthorized)); } List <ReservationBM> reservationInfo = new List <ReservationBM>(); List <Reservation> ress = context.Reservations.Where(x => x.GuestID == guestId && (x.Stauts == ReservationStatus.Done || x.Stauts == ReservationStatus.Rejected) && x.Deleted != true).ToList(); if (ress != null && ress.Count > 0) { foreach (var reservation in ress) { ReservationBM reservationBM = GetReservationInfo(reservation); reservationInfo.Add(reservationBM); } } return(Ok(reservationInfo)); }