public async Task <TicketDTO> CreateTicketAsync(CreateTicketDTO createTicketDTO) { var isFestivalExist = await _DBContext.Festivals.AnyAsync(f => f.Id == createTicketDTO.FestivalId); if (!isFestivalExist) { throw new ItemNotFoundException($"Festival with id {createTicketDTO.FestivalId} not found."); } var ticket = new TicketEntity { Price = createTicketDTO.Price, BeginingTime = createTicketDTO.BeginingTime, Duration = createTicketDTO.Duration, Type = (TicketType)(int)createTicketDTO.Type, FestivalId = createTicketDTO.FestivalId }; await _DBContext.Tickets.AddAsync(ticket); await _DBContext.SaveChangesAsync(); ticket = await _DBContext.Tickets .Include(t => t.Festival) .AsNoTracking().FirstOrDefaultAsync(t => t.Id == ticket.Id); var ticketDTO = _mapper.Map <TicketDTO>(ticket); return(ticketDTO); }
public IActionResult Contact(CreateTicketDTO model) { if (ModelState.IsValid) { try { _repositoryWrapper.Ticket.CreateTicket(_mapper.Map <Ticket>(model)); } catch (Exception ex) { _logger.LogError($"{nameof(Contact)} encountered a error adding Ticket to Database: {ex}"); throw new Exception($"{nameof(Contact)} encountered a error adding Ticket to Database: {ex}"); } return(RedirectToAction(nameof(Index))); } return(View(nameof(Contact), model)); }
public async Task <IActionResult> CreateTicket(CreateTicketDTO data) { ServiceResponse <AddedTicketDTO> response = new ServiceResponse <AddedTicketDTO>(); ServiceResponse <int> price = await _ticketService.GetPrice(data.TicketType); if (!price.Success) { response.Message = price.Message; response.Success = price.Success; return(BadRequest(response)); } response = await _ticketService.CreateTicket(data.TicketType, price.Data, data.Email); if (!response.Success) { return(BadRequest(response)); } return(Ok(response)); }