コード例 #1
0
        public HttpResponseMessage GetReservation(long id, [FromBody] Reservation reservationRequest)
        {
            ReservationPersistenceService reservationPersistenceService = new ReservationPersistenceService();
            Reservation         reservation = reservationPersistenceService.GetReservation(id);
            HttpResponseMessage response;

            if (reservation == null)
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound, "Reservation not found.");
                return(response);
            }

            return(Request.CreateResponse(HttpStatusCode.OK, reservation));
        }
コード例 #2
0
        public HttpResponseMessage GetReservations()
        {
            ReservationPersistenceService reservationPersistenceService = new ReservationPersistenceService();
            var reservations = reservationPersistenceService.GetReservations();
            HttpResponseMessage response;

            if (reservations == null || reservations.Count.Equals(0))
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound, "No reservations found.");
                return(response);
            }
            response = Request.CreateResponse(HttpStatusCode.OK, reservations);
            return(response);
        }
コード例 #3
0
        public HttpResponseMessage DeleteReservation(long id)
        {
            ReservationPersistenceService reservationPersistenceService = new ReservationPersistenceService();
            bool userExists = false;

            userExists = reservationPersistenceService.DeleteReservation(id);

            HttpResponseMessage response;

            if (userExists)
            {
                response = Request.CreateResponse(HttpStatusCode.OK, "Reservation deleted.");
                return(response);
            }
            else
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound, "Reservation not found.");
                return(response);
            }
        }
コード例 #4
0
        public HttpResponseMessage CreateReservation([FromBody] Reservation reservation)
        {
            ReservationPersistenceService reservationPersistenceService = new ReservationPersistenceService();
            HttpResponseMessage           response;

            var id = reservationPersistenceService.SaveReservation(reservation);

            if (id < 0)
            {
                response = Request.CreateResponse(HttpStatusCode.BadRequest, "Ensure referential integrity. Please try again.");
                return(response);
            }
            reservation.reservationID = id;
            // just recalculate the reservation length, super smelly lmao
            TimeSpan diff = reservation.endDateTime - reservation.startDateTime;

            reservation.reservationLength = diff.Days + 1;
            response = Request.CreateResponse(HttpStatusCode.Created, reservation);
            response.Headers.Location = new Uri(Request.RequestUri, string.Format("reservations/{0}", id));
            return(response);
        }