public async Task <ActionResult> ApproveReservation([FromBody] GetReservationItemResponse reservation)
        {
            var storedReservation = await Context.Reservations.SingleOrDefaultAsync(r => r.ID == reservation.ID);

            if (storedReservation == null)
            {
                return(BadRequest());
            }
            storedReservation.Status = ReservationStatus.Approved;
            await Context.SaveChangesAsync();

            return(Accepted());             // could also return a 201 but the location header isn't really changing.
        }
        public async Task <ActionResult> ApproveReservation([FromBody] GetReservationItemResponse reservation)
        {
            var storedReservation = await Context.Reservations.SingleOrDefaultAsync(r => r.Id == reservation.Id);

            if (storedReservation == null)
            {
                return(BadRequest());
            }
            storedReservation.Status = ReservationStatus.Approved;
            await Context.SaveChangesAsync();

            return(Accepted()); //
        }
        private GetReservationItemResponse MapIt(Reservation reservation)
        {
            var response = new GetReservationItemResponse
            {
                Id  = reservation.Id,
                For = reservation.For,
                ReservationCreated = DateTime.Now,
                Status             = reservation.Status,
                Books = reservation.Books.Split(',')
                        .Select(id => Url.ActionLink("GetBookById", "Books", new { Id = id })).ToList() //http://localhost:1337/books/1
            };

            return(response);
        }
        private GetReservationItemResponse MapIt(Reservation reservation)
        {
            var response = new GetReservationItemResponse
            {
                ID  = reservation.ID,
                For = reservation.For,
                ReservationCreated = DateTime.Now,
                Status             = reservation.Status,
                Books = reservation.Books.Split(',')
                        .Select(id => Url.ActionLink("GetBookById", "Books", new { id = id })).ToList()
            };

            return(response);
        }
Beispiel #5
0
        private GetReservationItemResponse MapIt(Reservation reservation)
        {
            var response = new GetReservationItemResponse
            {
                Id  = reservation.Id,
                For = reservation.For,
                ReservationCreated = DateTime.Now,
                Status             = reservation.Status, // this is going to not work quite right. We'll fix that.
                Books = reservation.Books.Split(',')
                        .Select(id => Url.ActionLink("GetBookById", "Books", new { id = id })).ToList()
            };

            return(response);
        }
        public async Task <ActionResult> ReservationApproved([FromBody] GetReservationItemResponse req)
        {
            var reservation = await Context.Reservations.Where(r => r.Id == req.Id).SingleOrDefaultAsync();

            if (reservation == null)
            {
                return(BadRequest("No pending reservation"));
            }
            else
            {
                reservation.Status = ReservationStatus.Approved;
                await Context.SaveChangesAsync();

                return(Accepted()); // NoContent()
            }
        }
        public async Task <ActionResult> AddAReservation([FromBody] PostReservationRequest request)
        {
            var reservation = new Reservation
            {
                For   = request.For,
                Books = string.Join(',', request.Books),
                ReservationCreated = DateTime.Now,
                Status             = ReservationStatus.Pending
            };

            Context.Reservations.Add(reservation);
            await Context.SaveChangesAsync();

            GetReservationItemResponse response = MapIt(reservation);

            reservationProcessor.SendForProcessing(response);

            return(CreatedAtRoute("reservations#getbyid", new { id = response.Id }, response));
        }
Beispiel #8
0
 public void SendForProcessing(GetReservationItemResponse response)
 {
     Manager.Publish(response, "", "direct", "reservationQueue");
 }
Beispiel #9
0
 public void SendReservationForProcessing(GetReservationItemResponse reservation)
 {
     Manager.Publish(reservation, "", "direct", "reservations");
 }