public async Task <IActionResult> Post(TicketModel ticketModel) { var ticket = _mapper.Map <Ticket>(ticketModel); var createdTicket = await _ticketService.AddAsync(ticket); return(Ok(createdTicket)); }
public async Task <ActionResult> SaveTicket([FromBody] Ticket ticket) { try { var savedTicket = await _ticketService.AddAsync(ticket); return(Ok(savedTicket)); } catch (Exception exception) { return(BadRequest(exception)); } }
public async Task <IActionResult> BookTicket(TicketDto ticketDto) { decimal price = 0; var currentUser = _userService.Where(x => x.Email == ticketDto.Email).Result.First(); var bookedSeat = _seatService.Where(x => x.SeatNumbers == ticketDto.SeatNumbers).Result.First(); var bookedBus = _busService.Where(x => x.Plate == ticketDto.Plate).Result.First(); var dest = _context.Buses.Where(x => x.Plate == ticketDto.Plate).Select(x => x.Destinations.Id).FirstOrDefault(); var count = _ticketService.Where(x => x.Buses.Id == bookedBus.Id).Result.Count(); if (_ticketService.Where(x => x.Buses.Plate == ticketDto.Plate).Result.Any() && _ticketService.Where(x => x.Seats.SeatNumbers == ticketDto.SeatNumbers).Result.Any()) { return(NotFound("Seat is Taken")); } if (dest == 1) { price = 10; } else if (dest == 2) { price = 20; } else { price = 30; } if ((count >= 5 && count < 10) || (count >= 10 && count < 15) || (count >= 15 && count < 20)) { price *= 1.1m; } else if (count == 20) { price /= 1.1m; } await _ticketService.AddAsync(new Tickets { Price = price, Buses = bookedBus, Seats = bookedSeat, Users = currentUser }); return(Created(string.Empty, "ok")); }
public async Task <ApiResponse <Domain.Models.Ticket> > AddTicket([FromBody] Domain.Models.Ticket ticket) { try { if (ticket == null) { return(new ApiResponse <Domain.Models.Ticket>(ApiResponseCode.BadRequest)); //return BadRequest(); } await _ticketService.AddAsync(ticket); return(new ApiResponse <Domain.Models.Ticket>(ApiResponseCode.OK, ticket)); //return Ok(ticket); } catch (Exception e) { return(new ApiResponse <Domain.Models.Ticket>(ApiResponseCode.ServiceUnavailable) { Exception = e }); //return StatusCode(503, e.Message); } }
public async Task Handle(TicketCreatedEvent @event) { await _ticketService.AddAsync(@event.Ticket); }