public ActionResult UpdateFlightDetail(int id, FlightDetailUpdateDto flightDetailUpdateDto) { var flight = _context.FlightDetails.FirstOrDefault(f => f.Id == id); if (flight == null) { return(NotFound()); } _mapper.Map(flightDetailUpdateDto, flight); _context.SaveChanges(); return(NoContent()); }
public IActionResult UpdateFlightDetail(string flightCode, FlightDetailUpdateDto flightToUpdate) { var flight = _context.FlightDetails.FirstOrDefault(f => f.FlightCode == flightCode); if (flight == null) { return(NotFound()); } var oldPrice = flight.PricePerSeat; _mapper.Map(flightToUpdate, flight); try { _context.SaveChanges(); if (oldPrice != flight.PricePerSeat) { Console.WriteLine("Price changed - Place message on bus"); var message = new NotificationMessageDto { WebhookType = "pricechange", OldPricePerSeat = oldPrice, NewPricePerSeat = flight.PricePerSeat, FlightCode = flight.FlightCode }; _messageBus.SendMessage(message); } else { Console.WriteLine("No Price change"); } return(NoContent()); } catch (Exception ex) { return(BadRequest(ex.Message)); } return(NoContent()); }
public async Task <ActionResult> UpdateFlightDetail(int id, FlightDetailUpdateDto flightDetailUpdateDto) { var flight = await _context.FlightDetails.FirstOrDefaultAsync(f => f.Id == id); if (flight is null) { return(await Task.FromResult(NotFound())); } decimal oldPrice = flight.Price; _mapper.Map(flightDetailUpdateDto, flight); try { await _context.SaveChangesAsync(); if (oldPrice != flight.Price) { Console.WriteLine("Price changed - Place message on bus"); var message = new NotificationMessageDto { WebhookType = "pricechange", OldPrice = oldPrice, NewPrice = flight.Price, FlightCode = flight.FlightCode }; _messageBusClient.SendMessage(message); } else { Console.WriteLine("No price change"); } return(await Task.FromResult(NoContent())); } catch (Exception e) { Console.WriteLine(e.Message); throw; } }
public ActionResult UpdateFlightDetail(int id, FlightDetailUpdateDto flightDetailUpdateDto) { var flight = _context.FlightDetails.FirstOrDefault(f => f.Id == id); if (flight == null) { return(NotFound()); } decimal oldPrice = flight.Price; _mapper.Map(flightDetailUpdateDto, flight); try { _context.SaveChanges(); if (oldPrice != flight.Price) { Console.WriteLine("Price changed - Place message on bus"); var message = new NotificationMessageDto { WebhookType = "Price Change", OldPrice = oldPrice, // TODO: TYPO NewPrice = flight.Price, FlightCode = flight.FlightCode, }; _messageBus.SendMessage(message); } else { Console.WriteLine("No price change"); } return(NoContent()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <ActionResult> UpdateFlightDetails(string flightCode, [FromBody] FlightDetailUpdateDto flightDetailsUpdateDto) { var flight = await _context.FlightDetails .FirstOrDefaultAsync( e => e.FlightCode == flightCode); if (flight == null) { return(NoContent()); } decimal oldPrice = flight.Price; _mapper.Map(flightDetailsUpdateDto, flight); try { await _context.SaveChangesAsync(); if (oldPrice != flight.Price) { Console.WriteLine("Price changed - PLace message on bus"); var message = new Dtos.NotificationMessageDto { Id = flight.Id.ToString(), FlightCode = flight.FlightCode, NewPrice = flight.Price, OldPrice = oldPrice, WebhookType = "pricechange" }; _messageBus.SendMessage(message); } } catch (Exception ex) { return(BadRequest(ex.Message)); } return(NoContent()); }
public ActionResult FlightChanged(FlightDetailUpdateDto flightDetailUpdateDto) { Console.WriteLine($"Webhook Receieved from: {flightDetailUpdateDto.Publisher}"); var secretModel = _context.SubscriptionSecrets.FirstOrDefault(s => s.Publisher == flightDetailUpdateDto.Publisher && s.Secret == flightDetailUpdateDto.Secret); if (secretModel == null) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Invalid Secret - Ignore Webhook"); Console.ResetColor(); return(Ok()); } else { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Valid Webhook!"); Console.WriteLine($"Old Price {flightDetailUpdateDto.OldPrice}, New Price {flightDetailUpdateDto.NewPrice}"); Console.ResetColor(); return(Ok()); } }
public async Task <ActionResult> FlightChanged(FlightDetailUpdateDto flightDetailUpdateDto) { Console.WriteLine($"webhook received from: {flightDetailUpdateDto.Publisher}"); var secretModel = await _context.SubscriptionSecrets.FirstOrDefaultAsync( e => e.Secret == flightDetailUpdateDto.Secret && e.Publisher == flightDetailUpdateDto.Publisher ); if (secretModel == null) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Invalid secret"); Console.ResetColor(); return(Ok()); } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Valid webhook"); Console.WriteLine("Old price: {0}, New Price: {1}", flightDetailUpdateDto.OldPrice, flightDetailUpdateDto.NewPrice); Console.ResetColor(); return(Ok()); }
public IActionResult FlightChanged(FlightDetailUpdateDto updatedFlight) { Console.WriteLine($"Webhook Received from {updatedFlight.Publisher}"); var secretModel = _context.SubscriptionSecrets.FirstOrDefault(s => s.Secret == updatedFlight.Secret && s.Publisher == updatedFlight.Publisher); if (secretModel == null) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Invalid secret - Ignore Webhook"); Console.ResetColor(); return(Ok()); } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Valid Webhook!"); Console.WriteLine($"Old Price: {updatedFlight.OldPricePerSeat}, New Price: {updatedFlight.NewPricePerSeat}"); Console.ResetColor(); return(Ok()); }