public async Task <ActionResult> Update(int id, [FromBody] TicketRequestDto dto) { var validator = new TicketValidator(); var result = await validator.ValidateAsync(dto); if (!result.IsValid) { return(BadRequest(result.Errors)); } return(Ok(await _service.Update(id, dto))); }
public async Task <Ticket> Create(TicketRequestDto dto) { Ticket entity = _mapper.Map <TicketRequestDto, Ticket>(dto); entity.Route = await _unitOfWork._routeRepository.GetOneById(dto.RouteId); Ticket ticket = await _unitOfWork._ticketRepository.Create(entity); await _unitOfWork.SaveChanges(); return(ticket); }
public async Task <Infrastructure.Models.Ticket> CreateTicketAsync(TicketRequestDto ticketRequestDto) { if (ticketRequestDto.StartDate < DateTime.UtcNow || ticketRequestDto.EndDate < DateTime.UtcNow) { throw new ArgumentException("date is invalid"); } var entry = await _dbContext.Tickets.AddAsync(new Infrastructure.Models.Ticket { Address = ticketRequestDto.Address, HotelClass = ticketRequestDto.HotelClass, StartDate = ticketRequestDto.StartDate, EndDate = ticketRequestDto.EndDate, StartTime = TimeSpan.Parse(ticketRequestDto.StartTime), EndTime = TimeSpan.Parse(ticketRequestDto.EndTime), IsAllInclusive = ticketRequestDto.IsAllInclusive }); await _dbContext.SaveChangesAsync(); return(entry.Entity); }
public async Task <TicketResponseDto> CreateTicket(TicketRequestDto ticketRequestDto) { var result = await _ticketService.CreateTicketAsync(ticketRequestDto); return(_mapper.Map <TicketResponseDto>(result)); }
public async Task <TicketResponseDto> UpdateTicket(long ticketId, TicketRequestDto ticketRequestDto) { var result = await _ticketService.UpdateTicketAsync(ticketId, ticketRequestDto); return(_mapper.Map <TicketResponseDto>(result)); }
public async Task <Infrastructure.Models.Ticket> UpdateTicketAsync(long ticketId, TicketRequestDto ticketRequestDto) { if (ticketRequestDto.StartDate < DateTime.UtcNow || ticketRequestDto.EndDate < DateTime.UtcNow) { throw new ArgumentException("date is invalid"); } var entity = await _dbContext.Tickets.SingleOrDefaultAsync(t => t.Id == ticketId); entity.Address = ticketRequestDto.Address; entity.HotelClass = ticketRequestDto.HotelClass; entity.StartDate = ticketRequestDto.StartDate; entity.EndDate = ticketRequestDto.EndDate; entity.StartTime = TimeSpan.Parse(ticketRequestDto.StartTime); entity.EndTime = TimeSpan.Parse(ticketRequestDto.EndTime); entity.IsAllInclusive = ticketRequestDto.IsAllInclusive; await _dbContext.SaveChangesAsync(); return(entity); }