public async override Task <bool> Process(string message) { //1. Deserialize the message (JSON document) var request = JsonSerializer.Deserialize <Reservation>(message); Logger.LogInformation($"Got a reservation for {request.For}"); //2. Decide if it is approved or denied var count = request.Books.Split(',').Length; if (count % 2 == 0) { return(await Service.MarkReservationAccepted(request)); } else { return(await Service.MarkReservationDenied(request)); } // return(true); }
public override async Task <bool> Process(string message) { // 1. deserialize from the json into a .net object var request = JsonSerializer.Deserialize <ReservationMessage>(message); // 2. maybe log it so we can see it. Logger.LogInformation($"Got a reservation for {request.For}"); // 3. do the business stuff. process the reservation. // (reservations with an even nuber of books get approved, otherwise, they are denied) var isOk = request.Books.Split(',').Count() % 2 == 0; // 4. tell the api about it. if (isOk) { return(await Service.MarkReservationAccepted(request)); } else { return(await Service.MarkReservationDenied(request)); } }
public override Task <bool> Process(string message) { // Deserialize the message into an object var request = JsonSerializer.Deserialize <Reservation>(message); Logger.LogInformation($"Got a reservation for {request.For}"); // Log it out. // Business logic! var shouldApprove = request.Books.Split(',').Length; if (shouldApprove <= 3) { // If Approved - POST /reservations/approved return(Service.MarkReservationApproved(request)); } else { // If Denied - POST /reservations/denied return(Service.MarkReservationDenied(request)); } }
public override async Task <bool> Process(string message) { // 1. message body is a string, deserialize it into a .NET object var request = JsonSerializer.Deserialize <ReservationMessage>(message); // 2. maybe log it so we can see it Logger.LogInformation($"Got a reservation for {request.For}"); // 3. do the business stuff, processes the reservation var isOk = request.Books.Split(',').Count() % 2 == 0; // 4. Tell the API about it if (isOk) { return(await Service.MarkReservationApproved(request)); } else { return(await Service.MarkReservationDenied(request)); } }
public override async Task <bool> Process(string message) { // deserialize the thing into a C# object again. var reservation = JsonSerializer.Deserialize <ReservationModel>(message); // Do the actual work... 1s per book var numberOfBooks = reservation.BookIds.Split(',').Count(); await Task.Delay(1000 *numberOfBooks); // even number books get approved, odd get denied. if (numberOfBooks % 2 == 0) { _logger.LogInformation($"Got a reservation for {reservation.For}. It is approved."); return(await _service.MarkReservationReady(reservation)); } else { _logger.LogInformation($"Got a reservation for {reservation.For}. It is DENIED."); return(await _service.MarkReservationDenied(reservation)); } // let the API know --- TODO: Set up something in our API for this. // if the api call is success, return True from this method, otherwise return False (this is our Plan B) }