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)); }
public async Task <ActionResult> AddAReservation([FromBody] PostReservationRequest request) { // 1. Map It to a Reservation var reservation = new Reservation { For = request.For, Books = string.Join(',', request.Books), ReservationCreated = DateTime.Now, Status = ReservationStatus.Pending }; // 2. Add it to the database Context.Reservations.Add(reservation); await Context.SaveChangesAsync(); // 3. That that reservation and map it to a reservation response. // 4. return a 201 with a location and attach a GetReservationItemResponse var response = MapIt(reservation); reservationProcessor.SendForProcessing(response); return(CreatedAtRoute("reservations#getbyid", new { id = response.Id }, response)); }